I am trying to do some image processing and I would like to apply the LoG kernel. I know the formula, which is :
But I didn't understand how to obtain the kernel matrix with this formula. From what I have read, I have a matrix of n x n and I apply this formula to every cell in that matrix, but what should be the starting values within that matrix in the first place.
Also, I have the same question with th开发者_StackOverflowe Laplacian filer. I know the formula, which is:
and also, from what I have read, the 3 x 3 filter should be the matrix:
x = [1 1 1; 1 -4 1; 1 1 1]
but can you please tell me how to apply the formula in order to obtain the matrix, or at least indicate me a tutorial of how to apply this.
Basically, we are just going from continuous space to discrete space. The first derivative in continuous time (space) is analogous to the first difference in discrete time (space). To compute the first difference of a discrete-time signal, you convolve [1 -1]
over the signal. To compute the second difference, you convolve a signal with [1 -2 1]
(which is [1 -1]
convolved with itself, or equivalently, convolving the signal with [1 -1]
twice).
To calculate the second difference in two dimensions, you convolve the input image with the matrix you mentioned in your question. That means that you take the 3-by-3 mask (i.e, the matrix you mentioned), multiply all nine numbers with nine pixels in the image, and sum the products to get one output pixel. Then you shift the mask to the right, and do it again. Each shift will produce one output pixel. You do that across the entire image.
To get the mask for a Gaussian filter, just sample the two-dimensional Gaussian function for any arbitrary sigma.
This may help: convolution matrix, Gaussian filter
精彩评论