Main Content

fitswrite

将图像写入 FITS 文件

说明

示例

fitswrite(imagedata,filename) 将指定的图像数据写入 filename 指定的普适图像传输系统 (FITS) 文件。如果该文件存在,fitswrite 会覆盖它。

示例

fitswrite(imagedata,filename,Name,Value) 使用一个或多个名称-值对组参量和附加选项创建一个文件。例如,'Compression','rice' 指定 Rice 压缩算法。

示例

全部折叠

创建包含 RGB 图像红色通道的 FITS 文件。红色通道在最终图像中以灰度表示。

读取一个示例图像并隔离其红色通道。

X = imread('ngc6543a.jpg');
R = X(:,:,1);

将红色通道数据写入一个 FITS 文件。

fitswrite(R,'myfile.fits');

显示 FITS 元数据。

fitsdisp('myfile.fits');
HDU:  1 (Primary HDU)
	SIMPLE  =                    T / file does conform to FITS standard
	BITPIX  =                    8 / number of bits per data pixel
	NAXIS   =                    2 / number of data axes
	NAXIS1  =                  600 / length of data axis 1
	NAXIS2  =                  650 / length of data axis 2
	EXTEND  =                    T / FITS dataset may contain extensions
	COMMENT   FITS (Flexible Image Transport System) format is defined in 'Astronomy
	COMMENT   and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H

创建一个带有三个从 RGB 图像通道构建的图像的压缩 FITS 文件。首先用一个通道创建文件,然后向该文件追加另外两个通道。

读取一个示例图像,并隔离其红色、绿色和蓝色通道。

X = imread('ngc6543a.jpg');
R = X(:,:,1);
G = X(:,:,2);
B = X(:,:,3);

使用 Rice 压缩将红色通道数据写入一个 FITS 文件。

fitswrite(R,'myfile.fits','Compression','rice');

使用 Rice 压缩将绿色和蓝色通道数据追加到 FITS 文件中。

fitswrite(G,'myfile.fits','WriteMode','append','Compression','rice');
fitswrite(B,'myfile.fits','WriteMode','append','Compression','rice');

显示该 FITS 文件。

fitsdisp('myfile.fits');
HDU:  1 (Primary HDU)
	SIMPLE  =                    T / file does conform to FITS standard
	BITPIX  =                   16 / number of bits per data pixel
	NAXIS   =                    0 / number of data axes
	EXTEND  =                    T / FITS dataset may contain extensions
	COMMENT   FITS (Flexible Image Transport System) format is defined in 'Astronomy
	COMMENT   and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H

HDU:  2 
	XTENSION= 'BINTABLE'           / binary table extension
	BITPIX  =                    8 / 8-bit bytes
	NAXIS   =                    2 / 2-dimensional binary table
	NAXIS1  =                    8 / width of table in bytes
	NAXIS2  =                  650 / number of rows in table
	PCOUNT  =               101902 / size of special data area
	GCOUNT  =                    1 / one data group (required keyword)
	TFIELDS =                    1 / number of fields in each row
	TTYPE1  = 'COMPRESSED_DATA'    / label for field   1
	TFORM1  = '1PB(470)'           / data format of field: variable length array

HDU:  3 
	XTENSION= 'BINTABLE'           / binary table extension
	BITPIX  =                    8 / 8-bit bytes
	NAXIS   =                    2 / 2-dimensional binary table
	NAXIS1  =                    8 / width of table in bytes
	NAXIS2  =                  650 / number of rows in table
	PCOUNT  =                95976 / size of special data area
	GCOUNT  =                    1 / one data group (required keyword)
	TFIELDS =                    1 / number of fields in each row
	TTYPE1  = 'COMPRESSED_DATA'    / label for field   1
	TFORM1  = '1PB(470)'           / data format of field: variable length array

HDU:  4 
	XTENSION= 'BINTABLE'           / binary table extension
	BITPIX  =                    8 / 8-bit bytes
	NAXIS   =                    2 / 2-dimensional binary table
	NAXIS1  =                    8 / width of table in bytes
	NAXIS2  =                  650 / number of rows in table
	PCOUNT  =                96255 / size of special data area
	GCOUNT  =                    1 / one data group (required keyword)
	TFIELDS =                    1 / number of fields in each row
	TTYPE1  = 'COMPRESSED_DATA'    / label for field   1
	TFORM1  = '1PB(470)'           / data format of field: variable length array

输入参数

全部折叠

输入图像数据,指定为一维或多维数组。

文件名,指定为字符向量或字符串标量。

名称-值参数

将可选的参量对组指定为 Name1=Value1,...,NameN=ValueN,其中 Name 是参量名称,Value 是对应的值。名称-值参量必须出现在其他参量之后,但参量对组的顺序无关紧要。

在 R2021a 之前,使用逗号分隔每个名称和值,并用引号将 Name 引起来。

示例: fitswrite(R,'myfile.fits','WriteMode','append')

写入模式,指定为字符向量或字符串标量。如果指定的文件已存在,写入模式将确定 fitswrite 的行为。

写入模式

描述

'overwrite'

覆盖现有文件。这是默认行为。

'append'

将图像数据追加到现有文件。

如果文件不存在,则无论使用哪种写入模式,fitswrite 都会创建一个新文件。

写入 FITS 图像时使用的压缩算法,指定为以下值之一。

描述

'none'

无压缩。这是默认行为。

'gzip'

将图像数据压缩为 GNU ZIP 文件。

'rice'

使用 Rice 算法压缩图像数据。

'hcompress'

使用 HCOMPRESS 算法压缩图像数据。

'plio'使用 PLIO 算法压缩图像数据。

提示

  • MATLAB® 以给定的顺序写入原始 FITS 图像数据,但一些用于读取和写入 FITS 图像数据的软件包假定图像数据按照图像的底行在前的顺序存储。因此,当使用其他软件包显示时,由 MATLAB 写入的 FITS 图像数据可能会出现上下方向的翻转(即绕水平轴翻转)。要翻转 MATLAB 中的图像,您可以在使用 fitswrite 写入图像之前对图像数据使用 flipud 函数。

版本历史记录

在 R2012a 中推出