changeset 16434:aa81cfa5c359

ind2x.m and ind2rgb.m: Enable handling of ND images * scripts/image/private/ind2x.m: Allow input image to have >= 2 dimensions * scripts/image/ind2rgb.m: Enable handling of ND images
author Adam H Aitkenhead <adamhaitkenhead@gmail.com>
date Thu, 04 Apr 2013 20:18:54 +0100
parents 28136851099a
children 22c0e0df1dbc
files scripts/image/ind2rgb.m scripts/image/private/ind2x.m
diffstat 2 files changed, 7 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/image/ind2rgb.m	Wed Apr 03 00:10:56 2013 -0400
+++ b/scripts/image/ind2rgb.m	Thu Apr 04 20:18:54 2013 +0100
@@ -46,15 +46,14 @@
   [x, map] = ind2x ("ind2rgb", x, map);
 
   ## Compute result
-  [row, col] = size (x);
-  R = reshape (map(x(:), 1), row, col);
-  G = reshape (map(x(:), 2), row, col);
-  B = reshape (map(x(:), 3), row, col);
+  sz = size (x);
+  R = reshape (map(x(:), 1), sz);
+  G = reshape (map(x(:), 2), sz);
+  B = reshape (map(x(:), 3), sz);
 
-  ## Use 3D array if only one output is requested.
+  ## Use ND array if only one output is requested.
   if (nargout <= 1)
-    R(:,:,2) = G;
-    R(:,:,3) = B;
+    R = reshape ([R(:); G(:); B(:)], [sz, 3]);
   endif
 
 endfunction
--- a/scripts/image/private/ind2x.m	Wed Apr 03 00:10:56 2013 -0400
+++ b/scripts/image/private/ind2x.m	Thu Apr 04 20:18:54 2013 +0100
@@ -22,7 +22,7 @@
 function [x, map] = ind2x (caller, x, map)
 
   ## Check if X is an indexed image.
-  if (ndims (x) != 2 || issparse (x) || (isfloat (x) && ! isindex (x)) ||
+  if (ndims (x) < 2 || issparse (x) || (isfloat (x) && ! isindex (x)) ||
       ! any (strcmp (class (x), {"uint8", "uint16", "single", "double"})))
     error ("%s: X must be an indexed image", caller);
   endif