Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support tiled TIFFs #4201

Merged
merged 13 commits into from
Sep 20, 2022
Merged

Support tiled TIFFs #4201

merged 13 commits into from
Sep 20, 2022

Conversation

szkarpinski
Copy link
Collaborator

@szkarpinski szkarpinski commented Aug 29, 2022

Category:

New feature (non-breaking change which adds functionality)

Description:

Until now, only striped TIFFs were supported. In this PR I add support for tiled TIFFs.

Additional information:

The main disadvantage of striped TIFFs is that efficient ROI decoding is effectively impossible - you always need to read a whole strip. This is the reason why Tiled TIFFs are common in applications where the data is bigger, for example in spatial information or microscopy. That's why we want to support them.

Before, this decoder was reading TIFF line-by-line. Now I extended it to support tiles and, in order to avoid code duplication, I simply pretend that lines are 1 x imagewidth tiles.

I do not support exotic bitdepths (i.e. other than 8, 16 and 32), because I was unable to find software capable of correctly writing or reading those, so it was impossible to test reliably.

Affected modules and functionalities:

I've temporarily fixed the testing framework, but I'll rebase on the proper fix (#4217) once it's merged.

Key points relevant for the review:

Tests:

The tests require images from NVIDIA/DALI_extra#101

  • Existing tests apply
  • New tests added
    • Python tests
    • GTests
    • Benchmark
    • Other
  • N/A

Checklist

Documentation

  • Existing documentation applies
  • Documentation updated
    • Docstring
    • Doxygen
    • RST
    • Jupyter
    • Other
  • N/A

DALI team only

Requirements

  • Implements new requirements
  • Affects existing requirements
  • N/A

REQ IDs: N/A

JIRA TASK: DALI-2924

@szkarpinski szkarpinski mentioned this pull request Aug 30, 2022
18 tasks
@szkarpinski szkarpinski marked this pull request as ready for review September 2, 2022 16:09
Copy link
Contributor

@klecki klecki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small nitpick, looks ok otherwise.

Comment on lines +360 to +364
DALI_ENFORCE(TIFFReadTile(tiff.get(), buf.get(), tile_x, tile_y, 0, 0) > 0,
"TIFFReadTile failed");
} else {
LIBTIFF_CALL(TIFFReadScanline(tiff.get(), buf.get(), tile_y, 0));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks weird, that we use both LIBTIFF_CALL and DALI_ENFORCE for TIFFRead***

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is weird, but that's libtiff. Almost all of its functions, including TIFFReadScanline, return 1 on success and that's what LIBTIFF_CALL checks for. But TIFFReadTile returns the number of bytes read, because why not

Signed-off-by: Szymon Karpiński <skarpinski@nvidia.com>
Signed-off-by: Szymon Karpiński <skarpinski@nvidia.com>
Signed-off-by: Szymon Karpiński <skarpinski@nvidia.com>
Signed-off-by: Szymon Karpiński <skarpinski@nvidia.com>
Signed-off-by: Szymon Karpiński <skarpinski@nvidia.com>
Signed-off-by: Szymon Karpiński <skarpinski@nvidia.com>
Signed-off-by: Szymon Karpiński <skarpinski@nvidia.com>
Signed-off-by: Szymon Karpiński <skarpinski@nvidia.com>
Signed-off-by: Szymon Karpiński <skarpinski@nvidia.com>
// TODO(skarpinski) Support tiled images
if (info.is_tiled)
return {false, make_exception_ptr(std::logic_error("Tiled images are not yet supported"))};
if (info.is_tiled && info.tile_width % 16 != 0 && info.tile_height % 16 != 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (info.is_tiled && info.tile_width % 16 != 0 && info.tile_height % 16 != 0) {
if (info.is_tiled && (info.tile_width % 16 != 0 || info.tile_height % 16 != 0)) {

Shouldn't be both a multiple of 16?

@@ -234,7 +234,7 @@ class DecoderTestBase : public ::testing::Test {
Tensor<CPUBackend> Crop(const Tensor<CPUBackend> &input, const ROI &roi) {
int ndim = input.shape().sample_dim();
VALUE_SWITCH(ndim, Dims, (2, 3, 4), (
TYPE_SWITCH(input.type(), type2id, InputType, (IMGCODEC_TYPES), (
TYPE_SWITCH(input.type(), type2id, InputType, (IMGCODEC_TYPES, double), (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the purpose of adding double here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess numpy reference data.

@jantonguirao jantonguirao self-assigned this Sep 20, 2022
@jantonguirao
Copy link
Contributor

!build

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [5957668]: BUILD STARTED

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [5957668]: BUILD PASSED

@jantonguirao jantonguirao merged commit 4721cd7 into NVIDIA:main Sep 20, 2022
staniewzki pushed a commit to staniewzki/DALI that referenced this pull request Sep 21, 2022
Until now, only striped TIFFs were supported. In this PR I add support for tiled TIFFs.

Additional information:
The main disadvantage of striped TIFFs is that efficient ROI decoding is effectively impossible - you always need to read a whole strip. This is the reason why Tiled TIFFs are common in applications where the data is bigger, for example in spatial information or microscopy. That's why we want to support them.

Before, this decoder was reading TIFF line-by-line. Now I extended it to support tiles and, in order to avoid code duplication, I simply pretend that lines are 1 x imagewidth tiles.

We do not support exotic bitdepths (i.e. other than 8, 16 and 32), because I was unable to find software capable of correctly writing or reading those, so it was impossible to test reliably.

Signed-off-by: Szymon Karpiński <skarpinski@nvidia.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants