Issues with scaling images for canny edge detection

Robin Wilson r.t.wilson.bak at googlemail.com
Tue Jun 25 11:37:20 EDT 2013


Hi,

*Summary: *I'm fairly new to skimage, and I'm trying to replicate some work 
I've done in IDL using the Canny edge detector. I've imported the same 
image into skimage and tried running the Canny function with the same 
parameters, but I either get a blank image, or very different results to 
IDL which don't change regardless of the parameters I use. I suspect my 
problems may be related to how I am scaling my image to make it between 0 
and 1, as the documentation for the skimage Canny function requires.

*More details:*
The input image I used in both IDL and skimage is available 
at https://www.dropbox.com/s/xaiq9kitrf1b4cf/HOT_sub.tif.

In IDL I called the CANNY function (documentation available at 
http://www.exelisvis.com/docs/CANNY.html) as follows:

result = CANNY(image, HIGH=0.95, LOW=0.3, SIGMA=2)

and got the following image:


<https://lh3.googleusercontent.com/-xwuyuH_mxEA/Ucm2Y2m2EyI/AAAAAAAAEnw/46OmI8iuf0Q/s1600/IDL_Output.png>
I loaded the image into skimage as follows:

hot = skimage.io.imread("HOT_sub.tif")

And removed all negative values by adding the absolute value of the minimum:

abs_hot = hot + abs(np.min(hot))

>From what I'd read in the documentation, the function img_as_float would 
then scale this between 0 and 1 in a sensible way, but it gave an error:

C:\Python27\lib\site-packages\skimage\util\dtype.pyc in convert(image, 
dtype)
     73     if kind_in == 'f':
     74         if np.min(image) < 0 or np.max(image) > 1:
---> 75             raise ValueError("Images of type float must be between 
0 and 1")
     76         if kind == 'f':
     77             # floating point -> floating point

ValueError: Images of type float must be between 0 and 1

So I did it myself by simply dividing by the maximum value:

im_hot = img_as_float(abs_hot/np.max(abs_hot)

However, running the Canny edge detector on this image produces an entirely 
blank edge image:

edges = canny(im_hot, sigma=2, low_threshold=0.3, high_threshold=0.90)
np.sum(edges) # Gives 0 showing there are no edges found

Regardless how I play with the parameters, I can't seem to get it to give 
me any edges.

Interestingly, if I ignore the instructions to make sure that my input 
image is between 0 and 1, and just use the raw image:

edges = canny(hot, sigma=2, low_threshold=0.3, high_threshold=0.90)

I get a more sensible result (well, at least it isn't blank!):

<https://lh5.googleusercontent.com/-Ta33pkF-pIY/Ucm4abti3lI/AAAAAAAAEoA/iyX6FSKSPF4/s1600/skimage.png>
But this is very different to the result given by IDL - and furthermore, 
adjusting the parameters doesn't seem to change the output at all.

What am I doing wrong here? I suspect it is something to do with the image 
scaling, but I'm not sure - it could be a conceptual problem with my image 
processing knowledge, or I could be using skimage improperly. Does anyone 
have any ideas or suggestions as to where to go from here? If I manage to 
solve this I will, of course, write up the solution on my blog so that 
others can benefit too.

Best regards,

Robin
University of Southampton, UK
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/scikit-image/attachments/20130625/f00e1284/attachment.html>


More information about the scikit-image mailing list