comparison scripts/io/Tiff.m @ 31153:c66d6c7f025e

Tiff: implemented write method for stripped images * __tiff__.cc(F_tiff_write__): implemented internal function for processing write method arguments. * __tiff__.cc(write_stripped_image): implemented support for writing to a stripped image for all cases exept logical images. * Tiff.m: added write method to the Tiff class.
author magedrifaat <magedrifaat@gmail.com>
date Wed, 03 Aug 2022 22:06:43 +0200
parents 6fb54834aa93
children 828b7cc9aa36
comparison
equal deleted inserted replaced
31152:2244617f4da5 31153:c66d6c7f025e
114 error ("Image file was closed"); 114 error ("Image file was closed");
115 endif 115 endif
116 argout = __tiff_read__ (t.tiff_handle); 116 argout = __tiff_read__ (t.tiff_handle);
117 endfunction 117 endfunction
118 118
119 function write (t, imageData)
120 if (t.closed)
121 error ("Image file was closed");
122 endif
123 __tiff_write__ (t.tiff_handle, imageData);
124 endfunction
125
119 function writeEncodedStrip (t, stripNumber, imageData) 126 function writeEncodedStrip (t, stripNumber, imageData)
120 if (t.closed) 127 if (t.closed)
121 error ("Image file was closed"); 128 error ("Image file was closed");
122 endif 129 endif
123 __tiff_write_encoded_strip__ (t.tiff_handle, stripNumber, imageData); 130 __tiff_write_encoded_strip__ (t.tiff_handle, stripNumber, imageData);
186 193
187 %!function verify_data (filename, data, ex_size) 194 %!function verify_data (filename, data, ex_size)
188 %! img = Tiff (filename, "r"); 195 %! img = Tiff (filename, "r");
189 %! data2 = img.read (); 196 %! data2 = img.read ();
190 %! assert (size (data2), ex_size); 197 %! assert (size (data2), ex_size);
191 %! assert (data2, resize (data, size (data2)), -1e5); 198 %! assert (data2, resize (data, size (data2)));
192 %! img.close (); 199 %! img.close ();
193 %!endfunction 200 %!endfunction
194 201
195 ## test setTag and getTag for scalar tags 202 ## test setTag and getTag for scalar tags
196 %!testif HAVE_TIFF 203 %!testif HAVE_TIFF
479 ## test multi-strip grayscale image 486 ## test multi-strip grayscale image
480 %!testif HAVE_TIFF 487 %!testif HAVE_TIFF
481 %! function test_fn (filename) 488 %! function test_fn (filename)
482 %! img = Tiff (filename, "w"); 489 %! img = Tiff (filename, "w");
483 %! setTag (img, struct ("ImageLength", 20, "ImageWidth", 20, 490 %! setTag (img, struct ("ImageLength", 20, "ImageWidth", 20,
484 %! "BitsPerSample", 16, "RowsPerStrip", 2)); 491 %! "BitsPerSample", 16, "RowsPerStrip", 3));
485 %! data = uint16 (reshape (1:400, [20, 20])); 492 %! data = uint16 (reshape (1:400, [20, 20]));
486 %! for strip = 1:10 493 %! for strip = 1:7
487 %! writeEncodedStrip (img, strip, data(strip * 2 - 1: strip * 2, :)); 494 %! writeEncodedStrip (img, strip, data(strip * 3 - 2: min(strip * 3, 20), :));
488 %! endfor 495 %! endfor
489 %! img.close (); 496 %! img.close ();
490 %! verify_data (filename, data, [20, 20]); 497 %! verify_data (filename, data, [20, 20]);
491 %! endfunction 498 %! endfunction
492 %! file_wrapper (@test_fn); 499 %! file_wrapper (@test_fn);
512 %!testif HAVE_TIFF 519 %!testif HAVE_TIFF
513 %! function test_fn (filename) 520 %! function test_fn (filename)
514 %! img = Tiff (filename, "w"); 521 %! img = Tiff (filename, "w");
515 %! setTag (img, struct ("ImageLength", 20, "ImageWidth", 20, 522 %! setTag (img, struct ("ImageLength", 20, "ImageWidth", 20,
516 %! "BitsPerSample", 16, "SamplesPerPixel", 3, 523 %! "BitsPerSample", 16, "SamplesPerPixel", 3,
517 %! "RowsPerStrip", 2, "PlanarConfiguration", 2, 524 %! "RowsPerStrip", 3, "PlanarConfiguration", 2,
518 %! "PhotometricInterpretation", 2)); 525 %! "PhotometricInterpretation", 2));
519 %! data = uint16 (reshape (1:1200, [20, 20, 3])); 526 %! data = uint16 (reshape (1:1200, [20, 20, 3]));
520 %! strip = 1; 527 %! strip = 1;
521 %! for sample = 1:3 528 %! for sample = 1:3
522 %! for row = 1:2:20 529 %! for row = 1:3:20
523 %! writeEncodedStrip (img, strip, data(row: row + 1, :, sample)); 530 %! writeEncodedStrip (img, strip, data(row: min(row + 2, 20), :, sample));
524 %! strip = strip + 1; 531 %! strip = strip + 1;
525 %! endfor 532 %! endfor
526 %! endfor 533 %! endfor
527 %! img.close (); 534 %! img.close ();
528 %! verify_data (filename, data, [20, 20, 3]); 535 %! verify_data (filename, data, [20, 20, 3]);