So I am a bit confused as to why this is happening.
I have a binary image:
Now I want to convert this binary image into RGB space, so therefore I use the dstack
function to concatenate the 3rd axis
Everything works fine so far, but now I have to multiply the out_image
array by 255
to reflect white in RGB space, and this is where the problem occurs everything turns black
But if I plot another random image, everything is fine so what is happening here, I've also played around with the cmap
but regardless of what kind of cmap
I use it always turns out to be black when multiplied by 255
Any ideas?
The solution for the problem in the question would be not to multiply the array with 255
.
The other option is to reduce the datatype of the image to unsigned int8,out_image = out_image.astype(np.uint8)
Let me explain why:
A single channel image can have arbitrary values and datatype. The color will be determined by the colormap to be used, and if required, normalized to a certain range.
In contrast, 3 channel RGB arrays are assumed by imshow
to be in two ranges, [0., 1.]
or [0,255]
. ("3-dimensional arrays must be of dtype unsigned byte, unsigned short, float32 or float64").
The range to use will be selected by the datatype of the array:
[0., 1.]
range,[0,255]
. Also note that integer arrays must be of datatype int8 and not int32.As can be seen in the RGB case, an integer array in the range [0,1]
stays black, as well as a float array of range [0., 255.]
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With