home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / octa21eb.zip / octave / SCRIPTS.ZIP / scripts / image / ind2gray.m < prev    next >
Text File  |  1996-10-11  |  2KB  |  69 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 an octave indexed image to a gray scale intensity image.
  21. ##
  22. ## Y = ind2gray (X) converts an indexed image to a gray scale intensity
  23. ## image.  The current colormap is used to determine the intensities.
  24. ## The intensity values lie between 0 and 1 inclusive.
  25. ##
  26. ## Y = ind2gray (X, map) uses the specified colormap instead of the
  27. ## current one in the conversion process.
  28. ##
  29. ## SEE ALSO: gray2ind, rgb2ntsc, image, colormap
  30.  
  31. ## Author: Tony Richardson <amr@mpl.ucsd.edu>
  32. ## Created: July 1994
  33. ## Adapted-By: jwe
  34.  
  35. function Y = ind2gray (X, map)
  36.  
  37.   if (nargin < 1 || nargin > 2)
  38.     usage ("ind2gray (X, map)");
  39.   elseif (nargin == 1)
  40.     map = colormap ();
  41.   endif
  42.  
  43.   ## Convert colormap to intensity values.
  44.  
  45.   yiq = rgb2ntsc (map);
  46.   y = yiq(:,1);
  47.  
  48.   ## We need Fortran indexing capability, but be sure to save the user's
  49.   ## preference.
  50.  
  51.   pref = do_fortran_indexing;
  52.  
  53.   unwind_protect
  54.  
  55.     do_fortran_indexing = 1;
  56.  
  57.     ## Replace indices in the input matrix with indexed values in the output
  58.     ## matrix.
  59.  
  60.     [rows, cols] = size (X);
  61.     Y = y(X(:));
  62.     Y = reshape (Y, rows, cols);
  63.  
  64.   unwind_protect_cleanup
  65.     do_fortran_indexing = pref;
  66.   end_unwind_protect
  67.  
  68. endfunction
  69.