Main Content

matlab.io.fits.writeImg

Write to FITS image

Syntax

writeImg(fptr,data)
writeImg(fptr,data,fpixel)

Description

writeImg(fptr,data) writes an entire image to the FITS data array. The number of rows and columns in data must equal the values of the NAXIS2 and NAXIS1 keywords, respectively. Any further extents must correspond to the NAXIS3, NAXIS4 ... NAXISn keywords respectively.

writeImg(fptr,data,fpixel) writes a subset of an image to the FITS data array. fpixel gives the coordinate of the first pixel in the image region.

This function corresponds to the fits_write_subset (ffpss) function in the CFITSIO library C API.

Examples

import matlab.io.*
fptr = fits.createFile('myfile.fits');
fits.createImg(fptr,'long_img',[256 512]);
data = reshape(1:256*512,[256 512]);
data = int32(data);
fits.writeImg(fptr,data);
fits.closeFile(fptr);

Create an 80x40 uint8 image and set all but the outermost pixels to 1.

import matlab.io.*
fptr = fits.createFile('myfile.fits');
fits.createImg(fptr,'uint8',[80 40]);
data = ones(78,38);
fits.writeImg(fptr,data,[1 1]);
fits.closeFile(fptr);

Tips

  • MATLAB® writes raw FITS image data in the order given, 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 written by MATLAB may appear flipped in the up-down direction (that is, about a horizontal axis) when displayed using other software packages. To flip an image in MATLAB, you can use the flipud function on the image data before writing the image with matlab.io.fits.writeImg.

See Also

|