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

[WIP] Add 3D support to sobel #2787

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

dcz-mpipz
Copy link

Added generalized version of Sobel edge detection in a particular direction. Accepts N-dimensional images, using h=[1, 2, 1] and h'=[1, 0, -1]. Only tested for 3D images. however.

Description

This change provides a way to implement a full Sobel operator, as noted in #2247

The sobel implementation is directional, and provides a function generating kernels. The values of sobel function can be greater than 1, despite normalizing the matrix. Dimensions above 3 were not checked, since I don't know what to expect and how to write tests.

Adding a full Sobel shouldn't be difficult, e.g. by analogy to 2-dim Sobel:

        res = numpy.empty_like(image)
        for axis in range(image.ndim):
            res += sobel(image, axis, mask) ** 2
        res /= np.sqrt(2)

I did not implement that, since I don't know whether sqrt(2) is a suitable factor for higher dimensions.

Checklist

  • Full sobel
  • Unit tests for fimensions above 3

For reviewers

(Don't remove the checklist below.)

  • Check that the PR title is short, concise, and will make sense 1 year
    later.
  • Check that new functions are imported in corresponding __init__.py.
  • Check that new features, API changes, and deprecations are mentioned in
    doc/release/release_dev.rst.

Added generalized version of Sobel edge detection in a particular direction. Accepts N-dimensional images, using h=[1, 2, 1] and h'=[1, 0, -1]. Only tested for 3D images. however.
@pep8speaks
Copy link

pep8speaks commented Sep 1, 2017

Hello @dcz-mpipz! Thanks for updating the PR.

Cheers ! There are no PEP8 issues in this Pull Request. 🍻

Comment last updated on September 01, 2017 at 12:56 Hours UTC

@emmanuelle emmanuelle changed the title Add 3D support to sobel [WIP] Add 3D support to sobel Sep 1, 2017
h = np.array([1, 2, 1])
for i in range(ndim - 1):
ret = np.multiply.outer(ret, h)
factor = ret.sum(1).max() # Find maximum factor for normalization
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure this is the right normalization but on the other hand the normalization of the 2D kernel seems weird (it does not correspond to the definition of the Wikipedia web page for Sobel)

Copy link
Author

Choose a reason for hiding this comment

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

This was just a guess, based on what other kernels in edges.py look like. It's more of a placeholder.

Copy link
Member

Choose a reason for hiding this comment

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

From git blame I think it was @ahojnnes who wrote the kernels with the normalization.

@emmanuelle
Copy link
Member

I think you would need to modify also the _mask_filter_result function so that it uses a structuring element of the same dimension as result or mask.

@dcz-mpipz
Copy link
Author

You're right, I'll try to get around to it soon. Should that be a separate pull request?

@emmanuelle
Copy link
Member

No, it should be done in the same branch, and as you push new commits they will automatically appear in this pull request.

Base automatically changed from master to main February 18, 2021 18:22
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