Reputation: 5235
in Matlab,
if I do:
output = false(5, 5);
imshow(output);
it will show me a black square instead of a white binary square image. Is there any reason to this? How can I output a white binary square?
Upvotes: 1
Views: 366
Reputation: 124553
You could also change the figure's colormap to customize how MATLAB maps values to colors:
BW = [false,true;true,false];
imshow(BW)
set(gcf, 'Colormap',[1,1,1;0,0,0])
Upvotes: 1
Reputation: 3031
You could use imcomplement
imshow(imcomplement(false(5, 5)))
or modify the default color mapping (quoting from imshow's documentation)
imshow(X,map)
displays the indexed image X with the colormap map. A color map matrix may have any number of rows, but it must have exactly 3 columns. Each row is interpreted as a color, with the first element specifying the intensity of red light, the second green, and the third blue. Color intensity can be specified on the interval 0.0 to 1.0.
Upvotes: 1
Reputation: 20915
The reason is that false
is mapped to 0
, and true
is mapped to 1
.
Also, when showing images, higher number is shown by higher intensity. White has more intensity than black.
Another way to think about it, is that usually you have 256 values - 0-255
. 0
is totally black and 255
is totally white. Now, imagine that you do a quantization to two colors. It is now obvious that 0
should be black.
In order to show white square, use
output = true(5,5)
Upvotes: 2