# HG changeset patch # User Adam H Aitkenhead # Date 1368042491 -3600 # Node ID 8d32a887754a4bb448b10bd359e7a7335adb66b4 # Parent ace0f60672ec94cacaa567162627a4fbc0a92767 rgb2ind.m: Fix handling ND images. * rgb2ind.m: Fix handling of ND images. diff -r ace0f60672ec -r 8d32a887754a scripts/image/rgb2ind.m --- a/scripts/image/rgb2ind.m Wed May 08 14:57:45 2013 -0400 +++ b/scripts/image/rgb2ind.m Wed May 08 20:48:11 2013 +0100 @@ -108,6 +108,8 @@ endif endif + sz = size (rgb); + ## Apply a limited colormap if required if (exist ("option","var")) @@ -138,6 +140,12 @@ endif + ## If image is an ND array, convert it to a tiled 2D image + ## before processing it with Graphicsmagick + if numel (sz)>3 + rgb = reshape (rgb, [prod(sz(1:end-2)), sz(end-1), 3]); + end + ## Prepare the Graphicsmagick dithering option if strcmp (dither_option, "nodither") ditherstr = "+dither"; @@ -156,7 +164,6 @@ endif ## Conversion of rgb image to x,map - sz = size (rgb); pr = prod (sz(1:end-1)); x = zeros (sz(1:end-1)); [map,~,x(:)] = unique (reshape(rgb, [pr, 3]), "rows");