阅读背景:

MATLAB图像处理与计算机视觉(3):实现Carsten Steger 的曲线检测算法(1)

来源:互联网 

用MATLAB实现,结果第一步就不大对劲,是什么原因呢?

function [ linePixel, direction] = z_lineCenterPts(im, sigma)
%
%
if nargin <2 
    sigma = 1.5;
end

% derivative masks
s_D = 0.7*sigma;
x  = -round(3*s_D):round(3*s_D);
dx = x .* exp(-x.*x/(2*s_D*s_D)) ./ (s_D*s_D*s_D*sqrt(2*pi));
dy = dx';

% image derivatives
Dx = conv2(im, dx, 'same');
Dy = conv2(im, dy, 'same');

% sum of the Auto-correlation matrix
s_I = sigma;
g = fspecial('gaussian',max(1,fix(6*s_I+1)), s_I);
Dxx = conv2(Dx.^2, g, 'same'); % Smoothed squared image derivatives
Dyy = conv2(Dy.^2, g, 'same');
Dxy = conv2(Dx.*Dy, g, 'same');

[eigenvalue1, eigenvalue2, eigenvectorx, eigenvectory]=eig2image(Dxx, Dxy, Dyy);

%判断(px, py)是否在[-1/2,1/2]X[-1/2,1/2]范围内
t = (Dx.*eigenvectorx + Dy .* eigenvectory) ./...
    (Dxx .* eigenvectorx.^2 + 2*Dxy.*eigenvectorx.*eigenvectory + Dyy.*eigenvectory.^2 );

px = t.*eigenvectorx;
py = t.*eigenvectory;

[candidateX1, candidateY1] = find(px >= -0.5 & px <= 0.5 & py >= -0.5 & py <= 0.5);

linePixel = [candidateX1, candidateY1];

%所有像素的方向方向
direction(:,:, 1) = asin(eigenvectory);
direction(:,:, 2) = acos(eigenvectorx);

end
function [ lineP



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: