Question about Difference of Gaussian (DoG) algorithm
Difference of gaussian is the difference in the output of two Gaussian filters with different blur amounts (sigma).

Sigma is the size of the Gaussian filter. A bigger sigma gives you a bigger amount of blurring. A good way to think about it is a Gaussian filter with variance sigma is very roughly like averaging 3 x sigma samples wide (or 3 x 3 in an image)

e.g. from wikipedia:



Very Important when making a Gaussian filter in MATLAB make sure the size of the filter is at least 6 x sigma. In your above code you have 5 x 5 which is fine for sigma = 0.5, but for sigma = 1 you would want 6 x 6 or bigger.

The k is simply a multiplier for sigma.

e.g.

sigma = 0.5;
gauss1 = fspecial('gaussian', round([10*sigma 10*sigma]), sigma);
sigma = 1;
gauss2 = fspecial('gaussian', round([10*sigma 10*sigma]), sigma);
blur1 = imfilter(img, gauss1, 'replicate', 'same');
blur2 = imfilter(img, gauss2, 'replicate', 'same');
dog2 = blur1 - blur2;


A more complete code example that allows you to set the number of octaves and the steps per octave:

%% Filter using DoG
stepsPerOctave = 5;
octaves = 4;
mult = nthroot(2,stepsPerOctave);

% Create blurry images
sigma = 0.5;
kernelSize = [10*sigma*2^(octaves),10*sigma*2^(octaves)]
for k = 1:octaves*stepsPerOctave+1
    disp(['Sigma is ' num2str(sigma)]);
    gauss = fspecial('gaussian', kernelSize, sigma);
    blur(:,:,k) = imfilter(I, gauss, 'replicate', 'same');
    imagesc(blur(:,:,k)); colorbar; title(['Gaussian ' num2str(k)]); pause;
    sigma = sigma * mult;
end

% Create DoG
for k = 1:octaves*stepsPerOctave
    dog(:,:,k) = blur(:,:,k+1) - blur(:,:,k);
    imagesc(dog(:,:,k)); colorbar; title(['DoG ' num2str(k)]); pause;
end