read .img format image without header file

15 次查看(过去 30 天)
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 中查找有关 Convert Image Type 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by