Skip to content

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

Description

@ywxk-0

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions