-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
median filter #1161
median filter #1161
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you Andrea, this will make a great addition and it's always a pleasure to see unit tests in a PR. I've left a couple of comments inline that will need addressing.
src/pipeline.cc
Outdated
|
||
// Median - must happen before blurring, due to the utility of blurring after thresholding | ||
if (shouldApplyMedian) { | ||
image = sharp::Median(image, baton->medianSize); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can probably use libvips' median
operation, something like:
if (baton->medianSize > 0) {
image = image.median(baton->medianSize);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, although I am missing something... do we still need
VImage Median(VImage image, int const m) {
return image.rank(m, m, (m*m)/2);
}
in src/operations.cc ?
src/pipeline.cc
Outdated
@@ -1194,6 +1199,7 @@ NAN_METHOD(pipeline) { | |||
baton->flatten = AttrTo<bool>(options, "flatten"); | |||
baton->negate = AttrTo<bool>(options, "negate"); | |||
baton->blurSigma = AttrTo<double>(options, "blurSigma"); | |||
baton->medianSize = AttrTo<double>(options, "medianSize"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The size is integral so uint32_t
would make a better type here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed! sorry - again - for the copy-paste.
src/operations.cc
Outdated
/* | ||
* Median filter with mask size m | ||
*/ | ||
VImage Median(VImage image, int const m) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here, do we still need this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good spot, yes, this code is no longer used. Please go ahead and remove it and its definition in the header file, thank you.
Thank you, this will be in v0.20.1. |
following #1159 I added the median filter using vips_rank()