[SciPy-user] PIL and gaussian_filter?
Wed May 21 15:41:45 CDT 2008
Thanks a lot, it works like a charm.
Does anyone know of an efficient way of implementing a threshold
filter, i.e. where the resulting value is either the difference
between the current value and the threshold (if the value is above the
threshold) or otherwise 0?
On Wed, May 21, 2008 at 4:26 PM, Zachary Pincus <email@example.com> wrote:
>> When I use the asarray() method on my PIL image I get a 3-dimensional
>> array, shape is (w, h, 3 [rgb-values]).
>> I am wondering how I can transform this to something that is
>> compatible with f.e. ndimage.gaussian_filter? (When I run it directly
>> it simply removes color from the image).
> ndimage works as the name implies: it is a library for dealing with n-
> dimensional images. So in this case, it treated your input as a [w,h,
> 3] array of voxels (a 3D image), and then applied the gaussian
> smoothing of the requested variance across all three dimensions. The
> result of which was probably (a) some degree of smoothing in the x and
> y dimensions (as requested), and (b) the same degree of smoothing
> across the "z" (color channel) dimension, which (as it is only "3
> voxels high" translates into quite a bit of mixing of the pixels).
> This "z smoothing" of course translates into mixing the color
> channels, probably by quite a large degree if your gaussian variance
> was anything above one pixel. Which would give the effect of "removing
> the color" from the image.
> So, you need to apply the gaussian filter to each channel
> independently. You could either do this with a for loop, or even
> easier, pass a tuple to the sigma parameter to describe the requested
> variance in each dimension. To smooth by a 2-pixel stdev gaussian in
> w, a 4-pixel gaussian in h, and to do no smoothing across color
> channels, just pass 'sigma=[2,4,0]' to gaussian_filter.
> SciPy-user mailing list
More information about the SciPy-user