I have simple example that is not working as expected
import numpy as np
from PIL import Image
from scipy import ndimage
def gaussian_smoothing(image, sigma = 1):
im = np.array(image)
sim = ndimage.gaussian_filter(im, sigma=sigma)
print(im.shape)
return Image.fromarray(sim)
def main():
im = Image.open("./data/kodim03.png")
filtered_image = gaussian_smoothing(im, 1)
filtered_image.show()
Input Image:
The shape of the image is (512, 768, 3)
.
Output Image:
The image is greyed out. That is not what I was expecting.
Ive done some digging but I am still confused. From the scipy.ndimage.gaussian_filter doc page:
sigma: scalar or sequence of scalars
Standard deviation for Gaussian kernel. The standard deviations of the Gaussian filter are given for each axis as a sequence, or as a single number, in which case it is equal for all axes.
When I change my code and replace the line sim = ndimage.gaussian_filter(im, sigma=sigma)
with sim = ndimage.gaussian_filter(im, sigma=(sigma, sigma, 0))
I get expected result.
Expected output:
I don't understand the concept of the axes. I think the first two axes are X direction and Y direction. But is third axis a color?
My experience with convolutions and filters is very limited but I always thought about it as a simple box moving across the image and applying Gaussian soothing. Since we have three channels here, RGB, I would imagine the process will be repeated across all 3 channels and some sort of averaging will happen.
Can someone explain to me what is the idea about going in X, Y and color direction and how does it work.