2847
|
1 ## Copyright (C) 1996, 1997 John W. Eaton |
2313
|
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. |
1024
|
19 |
3381
|
20 ## -*- texinfo -*- |
4836
|
21 ## @deftypefn {Function File} {} imshow (@var{i}) |
|
22 ## @deftypefnx {Function File} {} imshow (@var{x}, @var{map}) |
3373
|
23 ## @deftypefnx {Function File} {} imshow (@var{x}, @var{n}) |
|
24 ## @deftypefnx {Function File} {} imshow (@var{i}, @var{n}) |
|
25 ## @deftypefnx {Function File} {} imshow (@var{r}, @var{g}, @var{b}) |
4836
|
26 ## Display an image. |
3426
|
27 ## |
4836
|
28 ## @code{imshow (@var{x})} displays an intensity image, estimating the |
|
29 ## number of gray levels. |
3426
|
30 ## |
3373
|
31 ## @code{imshow (@var{x}, @var{map})} displays an indexed image using the |
|
32 ## specified colormap. |
3426
|
33 ## |
4836
|
34 ## @code{imshow (@var{i}, @var{N})} displays a gray scale intensity image of |
|
35 ## N levels. |
3426
|
36 ## |
3373
|
37 ## @code{imshow (@var{r}, @var{g}, @var{b})} displays an RGB image. |
4836
|
38 ## |
|
39 ## The string @code{truesize} can always be used as an optional |
|
40 ## final argument to prevent automatic zooming of the image. |
3373
|
41 ## @end deftypefn |
4836
|
42 ## |
3457
|
43 ## @seealso{image, imagesc, colormap, gray2ind, and rgb2ind} |
904
|
44 |
3202
|
45 ## Author: Tony Richardson <arichard@stark.cc.oh.us> |
2312
|
46 ## Created: July 1994 |
|
47 ## Adapted-By: jwe |
559
|
48 |
4836
|
49 function imshow (varargin) |
|
50 |
|
51 usage_str = "imshow (x) or imshow (x, map) or imshow (i, N) or imshow (r, g, b)"; |
559
|
52 |
4836
|
53 if (nargin == 0 || nargin > 4) |
|
54 usage (usage_str); |
|
55 endif |
|
56 |
|
57 ## Count nr of matrix arguments. |
|
58 mvars = 0; |
|
59 while (mvars < nargin && ismatrix (varargin{mvars+1})) |
|
60 mvars++; |
|
61 endwhile |
|
62 |
|
63 if (mvars < 1 || mvars > 3) |
|
64 usage (usage_str); |
|
65 endif |
|
66 |
|
67 ## All except imshow (r, g, b) |
|
68 |
|
69 if (mvars != 3) |
|
70 I = varargin{1}; |
4912
|
71 if (iscomplex (I)) |
4914
|
72 warning ("imshow: displaying real part of complex image"); |
|
73 I = real (I); |
4911
|
74 endif |
|
75 if (max (I(:)) <= 1) |
4912
|
76 ## image in [0-1]; scale to [0-255] |
4836
|
77 I = I * 255; |
|
78 M = gray (256); |
559
|
79 endif |
|
80 endif |
|
81 |
4836
|
82 if (mvars == 1) |
|
83 ## imshow (x) |
|
84 ## Grayscale image [0-N] -- estimate gray levels. |
4912
|
85 N = 2 ^ ceil (log2 (max (I(:)))); |
4911
|
86 if (N <= 65536) |
|
87 M = gray (N); |
|
88 else |
|
89 M = gray (256); |
|
90 I = I / max (I(:)) * 255; |
|
91 endif |
4836
|
92 elseif (mvars == 2) |
|
93 ## imshow (x, map) or imshow (x, N) |
|
94 M = varargin{2}; |
|
95 if (isscalar (M)) |
|
96 M = gray (M); |
|
97 endif |
|
98 elseif (mvars == 3) |
|
99 ## imshow (r, g, b) |
|
100 r = varargin{1}; |
|
101 g = varargin{2}; |
|
102 b = varargin{3}; |
|
103 tmp = [r; g; b]; |
4912
|
104 if (iscomplex (tmp)) |
|
105 warning ("imshow: displaying real part of complex rgb image"); |
|
106 r = real (r); |
|
107 g = real (g); |
|
108 b = real (b); |
4911
|
109 endif |
4836
|
110 if (max (tmp(:)) > 1) |
|
111 ## Normalise to [0-1]. |
4914
|
112 r = r / 255; |
|
113 g = g / 255; |
|
114 b = b / 255; |
4836
|
115 endif |
|
116 [I, M] = rgb2ind (r, g, b); |
|
117 endif |
|
118 |
|
119 ## Check for "truesize". |
|
120 zoom = []; |
|
121 for i = mvars+1:nargin |
|
122 if (isstr (varargin{i}) && strcmp (varargin{i}, "truesize")) |
|
123 zoom = 1; |
|
124 endif |
|
125 endfor |
|
126 |
|
127 colormap (M); |
|
128 image (I, zoom); |
559
|
129 |
|
130 endfunction |
4836
|
131 |
|
132 %!error imshow () # no arguments |
|
133 %!error imshow (1, 2, 3, 4, 5) # too many arguments |
|
134 %!error imshow ([1,2], [2,3], [3,4], [4,5]) # too many matrix arguments |
|
135 %!error imshow ("image.png") # filename not accepted as argument |
|
136 |
|
137 %!demo |
|
138 %! imshow (loadimage ("default.img")); |
|
139 |
|
140 %!demo |
|
141 %! I = loadimage ("default.img"); |
|
142 %! imshow (I, "truesize") |
|
143 |
|
144 %!demo |
|
145 %! [I, M] = loadimage ("default.img"); |
|
146 %! imshow(I, M); |