imhistmatch() output is zero matrix

5 views (last 30 days)
leonolovich
leonolovich on 17 Apr 2019
Edited: DGM on 15 May 2021
I have two 16bit .tif grayscale images that I am reading into my workspace using imread(). The output variable is of the correct type (uint16), but if I inspect the matrix for this image, I dont see any value above 255. If I then do an imhistmatch() using these two images I read in (they are almost identical grayscale images), I get a zero matrix output from the imhistmatch() function. If I do the above process by first converting the uint16 image to uint8, then it works perfectly. I am unsure what is going on. Any thoughts?

Answers (1)

DGM
DGM on 14 May 2021
Edited: DGM on 15 May 2021
I know this is old, but I'm bored and don't mind talking to ghosts.
Most image processing tools expect image data to be scaled correctly according to the standard data range for the image class. For floating point classes, this is [0 1]. For integer classes, it's the numeric range supported by the class (e.g. [0 65535] for uint16). What you have are incorrectly scaled images. You have uint8 data in a uint16 image. This is what happens when you do
uint16(myuint8image) % only casts
instead of
im2uint16(myuint8image) % casts and rescales accordingly
As far as everything is concerned, the image is essentially black, since 255 is a lot closer to 0 (black) than it is to 65535 (white).
Just recast your images to the appropriate class:
myimage = uint8(myimage);

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!