-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Circle Detection #5525
Comments
please assign me this issue. |
Hi Gunjan, |
@ashbrin: Only people with write access to a repository can assign issues, so you will not be able to do it. However, for us to address this we may need some more info to help reproduce the problem: 1.) If I understand correctly, the existing demo runs okay for you, but when you try it on your own image you get the failure? 2.) What is the shape of the image where you are seeing the failure? Are you able to share a link to it? 3.) Have you confirmed the same bug with the latest scikit-image release (0.18.2)? @gunjan381, thank you for volunteering to help look at this. We usually don't explicitly assign issues as conflicting PRs for the same thing have not been common. I can assign you to this issue, but please let us know if you later decide not to work on it. |
ok. I am doing it. |
@grlee77 : Here are my responses for your questions: |
@grlee77 , I tried it in the scikit-image version 0.18.2 and it did not change the behavior. |
Can you confirm what line of the example it is getting stuck at? (Many different functions are being called in that script: It will be helpful if you can provide the exact script as you ran it. You will likely need to update some thresholds or other parameters a bit for it to work for your data. For example, you probably should set |
@grlee77 , ValueError: Cannot specify order when the array has no fields. When I use ArgumentParser and pass the image and that is when the program hangs indefinitely. I did not see that behavior when I run it in debug mode. |
@grlee77 , kindly let me know if you have been able to reproduce the issue based on the code and the image I have shared. |
I am able to reproduce the problem using your example. One issue is that some adjustment to the arguments in the call to I have not studied or worked with this kind of circle detection algorithm before, so it would take a bit of research to figure out what the issue likely is. Perhaps there is a problem in detecting concentric circles or starting parameter values are not at a reasonable point. Let me ping @scikit-image/core to see if anyone has more experience with this transform. It looks like |
The plot thickens. The following snippet works: from skimage import color, io
from skimage.feature import canny
from skimage.transform import hough_ellipse
image_rgb = io.imread("130327738-c75154d2-e6d5-4122-a220-c6b0dd078bd7.jpeg")
image_gray = color.rgb2gray(image_rgb)
edges = canny(image_gray, sigma=2.0,
low_threshold=0.55, high_threshold=0.8)
hough_ellipse(edges, accuracy=50, threshold=250,
min_size=100, max_size=120) |
@stefanv , thanks much for your response. |
@ashbrin What I meant was that this is confusing: the program does not freeze, whether when I run the other version it does. I am not sure why yet. |
Hello @ashbrin and thank you for your interest in Using your image and after adapting functions parameters: from matplotlib import pyplot as plt
import numpy as np
import imageio
from skimage import color
from skimage.feature import canny
from skimage.transform import hough_circle, hough_circle_peaks
from skimage.draw import circle_perimeter
img_rgb = imageio.imread(
"/tmp/130327738-c75154d2-e6d5-4122-a220-c6b0dd078bd7.JPG"
)
img = color.rgb2gray(img_rgb)
print(img.max())
edges = canny(img, sigma=3, mode="reflect")
hough_radii = np.arange(10, 130, 2)
hough_res = hough_circle(edges, hough_radii)
accums, cx, cy, radii = hough_circle_peaks(hough_res, hough_radii,
min_xdistance=1,
min_ydistance=1,
total_num_peaks=2)
for center_y, center_x, radius in zip(cy, cx, radii):
circy, circx = circle_perimeter(center_y, center_x, radius,
shape=img_rgb.shape)
img_rgb[circy, circx] = (220, 20, 20)
fig, (ax0, ax1) = plt.subplots(1, 2, figsize=(8, 4))
ax0.imshow(img_rgb)
ax1.imshow(edges)
fig.tight_layout()
plt.show() Closing, but feel free to reopen if you wish 😉 |
@rfezzani , thanks for your support. Unfortunately the code does not run and it throws an error File "", line 1, in TypeError: canny() got an unexpected keyword argument 'mode' I removed the parameter mode and ran it but it won't detect the circles. p.s. I do not find an option to "Open" the issue again. |
The |
BTW, you may find more help on |
@rfezzani , the version of the package is 0.18.1. I have attached the output I got after running the code (removed the mode parameter). As I had mentioned earlier, it returns an empty plot. |
Hum, as I can't reproduce the issue, can any @scikit-image/core member confirm/infirm this behavior? |
Hey everyone,
It happens because
Maybe the Canny parameters you chose/we proposed at the example are not well suited for the image you are using. I have the same results as @rfezzani when using this code without the argument from matplotlib import pyplot as plt
import numpy as np
import imageio
from skimage import color
from skimage.feature import canny
from skimage.transform import hough_circle, hough_circle_peaks
from skimage.draw import circle_perimeter
img_rgb = imageio.imread(
"/tmp/130327738-c75154d2-e6d5-4122-a220-c6b0dd078bd7.JPG"
)
img = color.rgb2gray(img_rgb)
print(img.max())
edges = canny(img, sigma=3)
hough_radii = np.arange(10, 130, 2)
hough_res = hough_circle(edges, hough_radii)
accums, cx, cy, radii = hough_circle_peaks(hough_res, hough_radii,
min_xdistance=1,
min_ydistance=1,
total_num_peaks=2)
for center_y, center_x, radius in zip(cy, cx, radii):
circy, circx = circle_perimeter(center_y, center_x, radius,
shape=img_rgb.shape)
img_rgb[circy, circx] = (220, 20, 20)
fig, (ax0, ax1) = plt.subplots(1, 2, figsize=(8, 4))
ax0.imshow(img_rgb)
ax1.imshow(edges)
fig.tight_layout()
plt.show() Could you please check if this code works? Thank you! |
Hello @alexdesiqueira , Thanks, |
Hi @ashbrin, >>> print(edges)
>>> print(edges.dtype)
>>> import matplotlib; print("matplotlib version: {}".format(matplotlib.__version__)) Thank you! |
Hello @alexdesiqueira , For print(edges.dtype) the output is bool Fo matplotlib version: 3.2.2 |
Hi @ashbrin, >>> print(edges.max()) and let us know? I feel something is not right for the parameters, in your case. |
Hello @alexdesiqueira , Thanks |
Hi @ashbrin, edges = canny(img, sigma=3) passing from matplotlib import pyplot as plt
import numpy as np
import imageio
from skimage import color
from skimage.feature import canny
from skimage.transform import hough_circle, hough_circle_peaks
from skimage.draw import circle_perimeter
img_rgb = imageio.imread(
"/tmp/130327738-c75154d2-e6d5-4122-a220-c6b0dd078bd7.JPG"
)
img = color.rgb2gray(img_rgb)
print(img.max())
edges = canny(img, sigma=3) # <--- change sigma in this line to different values
hough_radii = np.arange(10, 130, 2)
hough_res = hough_circle(edges, hough_radii)
accums, cx, cy, radii = hough_circle_peaks(hough_res, hough_radii,
min_xdistance=1,
min_ydistance=1,
total_num_peaks=2)
for center_y, center_x, radius in zip(cy, cx, radii):
circy, circx = circle_perimeter(center_y, center_x, radius,
shape=img_rgb.shape)
img_rgb[circy, circx] = (220, 20, 20)
fig, (ax0, ax1) = plt.subplots(1, 2, figsize=(8, 4))
ax0.imshow(img_rgb)
ax1.imshow(edges)
fig.tight_layout()
plt.show() Please check the behavior of these plots, with different sigmas. Maybe one (or some) of them could solve your issue there. |
comments moved over from Discussion(we plan to close Discussions and move existing ones back to issues)
|
Description
I have referred to this link, https://scikit-image.org/docs/dev/auto_examples/edges/plot_circular_elliptical_hough_transform.html for detecting circles within an image. However upon running the code using my image, it goes for a spin. I have to kill my session after waiting for 30 min
-->
Way to reproduce
Version information
The text was updated successfully, but these errors were encountered: