# HG changeset patch # User Carnë Draug # Date 1370003224 -3600 # Node ID 4c11e9bcb7968e6b386843d014c3808c458fa2af # Parent 736dca8371eee979e810c40865da592af24c8c11 ind2rgb: add support for multidimensional indexed images. diff -r 736dca8371ee -r 4c11e9bcb796 scripts/image/ind2rgb.m --- a/scripts/image/ind2rgb.m Thu May 30 14:19:59 2013 -0400 +++ b/scripts/image/ind2rgb.m Fri May 31 13:27:04 2013 +0100 @@ -31,6 +31,8 @@ ## channels). Alternatively, the individual red, green, and blue color matrices ## of size MxN may be returned. ## +## Multidimensional indexed images (of size MxNx1xK) are also supported. +## ## @seealso{rgb2ind, ind2gray, hsv2rgb, ntsc2rgb} ## @end deftypefn @@ -53,7 +55,14 @@ ## Use ND array if only one output is requested. if (nargout <= 1) - R = reshape ([R(:); G(:); B(:)], [sz, 3]); + if (ndims (x) == 2) + R = reshape ([R(:); G(:); B(:)], [sz, 3]); + elseif (ndims (x) == 4) + R = permute (reshape ([R(:); G(:); B(:)], [sz(1) sz(2) sz(4) 3]), [1 2 4 3]); + else + ## we should never reach here since ind2x() should filter them out + error ("ind2rgb: an indexed image must have 2 or 4 dimensions."); + endif endif endfunction diff -r 736dca8371ee -r 4c11e9bcb796 scripts/image/private/ind2x.m --- a/scripts/image/private/ind2x.m Thu May 30 14:19:59 2013 -0400 +++ b/scripts/image/private/ind2x.m Fri May 31 13:27:04 2013 +0100 @@ -22,7 +22,11 @@ function [x, map] = ind2x (caller, x, map) ## Check if X is an indexed image. - if (ndims (x) < 2 || issparse (x) || (isfloat (x) && ! isindex (x)) || + ## an indexed image is defined has having only 2D, and that's how matlab + ## behaves. But we want to support ND images, so we will allow up to 4D + ## and check that the 3rd is a singleton + if (all (ndims (x) != [2 4]) || size (x, 3) != 1 || issparse (x) || + (isfloat (x) && ! isindex (x)) || ! any (strcmp (class (x), {"uint8", "uint16", "single", "double"}))) error ("%s: X must be an indexed image", caller); endif