user3025898
user3025898

Reputation: 571

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.

Upvotes: 3

Views: 5548

Answers (1)

Joe Kington
Joe Kington

Reputation: 284602

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)

Upvotes: 2

Related Questions