function [px, py] = ivote3(image, rmax, phi, iter, t0, sigma, t1) % This function performs iterative voting on an image in order to identify the centers of blobs % image = a matrix of values representing a 2D image % rmax = estimated radius of a blob % phi = angular range of the voting area (in radians) % iter = number of iterations for voting % sigma = standard deviation of the weighting filter used for voting % t0 = initial gradient magnitude threshold (limits the # of voting pixels) % t1 = final threshold for valid points dphi = phi / (iter); %compute the gradient and gradient magnitude [Igrad_x, Igrad_y] = gradient(image); Igrad_mag = sqrt(Igrad_x.^2 + Igrad_y.^2); %represent the gradient direction in polar coordinates Igrad_theta = atan2(Igrad_x,Igrad_y) + pi; %compute pixels that will be processed % calculate a mask representing the voting pixels S = Igrad_mag > t0; Sx = size(S, 1); Sy = size(S, 2); S(1:rmax, :) = 0; S(Sx - rmax:Sx, :) = 0; S(:, 1:rmax) = 0; S(:, Sy - rmax:Sy) = 0; %calculate the coordinates of all of the voting pixels [sx, sy] = find(S); %this provides a coordinate for each voter %eliminate pixels close to the image boundary nV = nnz(S); %calculate the number of valid pixels (voters) % create a meshgrid describing coordinates relative to the voter % position range = -rmax:rmax; [Vx, Vy] = meshgrid(range, range); %create a mask for the voting area M_dist = Vx.^2 + Vy.^2 < rmax^2; M_theta = atan2(Vx, Vy); pxPerRow = size(image,1); g_v_prime = zeros(nV, ceil(rmax^2*phi/3)); validPoints = zeros(nV,1); for i = 1: iter t_iter = tic; %set the vote image to zeros Ivote = zeros(size(image)); for v = 1:nV %determine the position of the current voter vx = sx(v); vy = sy(v); %determine the orientation (theta) of the current voter vtheta = Igrad_theta(vx, vy); % find the angular distance between M_theta and V_theta at each ang_diff = abs(M_theta - vtheta); M_diff = min(2*pi - ang_diff,ang_diff)