%% Create and Append Compressed FITS File
%  Create a compressed FITS file with three images constructed from the channels of an RGB image.
% Read a sample image.

X = imread('ngc6543a.jpg');

% Isolate red, green, and blue channels of image.

R = X(:,:,1);  G = X(:,:,2);  B = X(:,:,3);

% Write image data of red channel to a FITS file compressed as a GNU zip file.

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

% Append the FITS file with the image data of the green and blue channels compressed as GNU zip files.

fitswrite(G,'myfile.fits','writemode','append','Compression','gzip');
fitswrite(B,'myfile.fits','writemode','append','Compression','gzip');

% Display the FITS file.

fitsdisp('myfile.fits');

%
%%
% Copyright 2020 The MathWorks, Inc.