wrong result for morphology opening
See original GitHub issue🐛 Bug
To Reproduce
Steps to reproduce the behavior:
import torch
import numpy as np
from scipy.ndimage.morphology import grey_opening
from kornia.morphology import opening
from skimage.morphology import opening as sk_opening
kernel = np.array([[0, 0, 0, 0, 1, 0, 0, 0, 0],
[0, 0, 1, 1, 1, 1, 1, 0, 0],
[0, 1, 1, 1, 1, 1, 1, 1, 0],
[0, 1, 1, 1, 1, 1, 1, 1, 0],
[1, 1, 1, 1, 1, 1, 1, 1, 1],
[0, 1, 1, 1, 1, 1, 1, 1, 0],
[0, 1, 1, 1, 1, 1, 1, 1, 0],
[0, 0, 1, 1, 1, 1, 1, 0, 0],
[0, 0, 0, 0, 1, 0, 0, 0, 0]], dtype=np.float32)
input = np.zeros([1, 1, 128, 128])
output_scipy = grey_opening(input[0, 0, :, :], structure=kernel)
output_sk = sk_opening(input[0, 0, :, :], kernel)
output_kornia = opening(torch.tensor(input), torch.tensor(kernel))
print(np.all(output_scipy == output_sk))
print(np.all(output_sk == output_kornia))
print(np.all(output_scipy == output_kornia))
this bug present on master branch, opening
is not yet in any release version
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (3 by maintainers)
Top Results From Across the Web
Cases where Morphological Opening and Closing yields the ...
Remember, an opening is an erosion followed by a dilation where a closing is a dilation followed by an erosion.
Read more >Module: morphology — skimage v0.19.2 docs
The morphological opening on an image is defined as an erosion followed by a dilation.
Read more >Morphological Operations - an overview ... - ScienceDirect.com
Opening is an image morphological operation that darkens small objects and entirely removes single-pixel objects like noise spikes and small spurs.
Read more >OpenCV Morphological Operations - PyImageSearch
Figure 8: The results of applying an opening operation to our image — notice how the small, random blobs have been removed. Notice...
Read more >Men with a complete absence of normal sperm morphology ...
In couples with infertility, abnormal strict morphology of 0% normal forms (NF) is a criterion to proceed rapidly to in vitro fertilization ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I think it is solved. But I don’t remeber well what was this about. I am going to check it and I Will answer properly.
De: Edgar @.> Enviado: lunes, 2 de agosto de 2021 14:56 Para: @.> CC: @.>; @.> Asunto: Re: [kornia/kornia] wrong result for morphology opening (#1045)
@Manza12https://emea01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FManza12&data=04|01||3e2d6dd25c6f4abb7f0908d955b4ee2d|84df9e7fe9f640afb435aaaaaaaaaaaa|1|0|637635057835268856|Unknown|TWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D|1000&sdata=UEjEuOkGvjO2ASrQP%2BGw7dl3Dh0R3fPh4BVPB3xDVWA%3D&reserved=0 is this still relevant ?
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://emea01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fkornia%2Fkornia%2Fissues%2F1045%23issuecomment-891002195&data=04|01||3e2d6dd25c6f4abb7f0908d955b4ee2d|84df9e7fe9f640afb435aaaaaaaaaaaa|1|0|637635057835278809|Unknown|TWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D|1000&sdata=dJzK3uIAhkcLnoErr7enX0g8XfbHgmhCZBvUtRMwd%2FA%3D&reserved=0, or unsubscribehttps://emea01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FALAHVFRLDPYYFN2TVUM45BDT22IXLANCNFSM452HSMSA&data=04|01||3e2d6dd25c6f4abb7f0908d955b4ee2d|84df9e7fe9f640afb435aaaaaaaaaaaa|1|0|637635057835278809|Unknown|TWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D|1000&sdata=%2BuEGe4CbK0Vay1GJm0yQhhUy0Vnco6h%2FwsOlSpT60tY%3D&reserved=0.
This bug is produced by the padding of the border. I will implement a custom border value for all the morphological operations as it is done in nnMorpho. This way you would be able to fully control the border value.
Also, comparing PyTorch tensors with numpy arrays won’t work for np.all; last two lines should be
Nevertheless, I checked the images and it is true that they don’t give the same result. When testing with
input = np.ones([1, 1, 128, 128])
they do, though