Main Content

matlab.io.fits.readImg

Read FITS image data

Syntax

imgdata = matlab.io.fits.readImg(fptr)
imgdata = matlab.io.fits.readImg(fptr,fpixel,lpixel)
imgdata = matlab.io.fits.readImg(fptr,fpixel,lpixel,inc)

Description

imgdata = matlab.io.fits.readImg(fptr) reads the entire current image. The number of rows in imgdata matches the value of the NAXIS2 keyword; the number of columns matches the value of the NAXIS1 keyword. Further dimensions of imgdata match the values of the keywords NAXIS3, NAXIS4, and so on.

imgdata = matlab.io.fits.readImg(fptr,fpixel,lpixel) reads the subimage determined by pixel coordinates fpixel and lpixel. The fpixel argument is the coordinate of the first pixel, and the lpixel argument is the coordinate of the last pixel. The fpixel and lpixel arguments are one-based.

imgdata = matlab.io.fits.readImg(fptr,fpixel,lpixel,inc) reads the subimage determined by fpixel, lpixel, and inc. The inc argument denotes the inter-element spacing along each extent.

Examples

collapse all

Open a sample FITS file and read the entire current image. Check the size and type of the image data. Then close the file.

import matlab.io.*
fptr = fits.openFile("tst0012.fits");
data = fits.readImg(fptr);
whos data
  Name        Size             Bytes  Class     Attributes

  data      109x102            44472  single              
fits.closeFile(fptr)

Read a 70-by-80 portion of an image from a sample FITS file. Check the size and type of the image data. Then close the file.

import matlab.io.*
fptr = fits.openFile("tst0012.fits");
data = fits.readImg(fptr,[11 11],[80 90]);
whos data
  Name       Size            Bytes  Class     Attributes

  data      70x80            22400  single              
fits.closeFile(fptr)

Tips

  • This function corresponds to the fits_read_subset (ffgsv) function in the CFITSIO library C API.

  • To use this function, you must be familiar with the CFITSIO C interface. You can access the CFITSIO documentation at the CFITSIO website.

  • MATLAB® reads FITS image data in the order that it appears in the file, but some software packages for reading and writing FITS image data assume that the image data is stored in an order in which the bottom row of the image is first. Consequently, FITS image data displayed in MATLAB may appear flipped in the up-down direction (that is, about a horizontal axis) when compared to the same data displayed using other software packages. To flip an image in MATLAB, you can use the flipud function on the output of matlab.io.fits.readImg before displaying the image.

Extended Capabilities

expand all

Version History

expand all