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

Add connectedComponents to MagickImage #114

Merged
merged 14 commits into from
Nov 7, 2023

Conversation

with-heart
Copy link
Contributor

This PR adds MagickImage#connectedComponents. You can learn more from the ImageMagick connected-components docs.

New things:

  • Threshold for storing a min/max threshold
  • ConnectedComponentsSettings for storing connectivity and connected-components operation defines (and applying them to/removing them from an image with #_setArtifacts/#_removeArtifacts)
  • ConnectedComponent which represents a connected component and is automatically loaded from the component instance

Other things:

  • added TestImages.connectedComponents using the test image from Magick.Net
  • added toBeWithinRangeDelta custom matcher to make it easier to expect a number to be within the range of ±delta
  • added copious amounts of jsdoc for improved dx

@with-heart with-heart changed the title Add ConnectedComponentsSettings Add connectedComponents to MagickImage Oct 25, 2023
@dlemstra
Copy link
Owner

Thanks for adding this. I will try to take a look at this on Friday. I am wonder if we should use another image here instead so we have different tests. And you might not need the toBeWithinRangeDelta method? It's possible that I this because Magick.NET has Q16 and Q16-HDRI. Also not sure if I am a fan of declaring part of the properties in the constructor I would rather have connectivity as a normal property. I do think it's good to start with the jsdoc but that will probably mean I will need to add this to all the other classes that we now have.

@with-heart
Copy link
Contributor Author

with-heart commented Oct 26, 2023

And you might not need the toBeWithinRangeDelta method? It's possible that I this because Magick.NET has Q16 and Q16-HDRI.

I didn't really understand the different quantum types until I'd already written the tests. That makes sense.

I am wonder if we should use another image here instead so we have different tests.

Since magick-wasm and Magick.Net should theoretically produce the same result, seems like having the same test in both would make sense here. But not sure!

Also not sure if I am a fan of declaring part of the properties in the constructor I would rather have connectivity as a normal property.

That's fair, will fix.

I do think it's good to start with the jsdoc but that will probably mean I will need to add this to all the other classes that we now have.

Don't worry, I'll help! #116

@dlemstra
Copy link
Owner

Since magick-wasm and Magick.Net should theoretically produce the same result, seems like having the same test in both would make sense here. But not sure!

They should produce the same results but what we are really testing is ImageMagick so I would like to have a different testcase here so we are testing ImageMagick with two different images instead of using a single image and expect the same result. When it breaks in Magick.NET it will also break here.

Copy link
Owner

@dlemstra dlemstra left a comment

Choose a reason for hiding this comment

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

Some more comments.

src/connected-component.ts Outdated Show resolved Hide resolved
src/connected-component.ts Show resolved Hide resolved
src/connected-component.ts Outdated Show resolved Hide resolved
* @param connectivity The number of neighbors to visit (4 or 8).
* @see {@link https://imagemagick.org/script/connected-components.php}
*
* @example
Copy link
Owner

@dlemstra dlemstra Oct 31, 2023

Choose a reason for hiding this comment

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

Not sure if I want to keep this here because that would also require me to maintain it. A description of the method and parameters and the @see should be sufficient?

And should we not add this documentation to the interface instead?

Copy link
Contributor Author

@with-heart with-heart Nov 7, 2023

Choose a reason for hiding this comment

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

Not sure if I want to keep this here because that would also require me to maintain it.

Yeah that's totally fair. Maintenance concerns are always a good reason to be wary of too much "extra" stuff.

I think @example theoretically shouldn't be much of a maintenance concern though, at least in this case:

  • the examples aren't very complex (just showing basic usage and return type)
  • the IMagickImage api likely won't change drastically

A description of the method and parameters and the @see should be sufficient?

I feel like it's a good first-touch bit of context for users on how to use this in a js-specific setting. Descriptions tell you what it does, @see gives extra information like the various defines available, but @example shows how to use it in js specifically.

Just sharing my thoughts though! If it still feels like something you'd prefer to not have to think about, will gladly remove

Copy link
Owner

Choose a reason for hiding this comment

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

I will remove them myself after merging the PR. I think we should put the examples somewhere else.

src/point.ts Outdated Show resolved Hide resolved
@with-heart
Copy link
Contributor Author

with-heart commented Nov 7, 2023

Just need to add a new test image and this should be about ready to go

I rotated the existing test image 180º and updated the tests.

* @param connectivity The number of neighbors to visit (4 or 8).
* @see {@link https://imagemagick.org/script/connected-components.php}
*
* @example
Copy link
Owner

Choose a reason for hiding this comment

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

I will remove them myself after merging the PR. I think we should put the examples somewhere else.

@dlemstra dlemstra merged commit 59efed4 into dlemstra:main Nov 7, 2023
10 checks passed
@with-heart with-heart deleted the connected-components branch November 7, 2023 22: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.

None yet

3 participants