read .img format image without header file

조회 수: 17 (최근 30일)
aditi gupta
aditi gupta 2013년 10월 15일
댓글: Image Analyst 2015년 10월 31일
I am using chest Xray .img images .there are no header files .how do i read them in matlab. imread and dicomread are not working

답변 (2개)

Image Analyst
Image Analyst 2013년 10월 15일
편집: Image Analyst 2013년 10월 15일
Use fread(). Here's a snippet from my code. Flexible enough for 8 bit and 16 bit images.
% Read in image2D image data
% Get original, full-sized 2-D slice.
% Note: fread() requires that x_size and y_size be doubles.
% Note: fread() will return a 2D array if you pass in a 2D array for the number of bytes, as in [x_size y_size].
if stHeader.BytesPerVoxel == 1
oneSlice = fread(fileHandle, [x_size y_size], '*uint8');
elseif stHeader.BytesPerVoxel == 2
oneSlice = fread(fileHandle, [x_size y_size], '*int16'); % It will be a 2D array after this.
else
error('Unsupported BytesPerVoxel %d', stHeader.BytesPerVoxel);
end

Jonathan LeSage
Jonathan LeSage 2013년 10월 15일
You could directly read the *.img file directly into the MATLAB workspace via the fopen and fread commands. Since you do not have the information in the header file, you will have to come up with the image dimensions and image bit depth precision. Consult the documentation of fopen and fread for further clarification:
Here is some sample code that could get you started:
fid = fopen('xray.img');
data = fread(fid,imageDimensions,imagePrecision);
fclose(fid)
Another potential option if you have the image processing toolbox are some built in image format read tools, such as analyze75read and nitfread. A full list can be found below:
  댓글 수: 4
Walter Roberson
Walter Roberson 2015년 10월 31일
hadeel, it is not possible to know that without additional information from another source.
For example, suppose I tell you that I have three numbers, H, W, and D, that multiply together to give 60. Now I ask you to tell me what the three individual numbers are. How can you know if they are [2, 3, 10]; or [2 15 2]; or [5 4 3] ?
When you have a file without a header and with no other information then all you know is the total length of the file, which will be the product H * W * D, and that is never enough to determine the individual values, not even if the total length is a prime number.
Image Analyst
Image Analyst 2015년 10월 31일
If it's a 2D gray scale image in a simple header + image data, you can guess. Guess at a header length. If you're wrong the image will look sheared horizontally. As you get closer the the correct header length the shear will be less and less until it doesn't look sheared at all when you have the exact header length.

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

카테고리

Help CenterFile Exchange에서 Read, Write, and Modify Image에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by