changeset 31211:edbd725ee76c

imwrite: fixed tests to reflect alpha channel behavior for Tiff images * scripts/image/imwrite.m: modified tests to correctly handled the new behavior for alpha channel in Tiff images. * scripts/image/imread.m: added a note in the function documentation about the alpha channel behavior for Tiff images.
author magedrifaat <magedrifaat@gmail.com>
date Tue, 06 Sep 2022 21:12:29 +0200
parents e83a62df599b
children 13132e7834f5
files scripts/image/imread.m scripts/image/imwrite.m
diffstat 2 files changed, 14 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/image/imread.m	Tue Sep 06 20:57:50 2022 +0200
+++ b/scripts/image/imread.m	Tue Sep 06 21:12:29 2022 +0200
@@ -49,6 +49,12 @@
 ## the first.  In some rare cases this may be incorrect and @code{imfinfo} can
 ## be used to obtain the colormap of each image.
 ##
+## For TIFF images, the transaprency channel is appended to the rest of the 
+## channels in @var{img}, and @var{alpha} is always empty for matlab
+## compatibility. To differentiate between RGBA and CMYK images, check
+## @code{ColorType} or @code{PhotometricInterpretation} fields in the output
+## of @code{imfinfo}.
+##
 ## See the Octave manual for more information in representing images.
 ## (@pxref{Representing Images})
 ##
--- a/scripts/image/imwrite.m	Tue Sep 06 20:57:50 2022 +0200
+++ b/scripts/image/imwrite.m	Tue Sep 06 21:12:29 2022 +0200
@@ -160,8 +160,8 @@
 %! gray  = randi (255, 10, 10, 1, "uint8");
 %! alpha = randi (255, 10, 10, 1, "uint8");
 %! [r, ~, a] = write_and_read (".tif", gray, "Alpha", alpha);
-%! assert (r, gray);
-%! assert (a, alpha);
+%! assert (r, cat (3, gray, alpha));
+%! assert (a, []);
 
 ## multipage grayscale uint8 images
 %!testif HAVE_MAGICK
@@ -174,8 +174,8 @@
 %! gray  = randi (255, 10, 10, 3, 5, "uint8");
 %! alpha = randi (255, 10, 10, 1, 5, "uint8");
 %! [r, ~, a] = write_and_read (".tif", gray, "Alpha", alpha);
-%! assert (r, gray);
-%! assert (a, alpha);
+%! assert (r, cat (3, gray, alpha));
+%! assert (a, []);
 
 ## typical usage with RGB uint8 images
 %!testif HAVE_MAGICK
@@ -188,8 +188,8 @@
 %! rgb   = randi (255, 10, 10, 3, "uint8");
 %! alpha = randi (255, 10, 10, 1, "uint8");
 %! [r, ~, a] = write_and_read (".tif", rgb, "Alpha", alpha);
-%! assert (r, rgb);
-%! assert (a, alpha);
+%! assert (r, cat (3, rgb, alpha));
+%! assert (a, []);
 
 ## multipage RGB uint8 images
 %!testif HAVE_MAGICK
@@ -202,8 +202,8 @@
 %! rgb   = randi (255, 10, 10, 3, 5, "uint8");
 %! alpha = randi (255, 10, 10, 1, 5, "uint8");
 %! [r, ~, a] = write_and_read (".tif", rgb, "Alpha", alpha);
-%! assert (r, rgb);
-%! assert (a, alpha);
+%! assert (r, cat (3, rgb, alpha));
+%! assert (a, []);
 
 %!testif HAVE_MAGICK
 %! gray = repmat (uint8 (0:255), 100, 1);