MATLAB Answers

How can I tell if the raw data that I have is an image?

1 view (last 30 days)
Rafi
Rafi on 27 Apr 2018
Commented: Walter Roberson on 28 Apr 2018
Assuming I have a long list of data values which I suspect it is an image, either in some sort of format or just pixel values. In order to understand if its an image I need to present it on my laptop screen. any ideas what the steps to do it? what I mean : 1. If it is just pixel values can I present it as is ? how? 2. If it is already in a format (GIF JPEG etc.) how can I tell ? Thanks Rafi Rafi

  0 Comments

Sign in to comment.

Answers (1)

Siyu Guo
Siyu Guo on 27 Apr 2018
GIF, JPEG, etc., are image FILE format. Image data may be compressed, and additional information is added into the file, e.g., BITMAP header data. But once an image is loaded into the MATLAB workspace, it's just a normal matrix or array: for a gray-scale image, a matrix, and for an RGB image, a 3D array, with the size of the third dimension being 3.
There are several aspects indicating that a matrix or a 3D array be more likely to be image data. If the data type is uint8, or the data type is double and the values of the elements range between 0 and 1, the data are more likely to be an image commonly encountered during image processing.
But basically speaking, any matrix or 3D array (with the size of the 3rd dimension being 3) can be "treated" or "interpreted" or "shown" in the form of an image. This is a very common processing of the data for visualization. For example, given A as a matrix corresponding to the values of a function f(x,y) over a rectangular grid, you can use
imshow(A,[])
to show the data as a gray-scale image, or even better, use
imshow(A,[]), colormap(a_colormap)
to show the data as a pseudo-color image. You can even use imwrite to save the data as an image file. But all these do not necessarily mean that the matrix A itself is originally image data.

  3 Comments

Rafi
Rafi on 27 Apr 2018
OK thanks. One more : since the data that I have is not arranged in matrix, it is just a long list of values (which I assume a pixel values), I need to arrange it in a matrix before I can imshow it , yes? is there a limitation for the matrix sizes or I can use any size ? Is there a function in matlab that can take that list and build from it matrix in diffrent sizes the way I want ? Thanks.
Siyu Guo
Siyu Guo on 28 Apr 2018
Well, if you are sure that the data is an image, you need to rearrange the data to the size of the image itself, only then you can observe and understand the image. If other sizes are used (for example, a vector is also a matrix with a very elongated size), you can still imshow it, just that you can hardly know what's in the image. To rearrange the data to a specifically sized matrix, use reshape function.
Walter Roberson
Walter Roberson on 28 Apr 2018
What is the total number of values? If it is divisible by 3 then it is plausibly RGB.
You can factor() the total number of values to get some hints as to the number of rows and columns.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!