Reputation: 1
I have xray images in .img format.
How can ı read .img image format in MATLAB and convert to png or other image formats?
Upvotes: 0
Views: 3922
Reputation: 587
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
'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
Upvotes: 1
Reputation: 3574
In the context of x-ray images, '.img' files are the binaries of Mayo Analyze-type images. You need the '.hdr' file too. This format is not natively supported by matlab, unless you have the Image Processing Toolbox (in this case look at the analyze75read
function).
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
Refer to the '.hdr' file when you load the image, not the '.img'.
Upvotes: 4