[fitsbits] Cutouts from compressed image binary tables {External}

Dustin Jenkins djenkins.cadc at gmail.com
Thu Oct 20 22:21:04 EDT 2022


Thank you for the reply, Rob.

That was helpful.  Can you verify my logic?  If I want a CFITSIO style cutout, like so:

[1][12:20,12:20]

And I have 6 tiles of 10x10 (100 pixels) like so:

+——————+——————+——————+——————+——————+——————+
|                       |                       |                       |                       |                      |                       |
|                       |                       |                       |                       |                      |                       |
|                       |                       |                       |                       |                      |                       |
|                       |        |---------------------------------------------------------------------------------|           |
|                       |                       |                       |                       |                      |                       |
|                       |                       |                       |                       |                      |                       |
+——————+——————+——————+——————+——————+——————+

I’m able to get the correct size sub image by doing some pseudo-code like:

integer tileSize = 100
integer offset = 12 * 12   // 144
Integer rowStart = offset / tileSize   // 1
Integer rowOffset = offset % tileSize	// 44 - Offset into the tile
Integer length = 20 * 20   // 400
while(keepReading) {
    row = image.row(offset)
    compressedData = row[0]
    data = decompressRice(compressedData)
    for (I = rowOffset; I < data.length && I < length; I++) {
        readData()
    }
    offset = offset + 1
}

Which will read 400 pixels by reading row by row for the entire length, starting at pixel 144, like in my terrible ASCII image above.  

The problem is the that my pixel values are incorrect.  Could there be a problem with the Rice decompression?  Or are my offsets incorrect, possibly?

Many thanks for any input,
Dustin


> On Oct 18, 2022, at 8:12 PM, Seaman, Robert Lewis - (rseaman) <rseaman at arizona.edu> wrote:
> 
> Hi Dustin,
>  
> I can’t speak to nom-tam-fits support for what you want to do, but FITS tile compression is designed for this, eg: “Dividing the image into tiles before compression enables faster access to small sections of the image because only those tiles covering the area of interest need be uncompressed.” (https://heasarc.gsfc.nasa.gov/FTP/software/fitsio/c/docs/fpackguide.pdf <https://heasarc.gsfc.nasa.gov/FTP/software/fitsio/c/docs/fpackguide.pdf>)
>  
> See the discussion under ZTILEn in the FITS convention (https://fits.gsfc.nasa.gov/registry/tilecompression/tilecompression2.3.pdf <https://fits.gsfc.nasa.gov/registry/tilecompression/tilecompression2.3.pdf>) for the header keywords to sort it out. Either you or the library will then need to index from the table into the heap. By default, the tiles are row-by-row which makes the arithmetic easier. If there are constraints on the sub-images of interest such as location or size, the tiles can be tuned to optimize access.
>  
> Rob
>  
>  
>  
> On 10/18/22, 7:29 PM, "fitsbits" wrote:
>  
> I’m using the nom-tam-fits Java library to extract a sub image from a compressed image binary table.  Typically, the compressed image is decompressed and one can perform a normal extraction, but my service exists on the Cloud and needs to be able to cutout in a streaming manner.  Is there a way to look at the Header and know what row in the table (or which tile) that overlaps some range of pixels?  Alternatively, would I need to iterate the tiles to see if any of them overlap?
> 
> Many thanks,
> Dustin
> CADC
> 
> _______________________________________________
> fitsbits mailing list
> fitsbits at listmgr.nrao.edu <mailto:fitsbits at listmgr.nrao.edu>
> https://listmgr.nrao.edu/mailman/listinfo/fitsbits <https://listmgr.nrao.edu/mailman/listinfo/fitsbits>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listmgr.nrao.edu/pipermail/fitsbits/attachments/20221020/8db1e554/attachment.html>


More information about the fitsbits mailing list