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



我有.img格式的X射线图像。

如何在 MATLAB 中读取 .img 图像格式并转换为 png 或其他图像格式?

在 X 射线图像的上下文中,".img"文件是妙佑医疗国际分析类型图像的二进制文件。您还需要".hdr"文件。matlab 本身不支持这种格式,除非您有图像处理工具箱(在本例中查看 analyze75read 函数)。

但是您也可以使用文件交换库中的函数来读取它们(未经我测试):

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

加载映像时,请参阅".hdr"文件,而不是".img"。

以下代码足以满足您的问题。

% 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')

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

最新更新