Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do I get an all-black/grayscale image when I load this PNG in MATLAB?

Tags:

file

image

matlab

When I run this code:

>> I = imread('D:\Works\matlab\SecCode.php.png','png');
>> imshow(I);

It always shows an all-black image. What's wrong with it?

The image I'm using is this one:

enter image description here

like image 1000
user198729 Avatar asked Feb 03 '23 05:02

user198729


1 Answers

Ahhh, I see now. The problem is you have an indexed image and need to get the colormap argument from imread as well. Try this:

[I, map] = imread('D:\Works\matlab\SecCode.php.png', 'png');
imshow(I, map);

A description of the different types of images in MATLAB can be found here. Here's a brief summary:

  • Binary images: The image is a logical array where each pixel has the value 0 or 1.
  • Indexed images: The pixels in the image store indices into a colormap, which is an M-by-3 array of RGB values. The colormap is often stored with the indexed image in the image file.
  • Intensity (Grayscale) images: The pixels in the image each contain a single value representing the intensity.
  • RGB (Truecolor) images: The image is an M-by-N-by-3 array where each pixel has a red, green, and blue color component.
like image 153
gnovice Avatar answered Feb 20 '23 20:02

gnovice