Reputation: 23
I'm new with Python and I've tried to detect an ellipse in the following picture: https://i.sstatic.net/5ybMh.jpg
But when I use this code:
import matplotlib.pyplot as plt
from skimage import io
from skimage import data, color, img_as_ubyte
from skimage.feature import canny
from skimage.transform import hough_ellipse
image_rgb = io.imread('5ybMh.jpg',)
image_gray = color.rgb2gray(image_rgb)
edges = canny(image_gray, sigma=2.0,
low_threshold=0.55, high_threshold=0.8)
result = hough_ellipse(edges, accuracy=20, threshold=250,
min_size=0, max_size=0)
result.sort(order='accumulator')
I get the ValueError:
Buffer and memoryview are not contiguous in the same dimension.
I use scikit-image version 0.12.3. I think there is a problem with the min_size=0 and max_size=0, but I'm not sure if there is a context between the error an this two parameters. In the doc I couldn't find very helpful informations about the parameters. (http://scikit-image.org/docs/dev/api/skimage.transform.html?highlight=transform#skimage.transform.hough_ellipse)
So can anybody explain me what this error means and if I have to change the parameters, which value they should have?
Upvotes: 2
Views: 3045
Reputation: 3645
I finally found the issue in your code! :)
With the parameters you set in the canny
function for your image, the edges
image is empty! (all black)
This seems to be an issue for the hough_ellipse
function as you can see by trying to run the following:
import numpy as np
from skimage.transform import hough_ellipse
result = hough_ellipse(np.zeros((100, 100)))
If you change the parameters in the canny
function in order to get at least a few contours, the error is not raised anymore. I believe that this behavior is a bug (it should just return an empty list) and I am going to report it.
Hereafter is the code I could run without error. The parameters for the Canny algorithm and the ellipse are taken randomly.
from skimage import io
from skimage import data, color
from skimage.feature import canny
from skimage.transform import hough_ellipse
image_rgb = io.imread('5ybMh.jpg',)
image_gray = color.rgb2gray(image_rgb)
edges = canny(image_gray, low_threshold=.4, high_threshold=.9)
result = hough_ellipse(edges, threshold=20, min_size=10)
On a side note, I found the hough_ellipse
function extremely slow for some not so "crowded" edge maps. Maybe you will need some sort of artifact cleaning (deleting very short edges for instance) if you are facing the same issue.
On a second side note, skimage
version 0.13.0
is out and it's always good to work with the last version of a library ;)
Note: This bug is fixed in versions 0.14.x
of the library.
Upvotes: 2