function [x,y,v,rmax,tx,ty] = transform_to_unit_circle(img,center,radius,coef) [n1, n2] = size(img); tx = (n2+1)/2; ty = (n1+1)/2; m00 = sum(img(:)); if center == 2 w = 1:n2; v = 1:n1; if m00 ~= 0 tx = (sum(img*w'))/m00; ty = (sum(v*img))/m00; end end rmax = sqrt(max([(1-tx)^2+(1-ty)^2,(n2-tx)^2+(1-ty)^2,(n2-tx)^2+(n1-ty)^2,(1-tx)^2+(n1-ty)^2])); [y,x,v] = find(img); if isempty(v) return end x = x - tx; % moving the image to the center of image y = y - ty; if radius == 2 rmax = max((x.^2+y.^2).^0.5); % maximum of pixel distances from the center elseif radius == 3 mc = max(img(:)); rmax = sqrt(m00/mc)*sqrt(n2/n1+n1/n2)/sqrt(2); end rmax = rmax*coef; x = x/rmax; y = y/rmax; end