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

来源:互联网 发布:80端口攻击工具 编辑:程序博客网 时间:2024/05/16 05:07

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

function [ linePixel, direction] = z_lineCenterPts(im, sigma)%%if nargin <2     sigma = 1.5;end% derivative maskss_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 derivativesDx = conv2(im, dx, 'same');Dy = conv2(im, dy, 'same');% sum of the Auto-correlation matrixs_I = sigma;g = fspecial('gaussian',max(1,fix(6*s_I+1)), s_I);Dxx = conv2(Dx.^2, g, 'same'); % Smoothed squared image derivativesDyy = 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;endimg = img/255;%[ linePixel, direction] = z_detectLineSeg(img);[ linePixel, direction] = z_lineCenterPts(img);figure(1), imshow(rawImg);hold onplot(linePixel(:,2), linePixel(:,1), 'g.');hold off;


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

求大神帮助,感激不尽!

0 0
原创粉丝点击