KernelFactors.gaussian


#1

I have a doubt.
In KernelFactors.gaussian I am trying to create a 1D gaussian kernel to convolve an image in vertical direction only, i.e. I need the kernel to be horizontal.
If I define the kernel as:

imfilter(img_area, KernelFactors.gaussian(5))

I think it is returning a 1D vertical kernel. If I do a transpose to convert to a row vector, will imfilter automatically do the convolution in the vertical direction?
Thanks!


#2

This is a pretty easy question to answer on your own:

img = zeros(5,5); img[3,3] = 1
kern = KernelFactors.gaussian(0.5)
imfilter(img, kern)
julia> imfilter(img, g)
ERROR: ArgumentError: ImageFiltering.Pad{1}(:replicate, (2,), (2,)) lacks the proper padding sizes for an array with 2 dimensions

…so no. If you want to convolve in one dimension only, construct a kernel with σ = 0 in the other dimension: kern2 = KernelFactors.gaussian((0, 0.5))

julia> imfilter(img, kern2)
5×5 Array{Float64,2}:
 0.0          0.0       0.0       0.0       0.0        
 0.0          0.0       0.0       0.0       0.0        
 0.000263865  0.106451  0.786571  0.106451  0.000263865
 0.0          0.0       0.0       0.0       0.0        
 0.0          0.0       0.0       0.0       0.0  

#3

@stillyslalom
Thanks a lot!