home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / octa21eb.zip / octave / SCRIPTS.ZIP / scripts.fat / image / rgb2ind.m < prev    next >
Text File  |  1998-05-23  |  2KB  |  65 lines

  1. ## Copyright (C) 1996 John W. Eaton
  2. ##
  3. ## This file is part of Octave.
  4. ##
  5. ## Octave is free software; you can redistribute it and/or modify it
  6. ## under the terms of the GNU General Public License as published by
  7. ## the Free Software Foundation; either version 2, or (at your option)
  8. ## any later version.
  9. ##
  10. ## Octave is distributed in the hope that it will be useful, but
  11. ## WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13. ## General Public License for more details.
  14. ##
  15. ## You should have received a copy of the GNU General Public License
  16. ## along with Octave; see the file COPYING.  If not, write to the Free
  17. ## Software Foundation, 59 Temple Place - Suite 330, Boston, MA
  18. ## 02111-1307, USA.
  19.  
  20. ## Convert and RGB image to an octave indexed image.
  21. ##
  22. ## [X, map] = rgb2ind (R, G, B)
  23. ##
  24. ## SEE ALSO: ind2rgb, rgb2ntsc.
  25. ##
  26. ## Bugs: The color map may have duplicate entries.
  27.  
  28. ## Author: Tony Richardson <amr@mpl.ucsd.edu>
  29. ## Created: July 1994
  30. ## Adapted-By: jwe
  31.  
  32. function [X, map] = rgb2ind (R, G, B)
  33.  
  34.   if (nargin != 3)
  35.     usage ("[X, map] = rgb2ind (R, G, B)");
  36.   endif
  37.  
  38.   if (size (R) != size (G) || size (R) != size (B))
  39.     error ("rgb2ind: arguments must all have the same size");
  40.   endif
  41.  
  42.   [hi, wi] = size (R);
  43.  
  44.   X = zeros (hi, wi);
  45.  
  46.   map = zeros (hi*wi, 3);
  47.  
  48.   pref = do_fortran_indexing;
  49.  
  50.   unwind_protect
  51.  
  52.     do_fortran_indexing = 1;
  53.  
  54.     map(:,1) = R(:);
  55.     map(:,2) = G(:);
  56.     map(:,3) = B(:);
  57.  
  58.     X(:) = 1:(hi*wi);
  59.  
  60.   unwind_protect_cleanup
  61.     do_fortran_indexing = pref;
  62.   end_unwind_protect
  63.  
  64. endfunction
  65.