Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

apply gaussian blur to an image ussing python

I am trying to replicate the following smoothing of an image using a Gaussian filter (images from a journal): enter image description here

In the paper says that in order to get from the left image to the right image I have to apply a gaussian fiter with values x,y = 1,...,100 and sigma = 14 to obtain the "best resuts"

I have developed the following program in python to try to achieve this smoothing:

import scipy.ndimage as ndimage
import matplotlib.pyplot as plt

img = ndimage.imread('left2.png')
img = ndimage.gaussian_filter(img, sigma=(14), order=0)
plt.imshow(img)
plt.show()

for some reason the result obtained is not similar to the picture in the right. Can someone please point out what do I have to modify in the program to get from the left image to the right image?

Thank you.

like image 704
user3025898 Avatar asked Jan 01 '26 04:01

user3025898


1 Answers

I'm going to take a guess here:

Because they mention that their x and y values range from 0-100, they're probably applying a "sigma = 14 unit blur" instead of a "sigma = 14 pixel blur".

The sigma parameter in scipy.ndimage.gaussian_filter is in pixel units. If I'm correct about the author's intent, you'll need to scale the sigma parameter you pass in.

If the authors specified that both x and y ranged from 0-100, the sigma in the x and y directions will be different, as your input data appears have a different number of rows than columns (i.e. it isn't a perfectly square image).

Perhaps try something similar to this?

nrows, ncols = img.shape
sigma = (14 * nrows / 100.0, 14 * ncols / 100.0)
img = ndimage.gaussian_filter(img, sigma=sigma)
like image 162
Joe Kington Avatar answered Jan 03 '26 17:01

Joe Kington



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!