image-rs / imageproc

Image processing operations
MIT License
758 stars 149 forks source link

Color Bilateral Filter #606

Closed ripytide closed 6 months ago

ripytide commented 6 months ago

This PR expands the implementation of bilateral_filter() to any pixel type including Rgb by using a ColorSimilarity trait which allows arbitrary user defined metrics to be used. Another trait WeightedAverage was needed in order to allow the implementation to work with any pixel type.

It's mildly slower than the old version on greyscale images from my testing which was annoying but I can barely even understand the old version as the variable naming was very poor. I think this kind of function can be easily parallelized though which would make it tons faster than the old version.

ripytide commented 6 months ago

Here is an example of it in action: Before: leaf After: bilateral_color

theotherphil commented 6 months ago

Thanks, this is a nice function to have. I’ll review it this weekend.

The old function looks to have a very similar structure to yours except for using lookup tables for both colour and distance weights.

ripytide commented 6 months ago

Using a lookup table for non-greyscale becomes a much trickier as there are many many different combinations. Also the old version only allowed Gaussian Euclidean similarity but this version allows user-specified Similarity which also makes creating a lookup table more difficult.

ripytide commented 6 months ago

All comments raised have been addressed and #620 opened for the non-related changes.

theotherphil commented 6 months ago

Thanks!