-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathTime_Tiff.m
76 lines (75 loc) · 2.63 KB
/
Time_Tiff.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
clear all;close all; clc; fclose all;
%generate some data
N=1E3;
IM=imread('landOcean.jpg');
IM = uint16(sum(IM,3));
IM = IM(100:310,960:1170);
IM = IM-min(IM(:));
IM=IM*(2^15/max(IM(:)));
IM = repmat(IM,[1,1,N])+randi((2^15)-1,[size(IM,1),size(IM,2),N],'uint16');
S = (numel(IM)/N*2)/2^20;
%https://nl.mathworks.com/matlabcentral/fileexchange/35684-multipage-tiff-stack
%imread writespeed
methods = {'imwrite','tifflib','fTIF'};
for M = 1:length(methods)
method = methods{M};
%timing vector
t = nan(1,size(IM,3)+1);
%file
filename = [method,'.tif'];
if exist(filename,'file'), delete(filename);end
switch method
case 'imwrite'
tic;
t(1)=0;
imwrite(IM(:,:,1),filename,'Compression','none');
t(2)=toc;
for ct = 2:100
imwrite(IM(:,:,ct),filename,'WriteMode','append','Compression','none');
t(ct+1)=toc;
end
case 'tifflib'
t(1)=0;
tic;
tf = Tiff(filename,'w');
for ct = 1:100
if ct>1,tf.writeDirectory;end
tf.setTag('Photometric',Tiff.Photometric.MinIsBlack);
tf.setTag('Compression',Tiff.Compression.None);
tf.setTag('BitsPerSample',16);
tf.setTag('SamplesPerPixel',1);
tf.setTag('SampleFormat',Tiff.SampleFormat.UInt);
tf.setTag('ExtraSamples',Tiff.ExtraSamples.Unspecified);
tf.setTag('ImageLength',size(IM,1));
tf.setTag('ImageWidth',size(IM,2));
tf.setTag('PlanarConfiguration',Tiff.PlanarConfiguration.Chunky);
tf.setTag('ImageDescription',sprintf('ImageJ=1.51j\nchannels=%.0f',size(IM,3)));
tf.write(IM(:,:,ct));
t(ct)=toc;
end
tf.close();
case 'fTIF'
t(1)=0;
tic
fTIF = Fast_Tiff_Write(filename,1,0);
for ct = 1:size(IM,3)
fTIF.WriteIMG(IM(:,:,ct)');
t(ct)=toc;
end
tic
fTIF.close;
fprintf(1,'closing the tif file took %.5f seconds\n',toc);
otherwise
error('unknown method')
end
S = (size(IM,1)*size(IM,2)*2)/2^20; %MB/frame
y = S./diff(t);
subplot(1,length(methods),M)
plot([1:size(IM,3)],y);
title(sprintf('Writing with %s; mean = %.2f MB/s',method,mean(y,'omitnan')))
ylabel('Writing speed (MB/s)')
xlabel('Frame');
drawnow;
end
f=gcf;f.Position=[1000 918 1175 420];
saveas(f,'example.png')