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