简体   繁体   English

如何在MATLAB中读取.img图像格式?

[英]How can I read .img image format in MATLAB?

I have xray images in .img format. 我有.img格式的X射线图像。

How can ı read .img image format in MATLAB and convert to png or other image formats? 我如何在MATLAB中读取.img图像格式并将其转换为png或其他图像格式?

In the context of x-ray images, '.img' files are the binaries of Mayo Analyze-type images. 在X射线图像中,“。img”文件是Mayo Analyze类型图像的二进制文件。 You need the '.hdr' file too. 您还需要“ .hdr”文件。 This format is not natively supported by matlab, unless you have the Image Processing Toolbox (in this case look at the analyze75read function). 除非您具有“图像处理工具箱”(在本例中为analyze75read函数),否则matlab本身不支持该格式。

But you can also use a function from the file exchange library to read them (not tested by me): 但是您也可以使用文件交换库中的函数来读取它们(未经我测试):

http://www.mathworks.com/matlabcentral/fileexchange/1878-mri-analyze-tools http://www.mathworks.com/matlabcentral/fileexchange/1878-mri-analyze-tools

Refer to the '.hdr' file when you load the image, not the '.img'. 加载图像时,请参考“ .hdr”文件,而不要参考“ .img”。

The following code is sufficient for your question. 以下代码足以解决您的问题。

% the .img file is opened
f = fopen('image.img')
% the f variable is read as an image with the uint8 datatype
image = fread(f, [256 378], '*uint8');
% show the image
imshow(image,[])
% write the image with the your extension choose
imwrite(image, 'filename.extension', 'extension')

the extensions supported by matlab are matlab支持的扩展是

'bmp'      Windows® Bitmap (BMP)


1-bit, 8-bit, and 24-bit uncompressed images

'gif'     Graphics Interchange Format (GIF)


8-bit images

'hdf'     Hierarchical Data Format (HDF4)


8-bit raster image data sets with or without associated colormap, 24-bit raster image data sets

'jpg' or 'jpeg'    Joint Photographic Experts Group (JPEG)


8-bit, 12-bit, and 16-bit Baseline JPEG images

    Note:   imwrite converts indexed images to RGB before writing data to JPEG files, because the JPEG format does not support indexed images.

'jp2' or 'jpx'   JPEG 2000 — Joint Photographic Experts Group 2000


1-bit, 8-bit, and 16-bit JPEG 2000 images

'pbm'   Portable Bitmap (PBM)


Any 1-bit PBM image, ASCII (plain) or raw (binary) encoding

'pcx'   Windows Paintbrush (PCX)


8-bit images

'pgm'   Portable Graymap (PGM)


Any standard PGM image; ASCII (plain) encoded with arbitrary color depth; raw (binary) encoded with up to 16 bits per gray value

'png'   Portable Network Graphics (PNG)


1-bit, 2-bit, 4-bit, 8-bit, and 16-bit grayscale images; 8-bit and 16-bit grayscale images with alpha channels; 1-bit, 2-bit, 4-bit, and 8-bit indexed images; 24-bit and 48-bit truecolor images; 24-bit and 48-bit truecolor images with alpha channels

'pnm'   Portable Anymap (PNM)


Any of the PPM/PGM/PBM formats, chosen automatically

'ppm'   Portable Pixmap (PPM)


Any standard PPM image: ASCII (plain) encoded with arbitrary color depth or raw (binary) encoded with up to 16 bits per color component

'ras'   Sun™ Raster (RAS)


Any RAS image, including 1-bit bitmap, 8-bit indexed, 24-bit truecolor, and 32-bit truecolor with alpha

'tif' or 'tiff'   Tagged Image File Format (TIFF)


Baseline TIFF images, including:

    1-bit, 8-bit, 16-bit, 24-bit, and 48-bit uncompressed images and images with packbits, LZW, or Deflate compression

    1-bit images with CCITT 1D, Group 3, and Group 4 compression

    CIELAB, ICCLAB, and CMYK images

'xwd'  X Windows Dump (XWD)


8-bit ZPixmaps

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM