function m = maskcircle2(I,type) % auto pick a circular mask for image I % built-in mask creation function % Input: I : input image % type: mask shape keywords % Output: m : mask image % Copyright (c) 2009, % Yue Wu @ ECE Department, Tufts University % All Rights Reserved if size(I,3)~=3 temp = double(I(:,:,1)); else temp = double(rgb2gray(I)); end h = [0 1 0; 1 -4 1; 0 1 0]; T = conv2(temp,h); T(1,:) = 0; T(end,:) = 0; T(:,1) = 0; T(:,end) = 0; thre = max(max(abs(T)))*.5; idx = find(abs(T) > thre); [cx,cy] = ind2sub(size(T),idx); cx = round(mean(cx)); cy = round(mean(cy)); [x,y] = meshgrid(1:min(size(temp,1),size(temp,2))); m = zeros(size(temp)); [p,q] = size(temp); switch lower (type) case 'small' r = 10; n = zeros(size(x)); n((x-cx).^2+(y-cy).^2