changeset 20665:67e6343cd29a

Add support for colorspace conversion of signed integers images (patch #8709) * scripts/image/private/colorspace_conversion_input_check.m: add support for signed integers. 16 bit signed integers are common and supported by the image package. We might as well support 8 bit signed as well. * scripts/image/hsv2rgb.m, scripts/image/rgb2hsv.m, scripts/image/rgb2ntsc.m: add tests for signed integer images.
author Carnë Draug <carandraug@octave.org>
date Wed, 28 Oct 2015 22:34:43 +0000
parents a278de349250
children e0e2c2ce7e94
files scripts/image/hsv2rgb.m scripts/image/private/colorspace_conversion_input_check.m scripts/image/rgb2hsv.m scripts/image/rgb2ntsc.m
diffstat 4 files changed, 13 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/image/hsv2rgb.m	Wed Oct 28 19:51:02 2015 +0000
+++ b/scripts/image/hsv2rgb.m	Wed Oct 28 22:34:43 2015 +0000
@@ -188,8 +188,10 @@
 %! hsv_double = reshape ([2/3 1/3 1 0 1 1 1 0, 1 1 1 1], [2 2 3]);
 %! hsv_uint8  = reshape (uint8 ([170 85 255 0 255 255 255 0 255 255 255 255]),
 %!                       [2 2 3]);
+%! hsv_int16 = int16 (double (hsv_double * uint16 (65535)) -32768);
 %! expected = reshape ([0 0 1 1 0 1 0 1 1 0 0 1], [2 2 3]);
 %!
 %! assert (hsv2rgb (hsv_double), expected)
 %! assert (hsv2rgb (hsv_uint8), expected)
+%! assert (hsv2rgb (hsv_int16), expected)
 %! assert (hsv2rgb (single (hsv_double)), single (expected), eps (single (2)))
--- a/scripts/image/private/colorspace_conversion_input_check.m	Wed Oct 28 19:51:02 2015 +0000
+++ b/scripts/image/private/colorspace_conversion_input_check.m	Wed Oct 28 22:34:43 2015 +0000
@@ -29,7 +29,8 @@
 
   ## If we have an image convert it into a color map.
   if (! iscolormap (in_arg))
-    if (! any (strcmp (cls, {"uint8", "uint16", "single", "double"})))
+    if (! any (strcmp (cls, {"uint8", "int8", "int16", "uint16", ...
+                             "single", "double"})))
       error ("%s: %s of invalid data type '%s'", func, arg_name, cls);
     elseif (size (in_arg, 3) != 3)
       error ("%s: %s must be a colormap or %s image", func, arg_name, arg_name);
@@ -62,7 +63,13 @@
 
   ## Convert to floating point (remember to leave class single alone)
   if (isinteger (in_arg))
-    in_arg = double (in_arg) / double (intmax (cls));
+    int_max = double (intmax (cls));
+    int_min = double (intmin (cls));
+    if (int_min < 0)
+      in_arg = (double (in_arg) - int_min) / (int_max - int_min);
+    else
+      in_arg = double (in_arg) / int_max;
+    endif
   endif
 
 endfunction
--- a/scripts/image/rgb2hsv.m	Wed Oct 28 19:51:02 2015 +0000
+++ b/scripts/image/rgb2hsv.m	Wed Oct 28 22:34:43 2015 +0000
@@ -166,6 +166,7 @@
 %! rgb_double = reshape ([1 0 1 .5 1 1 0 .5 0 1 1 .5], [2 2 3]);
 %! rgb_uint8  = reshape (uint8 ([255 0 255 128 255 255 0 128 0 255 255 128]),
 %!                       [2 2 3]);
+%! rgb_int16 = int16 (double (rgb_double * uint16 (65535)) -32768);
 %! expected = reshape ([1/6 1/2 5/6 0 1 1 1 0 1 1 1 .5], [2 2 3]);
 %!
 %! assert (rgb2hsv (rgb_double), expected)
--- a/scripts/image/rgb2ntsc.m	Wed Oct 28 19:51:02 2015 +0000
+++ b/scripts/image/rgb2ntsc.m	Wed Oct 28 22:34:43 2015 +0000
@@ -144,6 +144,7 @@
 %! rgb_double = reshape ([1 0 0 0 0 1 0 0 0 0 1 0], [2 2 3]);
 %! rgb_uint8  = reshape (uint8 ([255 0 0 0 0 255 0 0 0 0 255 0]),
 %!                       [2 2 3]);
+%! rgb_int16 = int16 (double (rgb_double * uint16 (65535)) -32768);
 %! expected = reshape ([.299 .587 .114 0 .596 -.274 -.322 0 .211 -.523 .312 0],
 %!                     [2 2 3]);
 %!