0
votes

I am trying to learn how to find if images are in focus and remove them from a list of images. The images are in very high resolution (jp2) and I am trying to use a code that I found in the MATLAB website http://www.mathworks.com/matlabcentral/fileexchange/27314-focus-measure/content/fmeasure/fmeasure.m I am trying to use the following function

WSize = 15; % Size of local window (only some operators)

case 'SFIL' %Steerable filters (Minhas2009)
% Angles = [0 45 90 135 180 225 270 315];
N = floor(WSize/2);
sig = N/2.5;
[x,y] = meshgrid(-N:N, -N:N);
G = exp(-(x.^2+y.^2)/(2*sig^2))/(2*pi*sig);
Gx = -x.*G/(sig^2);Gx = Gx/sum(Gx(:));
Gy = -y.*G/(sig^2);Gy = Gy/sum(Gy(:));
R(:,:,1) = imfilter(double(Image), Gx, 'conv', 'replicate');
R(:,:,2) = imfilter(double(Image), Gy, 'conv', 'replicate');
R(:,:,3) = cosd(45)*R(:,:,1)+sind(45)*R(:,:,2);
R(:,:,4) = cosd(135)*R(:,:,1)+sind(135)*R(:,:,2);
R(:,:,5) = cosd(180)*R(:,:,1)+sind(180)*R(:,:,2);
R(:,:,6) = cosd(225)*R(:,:,1)+sind(225)*R(:,:,2);
R(:,:,7) = cosd(270)*R(:,:,1)+sind(270)*R(:,:,2);
R(:,:,8) = cosd(315)*R(:,:,1)+sind(315)*R(:,:,2);
FM = max(R,[],3);
FM = mean2(FM);

What I do not understand is how was the WSize=15 determined, does this have to do with the data or it is just about the window size in MATLAB? Also I do not understand how these two lines were determined

N = floor(WSize/2);
sig = N/2.5;

Is the 2.5 a standard deviation or some value determined from the data? I understand that this is not exactly a MATLAB question but more a focus measure question but I was hoping someone has used this code and can help me decipher how WSize,N and sig values were determined.Also if anyone can suggest a better way to find the focus of an image, I would appreciate it too.

Thank you in advance.

1

1 Answers

0
votes

My understanding is that WSize was set arbitrarily. The size of the neighborhood should be adapted to the size and resolution of your image. The sig=2.5 results in a Normal distribution with a standard deviation of 2.5.

There is nothing in Matlab that forces these parameters. I read the article mentioned in the code (which requires subscription). It claims the they used a window size of 5x5 to obtain the results. It refers to a (IMO, much better) paper about steerable filters (freely available from the MIT).