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