Skip to content

16 bits png support and compatibility with current transforms #4731

Closed
@NicolasHug

Description

@NicolasHug

We added support for decoding 16 bit pngs in #4657.

Pytorch doesn't support uint16 dtype, so we have to return a int32 tenor instead. However as @nairbv pointed out, this can lead to unexpected behaviour for the convert_image_dtype(), because this function relies on the max value of a given dtype to carry the conversions.

While the actual max value of a 16 bits image is 2**16 - 1, convert_image_dtype() will assume that it's (2**31 - 1) because the image is in a int32 tensor. This leads to e.g. a tensor full of zeros when converting to uint8.

Potential solutions are:

  • native support for uint16 in pytorch
  • add a new input_range=None parameter to convert_image_dtype() (not a fan of that)

For now, I'll just make this a private API (e.g. _decode_16bits_png() or something). It will still allow to continue the work on RAFT, which was the main reason I needed 16bits decoding in the first place.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions