# HG changeset patch # User Carnë Draug # Date 1353003467 0 # Node ID 37a21f615d6729929aac67a205590f7091b3d935 # Parent dffb28f47ea8c1f7b1de2064c0f0e52e88124c85 rgb2ind: great speedup increase creating indexed image (changeset 89c8d8f made a proper indexed image that used less memory but was much slower to create) diff -r dffb28f47ea8 -r 37a21f615d67 scripts/image/rgb2ind.m --- a/scripts/image/rgb2ind.m Mon Nov 12 05:32:02 2012 +0000 +++ b/scripts/image/rgb2ind.m Thu Nov 15 18:17:47 2012 +0000 @@ -51,12 +51,9 @@ error ("rgb2ind: arguments must all have the same size"); endif - map = unique([R(:) G(:) B(:)], "rows"); - ## RGB values for each point of the image are listed and expanded to compare - ## with the colormap values. We then find the indexes when all 3 match and - ## rebuild the image to its original size - [x, ~] = find (squeeze (all (bsxfun (@eq, reshape(map', [1 3 rows(map)]), [R(:) G(:) B(:)]), 2))'); - x = reshape (x, size (R)); + map = unique([R(:) G(:) B(:)], "rows"); + [~, x] = ismember ([R(:) G(:) B(:)], map, "rows"); + x = reshape (x, size (R)); ## a colormap is of class double and values between 0 and 1 switch class (R)