Elliptical Hough Transform doesn't work on own images

Hi everyone,

I am currently trying to use elliptical hough transforms with the end goal of using it to outline droplets for my final university project. I am using code based of this:

However, it only seems to work with some images in the skimage data library (not all) and not at all with my own basic image, such as:

droplet

Is anybody else having issues using own images and if so have you found a solution?

Thanks for the help and happy new year!
Tom

Hi Tom, welcome to the forum! You should take the magnitude of the gradient of your image before computing its Hough transform (for example by transforming first your image with a Canny filter as in the example you linked to). Did you use a gradient filter before computing the Hough transform? If you already did, could you please share a reproducible snippet of code so that we can see where the problem is?

Hi Emmanuelle,

Thank you so much for the response!
Here is the code that I used, and the output result of the image above. It seems to work on the straight edge but not on the elliptical one.134436456_116827580206190_6801207212639329959_n|613x500


Happy new year
Tom

hough_ellipse has many parameters and is therefore a bit hard to use, but in your case, fitting with a circle instead of an ellipse gives good results

from skimage import io, draw, filters, feature, transform, img_as_ubyte
import plotly.express as px
img = img_as_ubyte(io.imread('droplet.png', as_gray=True))
px.imshow(img)
edges = feature.canny(img, sigma=2, low_threshold=0.65, high_threshold=0.8)
px.imshow(edges)
import numpy as np
radii = np.arange(100, 150, 2)
result = transform.hough_circle(edges, radii)
accums, cx, cy, radii = transform.hough_circle_peaks(result, radii,
                                           total_num_peaks=2)
from skimage import color, draw
image = color.gray2rgb(img)
for center_y, center_x, radius in zip(cy, cx, radii):
    circy, circx = draw.circle_perimeter(center_y, center_x, radius,
                                    shape=image.shape)
    image[circy, circx] = (220, 20, 20)
px.imshow(image)

As for ellipses, it is true that I could not make it work with hough_ellipse and your image… I will try to investigate a bit more.

2 Likes

Wow, thanks so much for the help! Will try using this with some other images I’ve got instead of hough_ellipse.
If you get any further successes using the ellipse that would be amazing!
Thanks again