-
Notifications
You must be signed in to change notification settings - Fork 55
Enhancing RGB Tile Contrast #202
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
base: master
Are you sure you want to change the base?
Enhancing RGB Tile Contrast #202
Conversation
Will be marked as ready for review after more testing. |
03b68a3
to
1aad275
Compare
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. But for this pull request: All tested, everything works as it should. |
Sphinx fixes and tutorial updates Jb/sept25
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 theprocess_tile
,process_tile_train
, andtile_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 theout_transform
from the data object, since that's all the calling methods actually need anyway. This change affectsprocess_tile
,process_tile_ms
, andprocess_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 totrue
, allowing for immediate performance gains if the data is re-tiled.