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

Add ColorType::Multiband enum variant to support samples>1 per pixel #224

Merged
merged 9 commits into from
Mar 24, 2024

Conversation

weiji14
Copy link
Contributor

@weiji14 weiji14 commented Mar 4, 2024

Building on the work at #216 to support reading multi-band TIFF images (common in GeoTIFFs).

This PR extends the work done by @tromper in #216 which added the unit test for reading a 5-band GeoTIFF. I've just added the ColorType::Multiband enum variant as suggested at #216 (comment)), and made sure that the decoder functions can handle this multi-band type.

References:

Supersedes #216, closes #214 and resolves #147.

tromper and others added 5 commits September 11, 2023 08:23
…lowing BlackIsZero and WhiteIsZero to have up to 64 bits per sample. Also includes decode_geotiff_images unit test.
Contains attributes bit_depth and num_samples
When PhotometricInterpretation is BlackisZero or WhiteIsZero, and samples per pixel is more than 1, set the ColorType to Multiband. Also ensure that the expand_chunk function handles ColorType::Multiband, and updated the decode_geotiff_images unit test.
src/decoder/image.rs Show resolved Hide resolved
Comment on lines 578 to 584
(
ColorType::Multiband {
bit_depth: _n,
num_samples: _samples,
},
_,
) => {}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

A little unsure if this should be a separate branch, or go in one of the branches above. Not familiar with what the Horizontal and FloatingPoint predictors are.

Copy link
Contributor

Choose a reason for hiding this comment

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

The predictors are filters that are applied to the pixel data before compression, to help improve the compression ratio. Multiband should be included in both the match existing match arms where Gray is.

Copy link
Contributor Author

@weiji14 weiji14 Mar 24, 2024

Choose a reason for hiding this comment

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

Ok, done at e0b9ae0, but best if you can double check it. I don't have a multi-band TIFF file with a Horizontal/FloatingPoint predictor to test this out on.

@weiji14 weiji14 marked this pull request as ready for review March 6, 2024 19:51
weiji14 added a commit to weiji14/cog3pio that referenced this pull request Mar 17, 2024
Pulling from the `multi-band-geotiff` branch from my personal fork, that is currently in a pull request at image-rs/image-tiff#224.
@fintelia fintelia merged commit 0c54a18 into image-rs:master Mar 24, 2024
6 checks passed
@weiji14 weiji14 deleted the multi-band-geotiff branch March 24, 2024 22:14
weiji14 added a commit to weiji14/cog3pio that referenced this pull request Mar 24, 2024
The Multi-band PR at image-rs/image-tiff#224 has been merged, so updating to use the main branch instead.
weiji14 added a commit to weiji14/cog3pio that referenced this pull request Mar 25, 2024
* 📌 Use image-tiff fork with multi-band support

Pulling from the `multi-band-geotiff` branch from my personal fork, that is currently in a pull request at image-rs/image-tiff#224.

* ✨ Support reading multi-band GeoTIFF files

Count the number of bands or channels in the GeoTIFF file when decoding by looking at the ColorType. E.g. Gray = 1 band, Multiband = N bands. Added a unit test to read a 2-band float32 GeoTIFF file.

* ✅ Pytest check reading multi-band remote GeoTIFF

Ensure that reading a multi-band GeoTIFF file from a remote URL works.

* 📝 Update note on multi-band support in main README.md

Also clarify that the roadmap item on reading single-band GeoTIFFs is for different dtypes.

* 📌 Pin to image-tiff 0c54a18

The Multi-band PR at image-rs/image-tiff#224 has been merged, so updating to use the main branch instead.

* 🥅 Return TiffUnsupportedError instead of unimplemented panic

Replace `unimplemented!` with a recoverable TiffError::UnsupportedError instead to allow for better exception handling. Moved the band counting logic in the ndarray method above the image dimension line, and added a unit test to ensure unsupported ColorType TIFFs are handled properly.
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.

Very minor changes to allow multiband GeoTiff reading Support for arbitrary sample counts
3 participants