Mercurial > hg > octave-shane
changeset 15692:37a21f615d67
rgb2ind: great speedup increase creating indexed image (changeset 89c8d8f made a proper indexed image that used less memory but was much slower to create)
author | Carnë Draug <carandraug+dev@gmail.com> |
---|---|
date | Thu, 15 Nov 2012 18:17:47 +0000 |
parents | dffb28f47ea8 |
children | a1b634240352 |
files | scripts/image/rgb2ind.m |
diffstat | 1 files changed, 3 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/image/rgb2ind.m +++ b/scripts/image/rgb2ind.m @@ -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)