【问题标题】:How can I read .img image format in MATLAB?如何在 MATLAB 中读取 .img 图像格式?
【发布时间】:2016-02-14 09:42:12
【问题描述】:

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

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

【问题讨论】:

  • 在这种情况下,文件扩展名并不能说明文件格式。它可能是一个 ISO 磁盘映像,但这有点奇怪。首先找出你有什么样的文件。文件开头可能存在一些幻数或类似数字,可以识别文件格式:en.wikipedia.org/wiki/File_format#Magic_number
  • 我建议对您的标题进行编辑,但被拒绝。我仍然认为您应该将其更改为更准确地描述您所指的图像格式。

标签: image-processing matlab


【解决方案1】:

在 X 射线图像的上下文中,“.img”文件是 Mayo 分析类型图像的二进制文件。您也需要“.hdr”文件。 matlab 本身不支持这种格式,除非您有图像处理工具箱(在这种情况下,请查看analyze75read 函数)。

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

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

加载图像时参考“.hdr”文件,而不是“.img”。

【讨论】:

    【解决方案2】:

    以下代码足以解决您的问题。

    % 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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多