Which approach for finding the DoG of the Image is convenient?

clear;clc;close all;
image = imread('Circle.tif');
image = im2double(image(:,:,1));
Method 1
tic;
H1 = fspecial('gaussian',21,15);
H2 = fspecial('gaussian',21,20);
dog = H1 - H2;
dogFilterImage1 = conv2(image,dog,'same');
toc
figure,imshow(dogFilterImage1,[]);
%Method 2
tic;
h1 = fspecial('gaussian',21,15);
dog1 = conv2(image,h1,'same');
h2 = fspecial('gaussian',21,20);
dog2 = conv2(image,h2,'same');
dogFilterImage2 = dog2 - dog1;
toc
figure,imshow(dogFilterImage2,[]);
%Method 3
tic;
G1 = fspecial('gaussian',[1 21],15);
DoG1 = conv2(image,G1,'same');
DoG1 = conv2(DoG1,G1','same'); %h1' previously
G2 = fspecial('gaussian',[1 21],20);
DoG2 = conv2(image,G2,'same');
DoG2 = conv2(DoG2,G2','same'); % h1' previously
dogFilterImage3 = DoG2 - DoG1;
figure,imshow(dogFilterImage3,[]);
toc
output:
Elapsed time is 0.058436 seconds.
Elapsed time is 0.116693 seconds.
Elapsed time is 0.554481 seconds.
Method:1
Method 2:
Method 3:
Here, I wrote 3 different approach for finding the Difference of Gaussian(DoG). Three figures are the results of these 3 methods. Does any of the approach make any difference on the overall performance? Which method is efficient in terms of speed and performance simultaneously?
It seems that 1st method of creating DoG image is much more efficient in terms of both speed and performance, but when it comes to create DoG images in SCALE SPACE EXTREMA DETECTION(SIFT), I am confused among 3.
As suggested in this code, it uses 3rd approach. But as shown here in figure 3, I am quite hesitant to use this.

2 comentarios

image is a built-in function. You should not use it as the name for your variable.
I know.I would take care of this thing. Thanks for letting me know.

Iniciar sesión para comentar.

 Respuesta aceptada

Image Analyst
Image Analyst el 14 de Mzo. de 2016
Well of course method 1 is best. Subtract the kernels to get a new kernel and then you have to call conv2() only once instead of twice (like in method 2). Method 3 is totally ridiculous. It's not even equivalent. You're convolving with a 1-D row vector, and then assuming that you can convolve with a 1-D column vector because the kernel is separable. However you don't do that, you convolve it with a 2D array instead, so it's not the same. Even if you did it right, it's doubtful it would be faster. 2-D convolution has very well known methods for speeding it up, and I'm very confident that those well known methods have been implemented into conv2() so there is no need to try to do it yourself by separating your kernel.
The times you have also suggest the first method is the fastest which is what you'd expect.

7 comentarios

Jay
Jay el 14 de Mzo. de 2016
Editada: Jay el 14 de Mzo. de 2016
I made a mistake actually in method 3. Its subsequently convolving by G1/G1'(mistake is h1') and G2/G2'(mistake is h1'). After that the results are identical for method 2 and 3. And time for computation is 0.65 seconds for method 3.
While getting Scale Space Maxima, instead of using 2nd method, can I use first method? If yes, how?
Yes, you can use the first method. Just subtract the kernels and use conv2 like you're doing.
Ideally the kernel size(n*n) should be (6*standard deviation+ 1). While computing scale space maxima, to find DoG image from two sigma levels, you will have to take the kernels having different sizes.
1.n = (6*sigma_1+ 1) for 1st level.
2.n = (6*sigma_2+ 1) for 2nd level.
now, if I use 1st method of finding the DoG, I will have to subtract two different size of kernels, which is obviously not possible. So, I will have to resize any one kernel.
While doing this, is there any performance issue I will face? What is the role sigma and size of the kernel relation play as far as performance is concerned?
JAY, fspecial() lets you specify the window size and the sigma within that window independently. Just have the window size be the same for the two calls
windowSize = round(6 * max([sigma_1, sigma_2]) + 1);
g1 = fspecial('gaussian', windowSize, sigma_1);
g2 = fspecial('gaussian', windowSize, sigma_2);
dogKernel = g1 - g2;
Thank you :) !!
1.n = (6*sigma_1+ 1) for 1st level.
2.n = (6*sigma_2+ 1) for 2nd level.
as mentioned here that the value of n are different and impossible to subtract them for DoG filter.
So, how do we choose an appropriate size for any two sigmas given?
Because randomly assissgning a value between 'n' for first level and second level dont sound right.
"as mentioned here" -- as mentioned where???
What is the purpose of your n variable?
And who says that you can't subtract two matrices of the same size (rows and columns) containing Gaussians with different sigmas? Why do you say it's impossible???
The way I determine the best two sigmas is to have a double for loop where I try them all. Then look at the resulting images and determine which one you think works best. It's pretty much a subjective call.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Convert Image Type en Centro de ayuda y File Exchange.

Preguntada:

Jay
el 14 de Mzo. de 2016

Comentada:

el 29 de Oct. de 2019

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by