Clear Filters
Clear Filters

image format question

3 views (last 30 days)
Betty
Betty on 19 Dec 2011
I am dealing with satellite imagery have a binary file of image data. I can read the file correctly using fread, so have it in a 2d array called a. How do I display the image. I tried
imshow(a)
but I got the following:
Warning: Image is too big to fit on screen; displaying at
33%
> In imuitools/private/initSize at 72
In imshow at 259
A new window came up, but no image was displayed. I then tried:
imshow(a(1:100,1:100))
and a smaller window popped up, but still nothing in it. No warning that time though.
I think my fundamental question as a newbie to image processing in matlab is: do I have to convert my array to some sort of "image" format for matlab to understand how to display it and perform other image processing functions on it?
Thanks!

Accepted Answer

Alex Taylor
Alex Taylor on 19 Dec 2011
When you say that "a new window came up, but no image was displayed", the most likely cause of this is that the 'DisplayRange' property of imshow needs to be adjusted because the input data is not well scaled.
Try the following to get autoscaling behavior:
imshow(a,[]);
This will set the 'DisplayRange' to the range of the histogram of your data.
For more help, please take a look at the reference page for imshow
doc imshow
  1 Comment
Betty
Betty on 19 Dec 2011
Thank you! This worked well.

Sign in to comment.

More Answers (4)

Sean de Wolski
Sean de Wolski on 19 Dec 2011
No. You can display any 2d nmatrix or mxnx3 rgb matrix with imshow, you just might need to adjust a few parameters (such as initialmagnification displayrange colormap etc.)
doc imshow
explains a little. The warning you were seeing was just because the image was large. Adjust the initialmagnification or turn off the warning. (During grad school I permanently turned off that warning because it was thrown on every call)

Walter Roberson
Walter Roberson on 19 Dec 2011
I'm sure I already answered this question, but I see that question has disappeared :(
You do not need to convert your array to any kind of "image" format. However, if the values in your array are close together then imshow() and image() would only have a very small range of colors to work with. If you pass [] as the second parameter of imshow(), or if you use imagesc() instead of imshow(), then the data will automatically be scaled to use the entire color map.
What data type is your "a" array? Is it possibly uint8 ? And are all the values exactly 0 or 1 ? If that is the case then imshow(double(a)) would turn out to have the same effect but would take more memory.
  1 Comment
Betty
Betty on 19 Dec 2011
It's int16 (that's how the binary file was created). The values vary from 100 to 810.

Sign in to comment.


Image Analyst
Image Analyst on 19 Dec 2011
Like they said, try the bracket bracket [] to have it scale. If it's still not there, set a breakpoint and look at the size and type of "a." Maybe it's only one signel number for some reason. You should also choose a meaningful variable name, such as originalImage, rather than single letters. Just before you call imshow, insert this statement:
[rows columns numberOfColorChannels] = size(originalImage)
(no semicolon) and see what it spits out to the command window, then tell us.

Etamar
Etamar on 19 Dec 2011
try imread instead of fread.
or cast ur data to uint8 uint8(data)
  3 Comments
Betty
Betty on 19 Dec 2011
It was just raw data - 16-bit signed integer, 2000x2000 values. I didn't know how to get imread to read it.
Image Analyst
Image Analyst on 20 Dec 2011
It may not, unless it is some standard format like TIFF, PNG, BMP, etc. That's probably why you had to write your own custom reading program using fread().

Sign in to comment.

Categories

Find more on Images in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!