How can I tell if the raw data that I have is an image?
3 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Siyu Guo
2018-4-27
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 个评论
Siyu Guo
2018-4-28
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
2018-4-28
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Import, Export, and Conversion 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!