unit 8 and im2double and white pixel
2 views (last 30 days)
DGM on 27 Jul 2022
Edited: DGM on 28 Jul 2022
I think it was your comment I responded to earlier, so I suppose there's no harm repeating it here. Tools like imshow() and imwrite() expect image data to be within a certain range which depends on the numeric class of the array. Floating point classes are within [0 1], and integer classes are expected to be within the allowable range of the integer width (e.g. [0 255] for uint8).
So if you have any 'uint8' image, you can be certain that all values are within [0 255], since uint8 simply can't represent values outside that range. When cast and scaled with im2double(), those values must lie within [0 1] due to that prior constraint, but if you add 50 to it, 'double' can certainly represent values outside [0 1]. It's just by convention that MATLAB interprets 0 as black and 1 as white. So now your image contains values in the range [50 51] -- beyond white. The most that can be represented is white, so that's what's displayed.
Similar might happen if you took your uint8 image and created an improperly-scaled floating-point copy by using double() instead of im2double().
Bear in mind the older comment I made in that other thread. See also Walter's comment. The question is a bit misleading, since imshow(), image() and imagesc() will treat such a single-channel image differently than they would treat an RGB image. While image()/imagesc() display single-channel images in pseudocolor using the axes colormap, imshow() uses the gray() colormap. So depending on which tool you use to display the image and what options you select when you call it, you might get white, or you might get some color belonging to the current colormap.
FWIW, I know there's a webdocs page that discusses the subject of class-dependent image data range conventions, but I can't find it. If I can't find a webdocs page that I know exists, I can excuse anyone else for never finding it either.