-
Notifications
You must be signed in to change notification settings - Fork 143
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Best practices for handling multi-channel movies in Images.jl discussion #553
Comments
(NRRD lets you concatenate all your image files into a single file.) |
Is that what your lab uses? I agree TIFF kinda sucks for this use-case. Also, is it possible to tell if a file that is loaded is being |
We have a custom acquisition program that outputs in our own format, ImagineFormat. But the binary data are in the same format as NRRD (which is to say a raw dump); it's only the header that's different. I don't know of a way to tell whether an array is |
NRRD.jl has some issues, I have some fixes here: JuliaIO/NRRD.jl#3. It appears that Fiji's NRRD writer has some weird behavior because it encodes a XYT image as Gray Images.Image with:
data: 2048×2044×96 Array{UInt16,3}
properties:
spaceunits: pixel pixel pixel
colorspace: Gray
spatialorder: x y z
spacedirections: [1.0,0.0,0.0] [0.0,1.0,0.0] [0.0,0.0,1.0]
comments: Created by Nrrd_Writer at Sun Sep 11 13:43:43 PDT 2016
pixelspacing: 1.0 1.0 1.0 This has a couple problems. First, the spatialorder has |
Indeed let's fix whatever needs doing on the Julia side. Fiji's issues obviously would be ideal to fix too, but worst-case scenario one can edit the header, esp. if Fiji has the option to save as separate Overall I'd say NRRD.jl needs to do a lot more to make sure it can read/write NRRD files that are compatible with other software, ideally even when other software writes buggy headers. The implementation is just taken directly from the description of the format, but sometimes I find the description slightly confusing. And there's nothing like a test to discover you've gotten something wrong. For creating an image in Julia, this seems to work: julia> using Images
julia> img = grayim(collect(reshape(0x01:0x30, 4, 6, 2)))
Gray Images.Image with:
data: 4×6×2 Array{FixedPointNumbers.UFixed{UInt8,8},3}
properties:
colorspace: Gray
spatialorder: x y z
julia> img["timedim"] = 3
3
julia> img["spatialorder"] = ["x", "y"]
2-element Array{String,1}:
"x"
"y"
julia> img
Gray Images.Image with:
data: 4×6×2 Array{FixedPointNumbers.UFixed{UInt8,8},3}
properties:
timedim: 3
colorspace: Gray
spatialorder: x y
julia> save("/tmp/test.nrrd", img) which dumps out with header
which seems plausible to me. |
What does the actual header written by Fiji look like? |
This what Fiji created from a virtual stack of TIFF images I had:
which looks like a bug in Fiji moreso than in |
Thanks. Assuming you're on a little endian machine, that But now we have MappedArrays, and we can do on-the-fly transformation with essentially no "extra" overhead: julia> using MappedArrays
julia> a = [0x0102, 0x0304]
2-element Array{UInt16,1}:
0x0102
0x0304
julia> aswap = mappedarray((ntoh,hton), a)
2-element MappedArrays.MappedArray{UInt16,1,Array{UInt16,1},Base.#ntoh,Base.#hton}:
0x0201
0x0403
julia> aswap[1]
0x0201 Performance: julia> a = rand(UInt16, 10^4);
julia> aswap = mappedarray((ntoh,hton), a);
julia> using BenchmarkTools
julia> @benchmark sum($a)
BenchmarkTools.Trial:
samples: 10000
evals/sample: 60
time tolerance: 5.00%
memory tolerance: 1.00%
memory estimate: 0.00 bytes
allocs estimate: 0
minimum time: 866.00 ns (0.00% GC)
median time: 874.00 ns (0.00% GC)
mean time: 884.48 ns (0.00% GC)
maximum time: 1.45 μs (0.00% GC)
julia> @benchmark sum($aswap)
BenchmarkTools.Trial:
samples: 10000
evals/sample: 10
time tolerance: 5.00%
memory tolerance: 1.00%
memory estimate: 0.00 bytes
allocs estimate: 0
minimum time: 1.17 μs (0.00% GC)
median time: 1.22 μs (0.00% GC)
mean time: 1.23 μs (0.00% GC)
maximum time: 15.93 μs (0.00% GC) Julia is so awesome, sometimes I just have to cheer. Note that |
Oh, and I'm slow to realize this, but perhaps you're just using Fiji to convert a bunch of TIFFs into one NRRD? You should be able to do that in pure Julia just fine. The sequence would be (1) write the NRRD header to a |
This section of code: might help when it comes to writing the header. |
Yeah, this the case. Thanks for the intro to MappedArrays though. They look super cool. My machine is little-endian so that's a bug in the Fiji exporter. Might try and file a bug report with them. But more importantly, I would like to get proper NRRD support in micromanager itself since it would be able to populate all those fields of the NRRD file with the original data.
I might do this in the mean time to test my optical flow algorithm. |
I opened up an issue with micro-manager here: micro-manager/micro-manager#446 We'll see what they think. |
I haven't seen any examples of NRRD storing channel information, do you happen to know what that looks like? I want to make sure it can handle my data needs. Thanks! |
I played with this a bit yesterday. At least some files have an appalling lack of concrete information about color or hints how to interpret the dimensions. 😦 Assuming that a dimension of size 3 means color is oh-so-fragile, because I can't represent a 3d grayscale image with 3 pixels along the fastest dimension. However, starting with format version 3 one can use the |
That file is scary 😱 How are channels represented in Images/ImageCore? I'm interested because I generally have images with distinct channels, i.e. I imaged cells with a 405nm laser and brightfield. |
You might be interested in |
|
The only useful thing an Overlay currently does is to blend images for display. Are you saying you'd like to see an interface that provides access like |
I was initially thinking the former, but I'm intrigued by the latter. How would the image be stored in memory with the latter? With regards to the first option, I was thinking a 4D matrix* where you would have
|
Closed by #577 |
I'm not sure that this is the best place to ask this, but I generally take movies that are broken up along channel info and time stored as separate TIFF files in a directory (using MicroManager by the way). Currently I'm just using a bunch of looping
load
calls for everything inreaddir
. Is there a better way of handling this? I would prefer to have the time dimension and channel info in the image metadata if possible.The text was updated successfully, but these errors were encountered: