559
|
1 function Y = ind2gray(X,map) |
904
|
2 |
|
3 # Convert an octave indexed image to a gray scale intensity image. |
559
|
4 # |
904
|
5 # Y = ind2gray(X) converts an indexed image to a gray scale intensity |
|
6 # image. The current colormap is used to determine the intensities. |
|
7 # The intensity values lie between 0 and 1 inclusive. |
559
|
8 # |
904
|
9 # Y = ind2gray(X,map) uses the specified colormap instead of the current |
|
10 # one in the conversion process. |
559
|
11 # |
904
|
12 # SEE ALSO: gray2ind, rgb2ntsc, image, colormap |
559
|
13 |
|
14 if (nargin == 1) |
|
15 map = colormap; |
|
16 endif |
|
17 |
|
18 # Convert colormap to intensity values. |
|
19 yiq = rgb2ntsc(map); |
|
20 y = yiq(:,1); |
|
21 |
|
22 # We need Fortran indexing capability, but be sure to save the user's |
|
23 # preference. |
|
24 pref = do_fortran_indexing; |
|
25 do_fortran_indexing = "true"; |
|
26 |
|
27 # Replace indices in the input matrix with indexed values in the output |
|
28 # matrix. |
|
29 [rows, cols] = size(X); |
|
30 Y = y(X(:)); |
|
31 Y = reshape(Y,rows,cols); |
|
32 |
|
33 # Restore the user's preference. |
|
34 do_fortran_indexing = pref; |
|
35 |
|
36 endfunction |