nvImageCodec icon indicating copy to clipboard operation
nvImageCodec copied to clipboard

NITF with JPEG2000

Open drewgilliam opened this issue 3 months ago • 1 comments

Describe the question.

I’m interested in using the python API to decode a NITF file containing a very large image encoded with JPEG2000. A NITF is a container format, encapsulating a header and one or more images. When using JPEG2000 compression, image data is effectively a .jp2 file encapsulated within a larger NITF file.

I’m currently able to discover the extents of the encapsulated image data through other means, read the complete (very large) encoded image to a python variable as bytes, form a code stream from those encoded bytes, and then decode a numpy array for the small ROI I’m interested in. Unfortunately this is relatively inefficient as I have to read and store the complete encoded image just to decode a small portion.

One useful possibility would be a new code stream constructor that takes a file name, byte offset, and byte length. This would let me form a code stream from just the relevant JP2 portion of the encapsulating NITF without reading all bytes into memory.

Would such a constructor be possible? Or is there some other way to achieve decoding for a container format like NITF without reading the entire byte stream to memory?

Thanks in advance for any help!

Check for duplicates

  • [x] I have searched the open bugs/issues and have found no duplicates for this bug report

drewgilliam avatar Oct 15 '25 00:10 drewgilliam

In the nvImageCodec docs, in the Python basics example section you can see how to decode bytes of images instead of decoding from file (https://docs.nvidia.com/cuda/nvimagecodec/samples/nvimgcodec.html, cell [4])

If you know location of JPEG2000 bytes in the NIFT file you can read just them and pass such byte buffer to nvImageCodec decoder.decode() function. So if there are more that one JPEG2000 image you can just read a single image into bytes. But you need to do parsing of the NIFT yourself, nvImageCodec doesn't support it yet.

Even if you are interested in reading just small ROI of JPEG2000 image you still need to provide encoded bytes for the whole image. Right now nvJPEG2000 that nvImageCodec is using doesn't support reading partial image data.

mkepa-nv avatar Oct 28 '25 14:10 mkepa-nv