0

Let's say I have an image as the following 2D arrays:

img = np.array([
           [0, 0, 0, 1, 0, 0, 0, 0, 0.5, 0, 0, 0, 0],
           [0, 0, 0, 1, 0, 0, 0, 0, 0.5, 0, 0, 0, 0],
           [0, 0, 0, 1, 0, 0, 0, 0, 0.5, 0, 0, 0, 0],
           [0, 0, 0, 1, 0, 0, 0, 0, 0.5, 0, 0, 0, 0],
           [0, 0, 0, 1, 0, 0, 0, 0, 0.5, 0, 0, 0, 0],
           [0, 0, 0, 1, 0, 0, 0, 0, 0.5, 0, 0, 0, 0],
           [0, 0, 0, 1, 0, 0, 0, 0, 0.5, 0, 0, 0, 0],
           [0, 0, 0, 1, 0, 0, 0, 0, 0.5, 0, 0, 0, 0]])

I would like to apply a gaussian blur on it so the image would be as following :

imgBlurred = np.array([
           [0.0, 0.2, 0.7, 1, 0.7, 0.2, 0.3, 0.4, 0.5, 0.4, 0.3, 0.2, 0.1],
           [0.0, 0.2, 0.7, 1, 0.7, 0.2, 0.3, 0.4, 0.5, 0.4, 0.3, 0.2, 0.1],
           [0.0, 0.2, 0.7, 1, 0.7, 0.2, 0.3, 0.4, 0.5, 0.4, 0.3, 0.2, 0.1],
           [0.0, 0.2, 0.7, 1, 0.7, 0.2, 0.3, 0.4, 0.5, 0.4, 0.3, 0.2, 0.1],
           [0.0, 0.2, 0.7, 1, 0.7, 0.2, 0.3, 0.4, 0.5, 0.4, 0.3, 0.2, 0.1],
           [0.0, 0.2, 0.7, 1, 0.7, 0.2, 0.3, 0.4, 0.5, 0.4, 0.3, 0.2, 0.1],
           [0.0, 0.2, 0.7, 1, 0.7, 0.2, 0.3, 0.4, 0.5, 0.4, 0.3, 0.2, 0.1],
           [0.0, 0.2, 0.7, 1, 0.7, 0.2, 0.3, 0.4, 0.5, 0.4, 0.3, 0.2, 0.1]])

Basically, I would like a result where the gaussian is very thick for the ones values and larger for the 0.5 values in the original image.

Until now, I proceed as following:

 from scipy import ndimage
 import numpy as np
 #img is a numpy array
 imgBlurred = ndimage.filters.gaussian_filter(img, sigma=0.7)
 #Normalisation by maximal value, because the gaussian blur reduce the 1 to ~0.5
 imgBlurred = imgBlurred/imgBlurred.max()
 imgBlurred[imgBlurred > 1] = 1# In case of the maximal value was > 1

But doing this let the same larger for the ones and 0.5 on the blurred image. If someone know how to fix this "issue" I would like to have some advices !

Lionel
  • 331
  • 1
  • 2
  • 14
  • 1
    What do you mean by larger and thicker Gaussian? Do you want different sigmas depending on the value of each pixel? – Diego Palacios Dec 05 '19 at 15:01
  • Yes it can be the sigma, but here, the pixels are already defined and I was looking if it was possible to use a Gaussian filter over my image and get « flatten » distribution for px = 0.5. Is it possible with a same sigma ? – Lionel Dec 05 '19 at 16:02
  • Will the pixels always have this pattern, i.e. in columns? then you can use a 1d kernel. – Diego Palacios Dec 05 '19 at 16:13
  • no, this is just for the example, they can be oriented with different angles – Lionel Dec 19 '19 at 13:17

0 Answers0