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

Erode / dilate preliminary implementation. #1744

Closed
wants to merge 5 commits into from

Conversation

WRidder
Copy link

@WRidder WRidder commented Jun 6, 2019

Fixes #1719.

Initial attempt to add erode/dilate functionality. It works, but for some reason the morph dilate/erode functionality of libvips (https://jcupitt.github.io/libvips/API/current/libvips-morphology.html#vips-morph) seems to invert the image. While there is a reference to that behaviour in the documentation, I'd like someone to shed some light on that.

Open to any suggestions of course.

@coveralls
Copy link

coveralls commented Jun 6, 2019

Coverage Status

Coverage increased (+0.004%) to 99.759% when pulling db87b56 on WRidder:master into 69fe21a on lovell:master.

@lovell
Copy link
Owner

lovell commented Jun 6, 2019

Thank you very much for this PR. I expect to be able to take a closer look at it next week.

@WRidder
Copy link
Author

WRidder commented Aug 5, 2019

@lovell Did you manage to have a look already?

@rustyguts
Copy link
Contributor

@WRidder you missed a comma in package.json.

@WRidder
Copy link
Author

WRidder commented Aug 22, 2019

@rustyguts Thanks!

@jbendes
Copy link

jbendes commented Sep 27, 2019

Any update on this @lovell? If you want help with a review, I'm happy to help! Would love to have this merged in.

Copy link
Owner

@lovell lovell left a comment

Choose a reason for hiding this comment

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

Thanks for bearing with me whilst I got around to looking at this PR in more detail. It's always a pleasure to see lots of test cases! I like the API you've proposed with its simple, automagic creation of a matrix as this doesn't prevent a future possible enhancement to provide a custom matrix as an array of values e.g. cross-shaped for a more rounded result. I've added a few minor comments inline, with the only one that I think we should really address being the addition of an upper bound on the width.

if (!is.defined(width)) {
// No arguments: default to 1px dilation (3x3 mask)
this.options.dilateWidth = 1;
} else if (is.integer(width) && width > 0) {
Copy link
Owner

@lovell lovell Oct 2, 2019

Choose a reason for hiding this comment

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

We should place an upper bound on this. Any thoughts on a suitable value?

// Numeric argument: specific width
this.options.dilateWidth = width;
} else {
throw new Error('Invalid dilation width (positive integer) ' + width);
Copy link
Owner

Choose a reason for hiding this comment

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

Could use is.invalidParameterError here.

@@ -1271,6 +1281,8 @@ NAN_METHOD(pipeline) {
baton->gammaOut = AttrTo<double>(options, "gammaOut");
baton->linearA = AttrTo<double>(options, "linearA");
baton->linearB = AttrTo<double>(options, "linearB");
baton->dilateWidth = AttrTo<int32_t>(options, "dilateWidth");
Copy link
Owner

Choose a reason for hiding this comment

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

Could use unsigned uint32_t here.

* Dilate an image
*/
VImage Dilate(VImage image, int const width) {
int maskWidth = 2*width + 1;
Copy link
Owner

Choose a reason for hiding this comment

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

Could make this const.

@@ -170,6 +170,44 @@ function blur (sigma) {
return this;
}

/**
* Dilate the image.
Copy link
Owner

Choose a reason for hiding this comment

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

It might be nice to expand a little about what this means and mention things like "morphology" and the use of binary/two-tone/greyscale images being more suitable.

@WRidder
Copy link
Author

WRidder commented Oct 17, 2019

Thanks for you comments! I'll have a look at your suggestions asap :)

@lovell
Copy link
Owner

lovell commented Mar 14, 2020

If you hadn't noticed, there's been an internal migration to N-API hence the conflicts. As always, happy to keep PRs open for as long as required.

@lovell
Copy link
Owner

lovell commented Nov 16, 2021

This PR has drifted a bit and there haven't been any updates in 18 months so I'm going to close it for now. Please feel free to re-open with updates or, for anyone else reading this, submit a new PR with this feature.

Thanks again Wilbert for taking the time to work on this PR and improving sharp.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add erode and dilate from vips_morph
5 participants