comparison scripts/image/imshow.m @ 7328:d0784e593d39

[project @ 2007-12-20 07:24:02 by jwe]
author jwe
date Thu, 20 Dec 2007 07:24:02 +0000
parents 359f464342b3
children 3ed85de5922c
comparison
equal deleted inserted replaced
7327:9af6f0a214ee 7328:d0784e593d39
56 56
57 if (nargin == 0) 57 if (nargin == 0)
58 print_usage (); 58 print_usage ();
59 endif 59 endif
60 60
61 display_range = []; 61 display_range = NA;
62 true_color = false; 62 true_color = false;
63 indexed = false; 63 indexed = false;
64 64
65 ## Get the image. 65 ## Get the image.
66 if (ischar (im)) 66 if (ischar (im))
114 error ("imshow: argument number %d is invalid", narg+1); 114 error ("imshow: argument number %d is invalid", narg+1);
115 endif 115 endif
116 endwhile 116 endwhile
117 117
118 ## Set default display range. 118 ## Set default display range.
119 if (true_color || isempty (display_range)) 119 if (isempty (display_range))
120 display_range = [min(im(:)), max(im(:))]; 120 display_range = [min(im(:)), max(im(:))];
121 else 121 else
122 t = class (im); 122 t = class (im);
123 switch (t) 123 switch (t)
124 case {"double", "single", "logical"} 124 case {"double", "single", "logical"}
125 display_range = [0, 1]; 125 display_range = [0, 1];
126 case {"int8", "int16", "int32", "uint8", "uint16", "uint32"} 126 case {"int8", "int16", "int32", "uint8", "uint16", "uint32"}
127 display_range = [intmin(t), intmax(t)]; 127 ## For compatibility, uint8 data should not be handled as
128 ## double. Doing so is a quick fix to allow the images to be
129 ## displayed correctly.
130 display_range = double ([intmin(t), intmax(t)]);
128 otherwise 131 otherwise
129 error ("imshow: invalid data type for image"); 132 error ("imshow: invalid data type for image");
130 endswitch 133 endswitch
131 endif 134 endif
132 135
142 "imshow: pixels with NaN or NA values are set to minimum pixel value"); 145 "imshow: pixels with NaN or NA values are set to minimum pixel value");
143 im(nans) = display_range(1); 146 im(nans) = display_range(1);
144 endif 147 endif
145 148
146 ## This is for compatibility. 149 ## This is for compatibility.
147 if (ismember (class (im), {"int8", "int16", "uint32", "int32", "single"})) 150 if (! indexed || islogical (im))
148 im = double (im); 151 im = double (im);
149 endif 152 endif
150 153
151 ## Scale the image to the interval [0, 1] according to display_range. 154 ## Scale the image to the interval [0, 1] according to display_range.
152 if (! (true_color || indexed || islogical (im))) 155 if (! (true_color || indexed || islogical (im)))
153 class (im) 156 low = display_range(1);
154 im 157 high = display_range(2);
155 low = display_range(1) 158 im = (im-low)/(high-low);
156 high = display_range(2)
157 im = (im-low)/(high-low)
158 im(im < 0) = 0; 159 im(im < 0) = 0;
159 im(im > 1) = 1; 160 im(im > 1) = 1;
160 endif 161 endif
161 162
162 if (true_color) 163 if (true_color)