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

Color Bilateral Filter #606

Merged
merged 6 commits into from
May 20, 2024
Merged

Color Bilateral Filter #606

merged 6 commits into from
May 20, 2024

Conversation

ripytide
Copy link
Member

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 ripytide marked this pull request as ready for review May 15, 2024 20:13
@ripytide
Copy link
Member Author

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

@theotherphil
Copy link
Contributor

theotherphil commented May 15, 2024

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
Copy link
Member Author

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.

src/filter/bilateral.rs Outdated Show resolved Hide resolved
src/filter/bilateral.rs Outdated Show resolved Hide resolved
src/filter/bilateral.rs Show resolved Hide resolved
src/filter/bilateral.rs Outdated Show resolved Hide resolved
src/filter/bilateral.rs Outdated Show resolved Hide resolved
src/filter/mod.rs Outdated Show resolved Hide resolved
tests/regression.rs Show resolved Hide resolved
src/filter/median.rs Outdated Show resolved Hide resolved
@ripytide ripytide closed this May 19, 2024
@ripytide ripytide deleted the current branch May 19, 2024 16:18
@ripytide ripytide restored the current branch May 19, 2024 16:27
@ripytide ripytide reopened this May 19, 2024
@ripytide ripytide force-pushed the current branch 3 times, most recently from 4f67242 to 18cec90 Compare May 19, 2024 21:35
@ripytide
Copy link
Member Author

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

Copy link
Contributor

@theotherphil theotherphil left a comment

Choose a reason for hiding this comment

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

This looks almost good to go - just one bug I’ve spotted.

examples/bilateral.rs Outdated Show resolved Hide resolved
src/filter/bilateral.rs Outdated Show resolved Hide resolved
use super::*;

#[test]
fn test_bilateral_filter_greyscale() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Let’s leave this test input and expectations the same as it was before as a sanity check - a new implementation shouldn’t change the output values enough to make this fail

Copy link
Member Author

@ripytide ripytide May 20, 2024

Choose a reason for hiding this comment

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

I've left the input image and input parameters the same or as their equivalents since switching from window_size to radius, hence 3 -> 1, but I think rounding differences in the new implementation are causing the output to change slightly. From my testing it still looks to be giving the same output as shown in the images I posted so I'm fairly confident it's doing the right thing overall.

@theotherphil theotherphil merged commit 6ce0829 into image-rs:master May 20, 2024
15 checks passed
@theotherphil
Copy link
Contributor

Thanks!

@ripytide ripytide deleted the current branch May 20, 2024 15:21
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