使用 Matlab 的Tiff 类。
我可以组装一个我认为看起来不错的 ImageDescription 标签,ImageJ 将它(File>Open)作为 5D Hyperstack 读取,但数据已部分损坏。似乎存在偏移问题(我可以用 Matlab 再次很好地读取数据)。
但是,如果使用File>Import>Bio-Formats读取 tiff 文件,如果在 Bio-Formats 导入对话框中标记了带有 Hyperstack 的视图堆栈,它将在 ImageJ 中变为 5D (XYCZT) 堆栈。感谢ctrueden的有益评论。
d = ones(100, 200, 10, 2, 3, 'single') * 3.765;
hyperstack_write('test.tif', d);
function hyperstack_write(file, hyperstack)
% Writes an (up to) 5D stack into a (XYCZT) HyperStack Tiff file
% readable by ImageJ
%
% hyperstack must have class single
% simple checks
assert(nargin == 2, 'Not enough arguments');
assert(isa(hyperstack, 'single'), 'hyperstack must be single');
% get all five dimensions
d = zeros(5, 1);
for i = 1 : 5
d(i) = size(hyperstack, i);
end
% assemble image description
s = sprintf('ImageJ=1.51\nnimages=%d\nchannels=%d\nslices=%d\nframes=%d\nhyperstack=true\nmode=color\nloop=false\nmin=%.1f\nmax=%.1f\n', prod(d(3:5)), d(3), d(4), d(5), floor(min(hyperstack(:))*10)/10, ceil(max(hyperstack(:))*10)/10);
% open tif file for writing and set file tags
t = Tiff(file, 'w');
ts.ImageLength = d(1);
ts.ImageWidth = d(2);
ts.Photometric = Tiff.Photometric.MinIsBlack;
ts.Compression = Tiff.Compression.None;
ts.BitsPerSample = 32;
ts.SamplesPerPixel = 1;
ts.SampleFormat = Tiff.SampleFormat.IEEEFP;
ts.RowsPerStrip = 5;
ts.PlanarConfiguration = Tiff.PlanarConfiguration.Chunky;
ts.Software = 'MATLAB';
ts.ImageDescription = s;
% loop over dimensions 3, 4, and 5
for k = 1 : d(5)
for j = 1 : d(4)
for i = 1 : d(3)
frame = hyperstack(:, :, i, j, k);
t.setTag(ts)
t.write(frame);
t.writeDirectory();
end
end
end
% close tif file
t.close();
end
似乎 Bio-Formats 是将 >2D 数据从 Matlab 导出到 ImageJ 的唯一完全铺平且可用的方法,尽管在没有太多元数据可用且需要传输的情况下,此解决方案可能是一种轻量级的替代方案。