imshow() dispalys nothing for int16 array in Octave

Viewed 192

I am working on Octave with a brain MRI dataset.

The data is in the form of hundreds of .mat fils. I load the data file using: x = load("filename.mat") and the images are stored in the form of an array from 0 to 256.

Then when I try to imshow(x.image) a window pops up with 512 x 512 graph but is completely black. It also throws a warning saying: unsupported type for cdata (= int16 matrix). Valid types are uint8, uint16, double, single, and bool.

I have also tried casting the image array using: imshow(cast(x, "double")) and all the other data types mentioned above, but the result is almost the same.

Help me out here.

1 Answers

You can use the limits parameter of imshow. The image is appearing black because it only contains values in the range [0,256], while int16 contains values up to 32767.

You can set the limits manually:

imshow(x.image, [0, 256])

Or use

imshow(x.image, [])

For automatic limit detection.


Note: on Octave, this will only work with supported types. Since your image doesn't contain negative values, you can convert the image to uint16, which will fit your values. Or you can use double, for a more general approach:

imshow(uint16(x.image), [])
imshow(double(x.image), [])

In your case, if you don't mind the pixels with value 256 being saturated to 255, you can convert the image to uint8:

imshow(uint8(x.image))
Related