comparison scripts/image/ind2gray.m @ 15689:14b7679891dd

ind2sub ind2gray: merge common code in private function, expanding fix for images when integers, input check, and expansion of colormap to ind2gray.
author Carnë Draug <carandraug+dev@gmail.com>
date Mon, 12 Nov 2012 04:53:42 +0000
parents 1f911333ed3d
children a1b634240352
comparison
equal deleted inserted replaced
15688:4db08f52a6ed 15689:14b7679891dd
18 18
19 ## -*- texinfo -*- 19 ## -*- texinfo -*-
20 ## @deftypefn {Function File} {} ind2gray (@var{x}) 20 ## @deftypefn {Function File} {} ind2gray (@var{x})
21 ## @deftypefnx {Function File} {} ind2gray (@var{x}, @var{map}) 21 ## @deftypefnx {Function File} {} ind2gray (@var{x}, @var{map})
22 ## Convert a color indexed image to a gray scale intensity image. 22 ## Convert a color indexed image to a gray scale intensity image.
23 ## If the colormap doesn't contain enough colors, pad it with the
24 ## last color in the map.
23 ## If @var{map} is omitted, the current colormap is used to determine the 25 ## If @var{map} is omitted, the current colormap is used to determine the
24 ## intensities. 26 ## intensities.
25 ## @seealso{gray2ind, ind2rgb} 27 ## @seealso{gray2ind, ind2rgb}
26 ## @end deftypefn 28 ## @end deftypefn
27 29
29 ## Created: July 1994 31 ## Created: July 1994
30 ## Adapted-By: jwe 32 ## Adapted-By: jwe
31 33
32 function y = ind2gray (x, map) 34 function y = ind2gray (x, map)
33 35
36 ## Do we have the right number of inputs?
34 if (nargin < 1 || nargin > 2) 37 if (nargin < 1 || nargin > 2)
35 print_usage (); 38 print_usage ();
36 elseif (nargin == 1) 39 elseif (nargin == 1)
37 map = colormap (); 40 map = colormap ();
38 endif 41 endif
39 42
40 [rows, cols] = size (x); 43 [x, map] = ind2x ("ind2gray", x, map);
41 44
42 ## Convert colormap to intensity values (the first column of the 45 ## Convert colormap to intensity values (the first column of the
43 ## result of the call to rgb2ntsc) and then replace indices in 46 ## result of the call to rgb2ntsc) and then replace indices in
44 ## the input matrix with indexed values in the output matrix (indexed 47 ## the input matrix with indexed values in the output matrix (indexed
45 ## values are the result of indexing the intensity values by the 48 ## values are the result of indexing the intensity values by the
46 ## elements of x(:)). 49 ## elements of x(:)).
47 50 y = reshape (((rgb2ntsc (map))(:,1))(x(:)), rows (x), columns (x));
48 y = reshape (((rgb2ntsc (map))(:,1))(x(:)), rows, cols);
49 51
50 endfunction 52 endfunction