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

DOC: clarify that prewitt filter does not return the magnitude by default #18457

Closed
dschmitz89 opened this issue May 14, 2023 · 2 comments · Fixed by #18777
Closed

DOC: clarify that prewitt filter does not return the magnitude by default #18457

dschmitz89 opened this issue May 14, 2023 · 2 comments · Fixed by #18777
Labels
Documentation Issues related to the SciPy documentation. Also check https://github.com/scipy/scipy.org good first issue Good topic for first contributor pull requests, with a relatively straightforward solution scipy.ndimage
Milestone

Comments

@dschmitz89
Copy link
Contributor

dschmitz89 commented May 14, 2023

Issue with current documentation:

Like the sobel filter (#18444), prewitt by default computes a one dimensional transform. We should show how to compute the magnitude as that is typically the more useful image (cf. #18444).

image

from scipy import ndimage, datasets
import matplotlib.pyplot as plt
from skimage import filters

def prewitt_2d(image):
    image = image.astype('int32')
    dx = ndimage.prewitt(image, 0)  # horizontal derivative
    dy = ndimage.prewitt(image, 1)  # vertical derivative
    mag = np.hypot(dx, dy)  # magnitude
    mag *= 255.0 / np.max(mag)
    return mag

fig = plt.figure(figsize=(12, 3))
plt.gray()  # show the filtered result in grayscale
ax1 = fig.add_subplot(141)
ax2 = fig.add_subplot(142)
ax3 = fig.add_subplot(143)
ax4 = fig.add_subplot(144)


ascent = datasets.ascent()
ax1.imshow(ascent)
ax2.imshow(ndimage.prewitt(ascent))
ax2.set_title("scipy prewitt default (1D)")
ax3.imshow(filters.prewitt(ascent))
ax3.set_title("skimage prewitt default")
ax4.imshow(prewitt_2d(ascent))
ax4.set_title("scipy prewitt 2D magnitude")
for ax in [ax1, ax2, ax3, ax4]:
    ax.set_axis_off()
plt.show()
@dschmitz89 dschmitz89 added Documentation Issues related to the SciPy documentation. Also check https://github.com/scipy/scipy.org scipy.ndimage good first issue Good topic for first contributor pull requests, with a relatively straightforward solution labels May 14, 2023
@Ashad001
Copy link

Hi, can you emphasize what has to be done, the description seems to be a bit vague. Thankyou!

@dschmitz89
Copy link
Contributor Author

The root issue is that scipy.ndimage.prewitt by default computes a one dimensional Prewitt filter. This is not the "typical" use case in image processing. For example, skimage implements the magnitude instead (see images above).

In #18444, the same issue was fixed for the sobel filter. The documentation/examples should emphasize how to get the "typical" Prewitt filter from the function.

What needs to be done is a documentation PR. The Sobel filter PR can serve as an example. For general SciPy development, I recommend having a look at the quickstart and documentation related parts of the developer docs.

@j-bowhay j-bowhay added this to the 1.12.0 milestone Jun 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation Issues related to the SciPy documentation. Also check https://github.com/scipy/scipy.org good first issue Good topic for first contributor pull requests, with a relatively straightforward solution scipy.ndimage
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants
@dschmitz89 @j-bowhay @Ashad001 and others