How do I read data from a binary table in matlab using fitsread?

조회 수: 4 (최근 30일)
Aldo Apponi
Aldo Apponi 2013년 2월 5일
답변: Min 2014년 9월 15일
I am having trouble getting matlab to reconstruct (or uncompress) a FITS image that was compressed in Matlab using fits.imgCompress(infptr,outfptr). Below is the test code that I have been playing with. First I read in a FITS file that was created in Matlab, then I compress the image with a RICE compression algorithm and write the file out to disk. Then I read the compressed file back in with the hope that I can recreate the original file, but I am having trouble getting the data back out in a usable format.
I tried data = fitsread('file', 'binarytable'), but data only contains a 1 x 2 array of data and not the entire image as expected.
I tried colData = matlab.io.fits.readCol(fptr,1); colData seems to have the information that I am after, but I don't know what to do with it.
When I read the same files into Python using the pyfits module, I can reconstruct the original data, so I know the file is not corrupt.
I don't know how to attach the FITS file to this post.
filetoread = 'C:\LocalData\000005GEOST156328.1024.fit';
filetowrite = 'C:\LocalData\000005GEOST156328.1024.hcomp.fit';
infptr = matlab.io.fits.openFile(filetoread);
outfptr = matlab.io.fits.createFile(filetowrite);
matlab.io.fits.setCompressionType(outfptr,'RICE');
% matlab.io.fits.setHCompScale(outfptr, 2.5);
matlab.io.fits.imgCompress(infptr,outfptr);
matlab.io.fits.closeFile(infptr);
matlab.io.fits.closeFile(outfptr);
info = fitsinfo(filetowrite);
fptr = matlab.io.fits.openFile(filetowrite,'READONLY');
cleaner = onCleanup(@() matlab.io.fits.closeFile(fptr));
matlab.io.fits.movAbsHDU(fptr,2);
ncols = matlab.io.fits.getNumCols(fptr);
nrows = matlab.io.fits.getNumRows(fptr);
[dtype,repeat,width] = matlab.io.fits.getEqColType(fptr,1);
[NROWS,TTYPE,TFORM,TUNIT,EXTNAME,PCOUNT] = matlab.io.fits.readBTblHdr(fptr);
colData = matlab.io.fits.readCol(fptr,1);
matlab.io.fits.closeFile(fptr);
data = fitsread(filetowrite,'binarytable','Info',info);

답변 (1개)

Min
Min 2014년 9월 15일
try: data = fitsread(filetowrite,'image');

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by