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?

 채택된 답변

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

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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Data Import and Analysis에 대해 자세히 알아보기

질문:

2016년 10월 17일

댓글:

2016년 10월 18일

Community Treasure Hunt

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

Start Hunting!

Translated by