Fast Radial Symmetry Transform/快速径向对称变换(代码)

<span style="font-size:18px;">function [ filtered ] = frst2d( image, radii, alpha, stdFactor, mode )
%FRST2D Applies Fast radial symmetry transform to image
%   Check paper Loy, G., & Zelinsky, A. (2002). A fast radial symmetry transform for detecting points of interest. Computer Vision?ECCV 2002.
%   Three different modes are available: 'bright', 'dark', 'both'

% Example:
% I = imread('iris.jpg');
% Id = rgb2gray(I);
% IdSmall = imresize(Id, 0.25);
% 
% f = frst2d(IdSmall, 13, 2, 0.1, 'dark');
% 
% subplot(2,1,1);
% imshow(IdSmall, []);
% subplot(2,1,2);
% imshow(f,[]);

bright = false;
dark = false;
if (strcmp(mode, 'bright'))
    bright = true;     %寻找亮区域的对称
elseif (strcmp(mode, 'dark'))
    dark = true;
elseif (strcmp(mode, 'both'))
    bright = true;                   %寻找暗区域的对称
    dark = true;
else
    error('invalid mode');
end                         %寻找亮和暗区域的对称

original = double(image);

[gy, gx] = gradient(original);

maxRadius = ceil(max(radii(:)));
offset = [maxRadius maxRadius];

filtered = zeros(size(original) + 2*offset);%拓展的图像


S = zeros([numel(radii), size(filtered, 1), size(filtered, 2)]);%用于存储N个半径的变换值

radiusIndex = 1;
for n = radii
    
    O_n = zeros(size(filtered));
    M_n = zeros(size(filtered));
    
    for i = 1:size(original, 1)
        for j=1:size(original, 2)
            p = [i j];%图像点的位置
            g = [gx(i,j) gy(i,j)];%图像该点的x和y方向上的梯度方向
            gnorm = sqrt( g * g' ) ;%图像该点的梯度幅度值
            if (gnorm > 0)%如果该点幅度大于0
                gp = round((g./gnorm) * n);%沿着梯度方向长度为半径n的坐标偏差
                
                if (bright)                 %寻找亮区域的对称
                    ppve = p + gp;
                    ppve = ppve + offset;
                    
                    O_n(ppve(1), ppve(2)) = O_n(ppve(1), ppve(2)) + 1;
                    M_n(ppve(1), ppve(2)) = M_n(ppve(1), ppve(2)) + gnorm;
                end
                
                if (dark)                     %寻找暗区域的对称
                    pnve = p - gp;
                    pnve = pnve + offset;
                    
                    O_n(pnve(1), pnve(2)) = O_n(pnve(1), pnve(2)) - 1;
                    M_n(pnve(1), pnve(2)) = M_n(pnve(1), pnve(2)) - gnorm;
                end
            end
            
        end
    end
    
    O_n = abs(O_n);
    O_n = O_n ./ max(O_n(:));
    
    M_n = abs(M_n);
    M_n = M_n ./ max(M_n(:));
    
    
    S_n = (O_n.^alpha) .* M_n;  %就是论文里 的Fn
    
    gaussian = fspecial('gaussian', [ceil(n/2) ceil(n/2)], n*stdFactor);
    S(radiusIndex, :, :) = imfilter(S_n, gaussian); %进行高斯处理  加快处理速度
    
    radiusIndex = radiusIndex + 1;
end

filtered = squeeze(sum(S, 1));
filtered = filtered(offset(1)+1:end-offset(2), offset(1)+1:end-offset(2));

end
</span>
<span style="font-size:18px;">
</span>
<span style="font-size:18px;">
</span>


代码下载地址:

http://download.csdn.net/detail/qq_18343569/9086641

你可能感兴趣的:(Fast Radial Symmetry Transform/快速径向对称变换(代码))