function polarImg = lpImgTrans(img,xo,yo,smpl_size,scaleFac)
%Function to apply the log polar sampling to an image
%Inputs:
%img: the image to be sampled
%xo,yo: the centre point for sampling
%smpl_size: the number of samples to create in each circle, actual number
%of samples is smpl_size^2
%Scale factor: a factor to scale the image down by



%low pass filter the image
img = medfilt2(rgb2gray(img),[5 5]);
%get height and width
[height width] = size(img);

x = xo * scaleFac;
y = yo * scaleFac;

phi = (1 + sqrt(5)) /2;
r = 20;

%Intialise result image
polarImg = uint8(zeros(smpl_size,smpl_size));

for i=1:smpl_size,
    for j = 1:smpl_size,
        %Convert polar coordinates into cartesian
        [xp,yp] = pol2cart(-j*2*pi/(smpl_size),i^1.6);
        %        [xp,yp] = pol2cart(-j*2*pi/(smpl_size),i^1.85 +10);
        %        [xp,yp] = pol2cart(-j*2*pi/(smpl_size),(1.4^i));
        %        [xp,yp] = pol2cart(-j*2*pi/(smpl_size),(phi)^(i/1.55));
        polarImg(j,i) = img(j,i);
        if (y+yp > 1) & (x+xp > 1) & (y+yp < height) & (x+xp < width),
            polarImg(j,i) = img(round(y+yp),round(x+xp));
        else
            %sampling is outside the image so insert random points.
            polarImg(j,i) = round(rand() * 200);
        end

    end
end


%If an image of the sampling function applied to the original is required 
%uncomment the following lines and comment the ones above
% polarImg = img;
%
% for i=1:smpl_size,
%     for j = 1:smpl_size,
%         [xp,yp] = pol2cart(-j*2*pi/(smpl_size),1.3^i);
%         polarImg(round(y+yp),round(x+xp)) = 255;
%     end
%     r = (phi)^(i/1.55);
% end


