%% 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 red channel data to a FITS file using Rice compression.

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

% Append the FITS file with green and blue channel data using Rice compression.

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

% Display the FITS file.

fitsdisp('myfile.fits');

%
%%
% Copyright 2020 The MathWorks, Inc.