NVIDIA / nvImageCodec

A nvImageCodec library of GPU- and CPU- accelerated codecs featuring a unified interface
https://docs.nvidia.com/cuda/nvimagecodec/index.html
Apache License 2.0
76 stars 5 forks source link

region-of-interest decoding #4

Closed grez72 closed 3 months ago

grez72 commented 6 months ago

Is this a new feature, an improvement, or a change to existing functionality?

New Feature

How would you describe the priority of this feature request

Must have (e.g. nvImageCodec adoption is impossible due to lack in functionality).

Please provide a clear description of problem this feature solves

I'm working with high-resolution images, but only need to decode a region-of-interest on any given pass over an image in my pipeline. The alternative is to decode entire images, then crop them, but this is far too slow when working with very high resolution images.

Feature Description

I see many of the decoders (e.g., nvjpeg2k/cuda_decoder.cpp) have an enable_roi flag and image_info.region parameters. I'm proposing to expose this functionality through the Python API. Ideally I would be able to decode a different region of interest for each image in a batch.

Describe your ideal solution

decoder = nvimgcodec.Decoder()

# region tuple (start_x, start_y, end_x, end_y) or list of tuples
rois = [ (0,0,150,150), (100,100,250,250)]

# decode regions of interest (one roi per image)
data_list = [img1_data, img2_data]
cropped_images = decoder.decode(data_list, region_of_interest=rois)

# or using read
file_list = [filepath_img1, filepath_img2]
cropped_images = decoder.read(data_list, region_of_interest=rois)

Describe any alternatives you have considered

I've looked into using nvidia-dali (nvidia.dali.fn.decoders.image_crop) but it doesn't fit into my current pipeline, which requires a stand-alone decoding solution (like nvImageCodec).

Additional context

No response

Check for duplicates

jantonguirao commented 6 months ago

@grez72 Thank you for your request. This is already in scope for our next release (we don't have a target date yet). We'll let you know when it's ready.

jantonguirao commented 3 months ago

The new release v0.3.0 enables this feature. Let us know if you find any issues.

grez72 commented 1 week ago

I've only had a chance to try on a few test images, but this looks great! Many thanks!