Help with reading a binary array of intensity values from .img file?

I downloaded a .img file from the opportunity rover. I want to read the intensity values associated with each pixel. Currently I'm writing to a vector but I'm pretty sure I'm getting the wrong values since I'm getting a range of 0-65000. The file should just be a binary array (I removed the ascii detachable string).
There's 16 bits per pixel and I know the height and width of the image. The intensity values should be from 0-1. Does anybody have any ideas? I'm using the function 'fread' right now.
Currently, I'm doing this.
if true
fileID = fopen("filenamepath")
[A, count] = fread(fileID, [height, width], 'double')
end
I'm getting less data than I thought because using double is 8 bytes but each pixel is 2 bytes....thoughts?

 Accepted Answer

16 bit floating point is possible but it is not common, and I think it unlikely that is what you are seeing.
More likely is that you should use
[temp, count] = fread(fileID, [height, width], '*uint16');
im2double(temp);
or possibly
[temp, count] = fread(fileID, [width, height], '*uint16') .';
im2double(temp);

2 Comments

This definitely got me some values between 0-1. I don't know if it should be half precision floating point, like you said.
The image isn't correct though. Even before conversion to double precision, I plotted the image and it's wrong so I must be misinterpreting how the data is set up. I'll keep working on it!
Could you post a URL for the data? What I find at http://mars.nasa.gov/mer/gallery/all/opportunity.html is all jpeg images.

Sign in to comment.

More Answers (0)

Categories

Find more on Data Import and Analysis 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!