1. carandraug
  2. octave


carandraug  committed 37a21f6

rgb2ind: great speedup increase creating indexed image (changeset 89c8d8f made a proper indexed image that used less memory but was much slower to create)

  • Participants
  • Parent commits dffb28f
  • Branches default

Comments (0)

Files changed (1)

File scripts/image/rgb2ind.m

View file
     error ("rgb2ind: arguments must all have the same size");
-  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)