Skip to content

Erode / dilate preliminary implementation. - #1744

Closed
WRidder wants to merge 5 commits into
lovell:masterfrom
WRidder:master
Closed

WRidder wants to merge 5 commits into
lovell:masterfrom
WRidder:master

Conversation

@WRidder

@WRidder WRidder commented Jun 6, 2019

Copy link
Copy Markdown

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

coveralls commented Jun 6, 2019 •

Copy link
Copy Markdown

Coverage Status

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

@lovell

lovell commented Jun 6, 2019

Copy link
Copy Markdown
Owner

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

@WRidder

WRidder commented Aug 5, 2019

Copy link
Copy Markdown
Author

@lovell Did you manage to have a look already?

@rustyguts

Copy link
Copy Markdown
Contributor

@WRidder you missed a comma in package.json.

@WRidder

WRidder commented Aug 22, 2019

Copy link
Copy Markdown
Author

@rustyguts Thanks!

@jbendes

jbendes commented Sep 27, 2019

Copy link
Copy Markdown

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

@lovell lovell left a comment

Copy link
Copy Markdown
Owner

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.

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

@lovell lovell Oct 2, 2019 •

Copy link
Copy Markdown
Owner

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?

Comment thread lib/operation.js
// Numeric argument: specific width
this.options.dilateWidth = width;
} else {
throw new Error('Invalid dilation width (positive integer) ' + width);

Copy link
Copy Markdown
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.

Comment thread src/pipeline.cc
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
Copy Markdown
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.

Comment thread src/operations.cc
* Dilate an image
*/
VImage Dilate(VImage image, int const width) {
int maskWidth = 2*width + 1;

Copy link
Copy Markdown
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.

Comment thread lib/operation.js
}

/**
* Dilate the image.

Copy link
Copy Markdown
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

WRidder commented Oct 17, 2019

Copy link
Copy Markdown
Author

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

@lovell

lovell commented Mar 14, 2020

Copy link
Copy Markdown
Owner

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

lovell commented Nov 16, 2021

Copy link
Copy Markdown
Owner

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