changeset 19803:70911df8ad28

gray2ind: return uint8 when (n <= 256) instead of (n < 256) (bug #44309) * gray2ind.m: the class of the indexed image returned by gray2ind is dependent on the number of indices to use. If there are 256 or less, we return uint8, and uint16 otherwise. Add more tests for the limits.
author Carnë Draug <carandraug@octave.org>
date Thu, 19 Feb 2015 14:29:34 +0000
parents 95a94c98c884
children 35a8e1beac8d
files scripts/image/gray2ind.m
diffstat 1 files changed, 10 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/image/gray2ind.m	Thu Feb 19 13:26:40 2015 +0100
+++ b/scripts/image/gray2ind.m	Thu Feb 19 14:29:34 2015 +0000
@@ -75,7 +75,7 @@
 
   ## Note: no separate call to round () necessary because
   ##       type conversion does that automatically.
-  if (n < 256)
+  if (n <= 256)
     I = uint8 (I);
   else
     I = uint16 (I);
@@ -94,6 +94,15 @@
 %! g2i = gray2ind (i2g, 100);
 %! assert (g2i, uint8 (0:99));
 
+%!assert (gray2ind ([0 0.25 0.5 1], 256), uint8 ([0 64 128 255]))
+%!assert (gray2ind ([0 (1/511) (1/510) 1-(1/509) 1-(1/510) 1], 256),
+%!        uint8 ([0 0 1 254 255 255]))
+
+%!test
+%! assert (class (gray2ind ([0.0 0.5 1.0], 255)), "uint8")
+%! assert (class (gray2ind ([0.0 0.5 1.0], 256)), "uint8")
+%! assert (class (gray2ind ([0.0 0.5 1.0], 257)), "uint16")
+
 %% Test input validation
 %!error gray2ind ()
 %!error gray2ind (1,2,3)