Issues with scaling images for canny edge detection

Tony Yu tsyu80 at gmail.com
Wed Jun 26 18:48:18 EDT 2013


On Wed, Jun 26, 2013 at 6:08 AM, Robin Wilson <r.t.wilson.bak at googlemail.com
> wrote:

<snip>


> I think I've managed to solve most of my problems, but I have one
> question: the canny routine seems to work fine for my original image,
> without rescaling it from 0-1. Is there a reason that it should only work
> for images between 0-1, or am I safe to use my original images?
>
>

Hi Robin,

It may be OK to use the scaling in the original images for canny, but it's
best to stick to (0, 1). For details, see:

http://scikit-image.org/docs/dev/user_guide/data_types.html


The easiest way to handle rescaling to the correct float range is using
rescale_intensity:


>>> from skimage import exposure
>>> exposure.rescale_intensity(hot)

By default, this takes the minimum and maximum values in the image
(-6548.7, 4123.2) and rescales the image such that those values map to the
data types' min/max values; (0, 1) or (-1, 1) for float images (depends on
whether the input has negative values). Since your image has negative
values, the rescaled result will be (-1, 1).

Usually it's preferable to stick to (0, 1), so you might want to force the
output range:


>>> exposure.rescale_intensity(hot, out_range=(0, 1))

Note that most of your data are the middle ranges. If you plot the image,
it'll just appear gray. To fix that, you may want to clip the input range:

>>> exposure.rescale_intensity(hot, in_range=(-100, 100), out_range=(0, 1))

Now everything at or below -100 in the original gets mapped to 0;
everything at or above 100 gets mapped to 1; and everything in between -100
and 100 is linearly rescaled between 0 and 1.

Hope that helps!
-Tony
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/scikit-image/attachments/20130626/885939f8/attachment.html>


More information about the scikit-image mailing list