NVIDIA / NVIDIA/nvImageCodec

How to create a TIFF file with JPEG compression, JPEG2000 compression, or other compression methods in Python?

Open
#41 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

question
Dominant language
Jupyter Notebook
Stars
159
Forks
22
PR merge metrics
No merged PRs in 30d

Description

Describe the question.

Hello, thank you for viewing this question. I need to create some TIFF files with JPEG or JPEG2000 compression. After learning about nvImageCodec, I tried to study it. However, I couldn't find suitable answers in the official documentation at https://docs.nvidia.com/cuda/nvimagecodec/samples/python_samples.html and https://docs.nvidia.com/cuda/nvimagecodec/py_api.html . Since I don't know how to write C or C++ code, I came here to ask. Thank you for your help.

Here is my Python code snippet:


import numpy as np
from nvidia import nvimgcodec



tif_file = r"HH_2.tiff"
# The image is 8-bit with 3 channels.

decodeparams = nvimgcodec.DecodeParams(allow_any_depth=True)

decoder = nvimgcodec.Decoder()

nv_img_0 = decoder.decode(tif_file, params=decodeparams)

img_0 = np.array(nv_img_0.cpu())


encoder = nvimgcodec.Encoder()

codec = 'tiff'
encode_params_0 = nvimgcodec.EncodeParams(quality_type=nvimgcodec.QualityType.LOSSLESS)

encoder.write("HH_nv.tiff", img_0, codec, params=encode_params_0)
# It outputs an uncompressed TIFF image.

encode_params_1 = nvimgcodec.EncodeParams(quality_value=1)

encoder.write("HH_LZW_nv.tiff", img_0, codec, params=encode_params_1)
# The output is a TIFF image compressed with LZW.

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked Python samples and Python API reference, then trace the EncodeParams usage shown in the issue. Determine whether the documented API covers the requested TIFF compression methods and make the supported procedure and limitations clear for Python users.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
computer-vision, documentation
Issue type
Documentation
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.