La réponse suivante s'applique tiff les images spécifiquement.
J'ai essayé de trouver une solution générale pour imwrite
fonction, mais je n'ai pas pu.
La solution utilise Classe Tiff au lieu d'utiliser imwrite
.
La classe Tiff permet d'enregistrer un fichier image tiff bande par bande, au lieu d'enregistrer l'image entière en une seule fois.
Voir : http://www.mathworks.com/help/matlab/ref/tiff-class.html
L'exemple de code suivant enregistre un fichier image tiff (relativement) volumineux, et affiche une barre d'attente qui progresse pendant l'enregistrement :
%Simulate large image (to be saved as tiff later)
I = imread('peppers.png');
I = repmat(I, [10, 10]); %Image resolution: 5120 x 3840.
t = Tiff('I.tif', 'w');
width = size(I, 2);
height = size(I, 1);
rows_per_strip = 16; %Select 16 rows per strip.
setTag(t, 'ImageLength', height)
setTag(t, 'ImageWidth', width)
setTag(t, 'Photometric', Tiff.Photometric.RGB)
setTag(t, 'BitsPerSample', 8)
setTag(t, 'SamplesPerPixel', 3)
setTag(t, 'RowsPerStrip', rows_per_strip)
setTag(t, 'PlanarConfiguration', Tiff.PlanarConfiguration.Chunky)
setTag(t, 'Compression', Tiff.Compression.LZW)
n_strips = ceil(height / rows_per_strip); %Total number of strips.
h = waitbar(0, 'In process');
%Write the tiff image strip by strip (and advance the waitbar).
for i = 1:n_strips
y0 = (i-1)*rows_per_strip + 1; %First row of current strip.
y1 = min(y0 + rows_per_strip - 1, height); %Last row of current strip.
writeEncodedStrip(t, i, I(y0:y1, :, :)) %Write strip rows y0 to y1.
waitbar(i/n_strips, h); %Update waitbar.
drawnow %Force GUI refresh.
end
close(t)
close(h)