Skip to content

Conversation

ChristopherKotthoff
Copy link
Collaborator

@ChristopherKotthoff ChristopherKotthoff commented Jul 16, 2025

Summary

This pull request enhances the image preprocessing capabilities in detectree2/preprocessing/tiling.py by introducing an optional RGB contrast enhancement feature and fixing some inconsistencies with return values across the tiling functions.

Changes

RGB Contrast Enhancement

I've added an enhance_rgb_contrast parameter to the process_tile, process_tile_train, and tile_data functions. When this feature is enabled, the system rescales RGB pixel values from their original distribution to a 1-255 range, reserving 0 for nodata values. The contrast enhancement uses percentile-based rescaling (0.2% to 99.8%) to increase RGB diversity, which significantly improves the accuracy of jungle crown delineations.

Context Manager Fix

There was also a resource handling issue I discovered where functions were returning a data object from within a context manager (with rasterio.open(img_path) as data:), which could lead to problems down the line. I've fixed this by having the functions return only the out_transform from the data object, since that's all the calling methods actually need anyway. This change affects process_tile, process_tile_ms, and process_tile_train functions.

Minor Adjustments

Additionally, I made a small adjustment to the convex mask precision by reducing the buffer size from 5 to 3 for the convex delineation mask. This value is still large enough to be effective while avoiding too much inclusion of nearby tree crowns.

Future Considerations

I'll admit the function signatures are getting pretty parameter-heavy with these additions. I'm planning a follow-up pull request in the near future to refactor and clean up these function interfaces, but the current implementation is still manageable for now.

Compatibility

Existing workflows will work exactly as before. The parameter enhance_rgb_contrast defaults to true, allowing for immediate performance gains if the data is re-tiled.

@ChristopherKotthoff
Copy link
Collaborator Author

Will be marked as ready for review after more testing.

@ChristopherKotthoff ChristopherKotthoff force-pushed the chris/color-contrast-rescaling branch from 03b68a3 to 1aad275 Compare July 20, 2025 21:00
@ChristopherKotthoff
Copy link
Collaborator Author

Many problems are arising with dependency issues and module version mismatch in the GitHub actions. MyPy was raising errors that I was not able to replicate on my system with the same version numbers. I was able to fix them via commit fix -> overvation -> commit fix -> etc.
Also it seems that the Docker Action never is dispatched.

But for this pull request: All tested, everything works as it should.
Please feel free to review / merge.

@ChristopherKotthoff ChristopherKotthoff marked this pull request as ready for review July 20, 2025 21:05
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.

2 participants