Re: Using ndimage.gaussian_filter for 3d array
"ashwin .D" <[email protected]> Tue, 26 Oct 2021 16:31:07 +0530
| Newsgroups | gmane.comp.python.scientific.user |
|---|---|
| Message-ID | <CAH0LXy7mmj_w7TQR9YodpeT7b2JiqEBkFBfOM3PzvSXdOzNcXg@mail.gmail.com> |
Hello Juan,
Thanks for your prompt response. You are right - I
only want to smooth along 2d slices along the first axis.
args = []
#abc shape is (10,100,100)
for abc2d in abc:
ndimage.gaussian_filter(abc2d*1e2,sigma=2,output=abc2d,order=0)
b = abc2d[newaxis,:,:]
args.append(b)
smoothedABC = np.concatenate(args,axis=0)
Is this the best vectorized approach that I can take forward ?
On Tue, Oct 26, 2021 at 3:43 PM Juan Nunez-Iglesias <[email protected]>
wrote:
> A 3D gaussian filter is smoothing across all axes, so in abc[k, :, :] you
> are getting some of abc[k-1, :, :] and abc[k+1, :, :], and so on, according
> to the kernel weights in 3D. To smooth in 2D across all slices of a 3D
> array, specify a different sigma per axis, like so:
>
> abc = ndimage.gaussian_filter(abc * 1e2, sigma=(0, 2, 2), output=abc,
> order=0)
>
> Note that you don't need the [:, :, :]: using output=array is how to
> ensure that the array is modified in-place (if you are trying to avoid an
> extra allocation).
>
> Juan.
>
> On Tue, 26 Oct 2021, at 4:59 AM, ashwin .D wrote:
>
> Hello,
> I am wanting to use ndimage.gaussian_filter for a 3d array in
> order to smooth the data .
>
> When I do this -
>
> abc[:,:,:] = ndimage.gaussian_filter(abc[:,:,:]*1e2,sigma=2,order=0) I get
> unreal values.
>
> However the function call when done within a loop like this
>
> for k in range(0,N):
> abc[k,:,:] = ndimage.gaussian_filter(abc[k,:,:]*1e2,sigma=2,order=0)
> gives reasonable smoothed values.
>
> From the docs -
> https://docs.scipy.org/doc/scipy/reference/generated/scipy.ndimage.gaussian_filter.html
>
> the input array does not seem to have any restriction on the
> dimensionality . So where am I going wrong ?
>
> Best regards,
> Ashwin.
>
> _______________________________________________
> SciPy-User mailing list -- [email protected]
> To unsubscribe send an email to [email protected]
> https://mail.python.org/mailman3/lists/scipy-user.python.org/
> Member address: [email protected]
>
>
> _______________________________________________
> SciPy-User mailing list -- [email protected]
> To unsubscribe send an email to [email protected]
> https://mail.python.org/mailman3/lists/scipy-user.python.org/
> Member address: [email protected]
>
_______________________________________________
SciPy-User mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/scipy-user.python.org/
Member address: [email protected]