just curious if anyone knows of a tool that deblurs in a single dimension? AFNI has 3dSharpen and it works but in all 3 dims at once. i have data that’s anisotropically smooth, so i’d like to deblur only in the slice direction, for example. thanks!

One option is `scipy`

’s `gaussian_filter()`

, along with `nibabel`

.

Using the anatomical image from this nibabel demo, something like the following could work

```
from scipy.ndimage import gaussian_filter
import numpy as np
from scipy import datasets
import matplotlib.pyplot as plt
import nibabel as nb
fig = plt.figure()
plt.gray() # show the filtered result in grayscale
ax1 = fig.add_subplot(131)
ax2 = fig.add_subplot(132)
ax3 = fig.add_subplot(133)
anat_img = nb.load("someones_anatomy.nii.gz")
img_data = anat_img.get_fdata()
sigma = 2 # note that their sigma is not, e.g., fwhm
blur3d = gaussian_filter(img_data, sigma=sigma)
blur2d = gaussian_filter(img_data, sigma=sigma, axes=(0, 1)) # excludes z-axis
x = 28 # sagittal slice to show
ax1.imshow(img_data[x, :, :])
ax2.imshow(blur3d[x, :, :])
ax3.imshow(blur2d[x, :, :])
plt.show()
```

hi @psadil !

really appreciate the fast response. but this *blurs* in various dimensions, right?

i need *deblurring* (sharpening) in a single dimension.

i see some scipy and pylops stuff out there so maybe i’ll try to roll my own with neuroimaging data.

thanks again

-Sam

Oh! So sorry for misreading. Please do post what you come up with. FWIW, I suppose this approach could work

```
# [...] as above
blur2d = gaussian_filter(img_data, sigma=.5, axes=(0, 1))
filter_blurred_f = gaussian_filter(blur2d, 0.4, axes = (0, 1))
sharpened = blur2d + 10 * (blur2d - filter_blurred_f)
# sigmas and amount (10) were pulled out of a hat
z = 28
ax1.imshow(img_data[:, :, z])
ax2.imshow(filter_blurred_f[:, :, z])
ax3.imshow(sharpened[:, :, z])
plt.show()
```

Ciao, Sam-

If you are looking at structural data, I would note that AFNI’s 3danisosmooth has a `-2D`

option for within-slice anisotropic smoothing:

```
-2D = smooth a slice at a time (default)
```

This is primarily smoothing *within* similar contrast while also accentuating boundaries.

–pt