function [I,imcenter]=circmask(I1,circsize)

% function [I,imcenter]=circmask(I1,circsize)
% applies circular mask of diameter "circsize" to image I1 and returns
% image I and image center coordinates imcenter
% implemented by Lucas Pinto

if size(I1,3)==3
    I1=double(rgb2gray(I1));
else I1=double(I1);
end

I=zeros(size(I1));
imcenter=[size(I1,1)/2 size(I1,2)/2];

for i=1:size(I1,1)
    for j=1:size(I1,2)
        if sqrt((i-imcenter(1,1))^2+(j-imcenter(1,2))^2)>(circsize/2)
            I(i,j)=0;
        else I(i,j)=I1(i,j);
        end
    end
end

figure;
imshow(uint8(I));