matlab 图形识别算法,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

然后写一个小的测试脚本:

clc;

clear all;

%rawImg = imread('D:\DataSet\Tub\Tub20010223ss09s08q1i013.z6.tif');

rawImg = imread('F:\DataSet\DRIVE\DRIVE\test\images\01_test.tif');

if length(size(rawImg)) == 3

img = double(rgb2gray(rawImg));

maskImg = imread('F:\DataSet\DRIVE\DRIVE\test\mask\01_test_mask.gif');

maskImg = im2bw(maskImg, 0.5);

img = maskImg .* img;

else

img(1024,:) = 0;

img = double(rawImg);

maskImg = imread('D:\DataSet\3DHela_Tub\Tub\cell13\crop\Tub20010223ss09s08q1i013.mask1.tif');

maskImg = im2bw(maskImg, 0.001);

img = maskImg .* img;

end

img = img/255;

%[ linePixel, direction] = z_detectLineSeg(img);

[ linePixel, direction] = z_lineCenterPts(img);

figure(1), imshow(rawImg);

hold on

plot(linePixel(:,2), linePixel(:,1), 'g.');

hold off;

得到的结果显示,这个结果让我要哭了:

0818b9ca8b590ca3270a3433284dd417.png

求大神帮助,感激不尽!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值