Issues with scaling images for canny edge detection

Josh Warner silvertrumpet999 at gmail.com
Tue Jun 25 23:59:09 EDT 2013


Argh, correction: if normhot = abs_hot / np.max(abs_hot) were conducting 
truncating division the result wouldn't be a boolean array but an integer 
array, with all values 0 except the previous maximum value(s), which would 
be 1. Functionally boolean, but the dtype would be integer.


On Tuesday, June 25, 2013 10:55:31 PM UTC-5, Josh Warner wrote:
>
> I can‘t duplicate this, but I may know what's going on.
>
> img_as_float converts non-float datatypes into floating-point images on 
> the range [0, 1]. The traceback you note shows that a floating point array 
> was passed to img_as_float, but the image had values outside [0, 1]. Try 
> checking hot.dtype before running img_as_float; if it's an (unsigned) 
> integer, everything should work fine. 
>
> From the operation you listed, abs_hot = hot + abs(np.min(hot)), it seems 
> like hot should still be an integer, but that traceback code path is only 
> active for inputs where arr.dtype.kind == 'f' so abs_hot got converted to 
> float at some point. Check abs_hot.dtype right prior to running 
> img_as_float; is it an integer or a float?
>
> My intuition for a blank canny result is that your division operation abs_hot 
> / np.max(abs_hot) may have been between two integer types, resulting in a 
> boolean array which would have almost no edges. Try assigning normhot = 
> abs_hot / np.max(abs_hot) and checking the dtype; if it's boolean, cast 
> one or both to float before the division and re-run. The other possibility 
> is the canny parameters are pretty far off.
>
> I‘m not sure what’s going on with the raw result, but check the above and 
> get back with us! Hopefully that helps to get things moving.
>
> Josh
>
> On Tuesday, June 25, 2013 10:37:20 AM UTC-5, Robin Wilson wrote:
>
> 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/11558552/attachment.html>


More information about the scikit-image mailing list