gpt4 book ai didi

matlab - 识别所有共线线段(在 matlab 中)

转载 作者:太空宇宙 更新时间:2023-11-03 19:24:45 25 4
gpt4 key购买 nike

我在这里发布了一个相关但不相同的问题 https://stackoverflow.com/questions/8279698/measuring-length-of-dna-fibers-from-an-image-of-single-molecules

背景:我有很多像这样的图像: enter image description here

我想确定所有共线的线段,然后测量这些线段的长度。在上图中,有 3 对线段位于一条具有负斜率的假想线上。最长的线段没有一对,因此不会被考虑,即必须至少有 2 条线段是共线的。

我得到以下信息: enter image description here

I  = imread('http://dl.dropbox.com/u/18072545/c_39_green.tif'); 
BW = edge(I,'canny');
[H,T,R] = hough(BW);
NUMPEAKS=15;
PEAKTHRESHOLD= 80;
SUPPRESSNHBR=[40 40];
P = houghpeaks(H,NUMPEAKS,'threshold',PEAKTHRESHOLD,'NHoodSize',SUPPRESSNHBR);
MINLENGTH_OF_SEGMENT=50;
GAPLENGTH_TO_MERGE=30;
lines = houghlines(BW,T,R,P,'FillGap',GAPLENGTH_TO_MERGE,'MinLength',MINLENGTH_OF_SEGMENT);
max_len = 0;
figure, imshow(I), hold on
for k = 1:length(lines)
xy = [lines(k).point1; lines(k).point2];
plot(xy(:,1),xy(:,2),'LineWidth',2,'Color','green');
plot(xy(1,1),xy(1,2),'x','LineWidth',2,'Color','yellow');
plot(xy(2,1),xy(2,2),'x','LineWidth',2,'Color','red');
end

为了获得合理的性能,我不得不尝试使用参数(尽管我无法找到一个参数来捕获底部段的起始位)。但是,我无法避免找到多个重叠的片段。

谁能帮帮我1.防止识别重叠段。2. 识别所有共线的线

非常感谢!

最佳答案

此代码查找共线的线组。

enter image description here

theta = zeros(length(lines),1);
rho = zeros(length(lines),1);
for k = 1:length(lines)
xy = [lines(k).point1; lines(k).point2];
plot(xy(:,1),xy(:,2),'LineWidth',1,'Color','green');
plot(xy(1,1),xy(1,2),'x','LineWidth',1,'Color','yellow');
plot(xy(2,1),xy(2,2),'x','LineWidth',1,'Color','red');
%text(xy(1,1),xy(1,2),[' ' num2str(k)],'fontsize',10,'color',[1 1 1]);
theta(k) = lines(k).theta;
rho(k) = lines(k).rho;
end

theta_tolerance = 2;
theta2 = abs(bsxfun(@minus, theta, theta')) <= theta_tolerance;
theta2(1:size(theta2,2)+1:numel(theta2)) = 0; % zero diagonal
rho_tolerance = 1;
rho2 = abs(bsxfun(@minus, rho, rho')) <= rho_tolerance;
rho2(1:size(rho2,2)+1:numel(rho2)) = 0; % zero diagonal
rhotheta2 = sparse(rho2 & theta2);
[nc, C] = graphconncomp(rhotheta2);


paired = ismember(C,find(hist(C,1:max(C))>1)); % paired lines
colors=get(gcf,'DefaultAxesColorOrder');
for line=find(paired)
xy = [lines(line).point1; lines(line).point2];
plot(xy(:,1),xy(:,2),':','LineWidth',4,'Color',colors(C(line),:));
text(xy(1,1),xy(1,2),num2str(C(line)),'fontsize',20,'Color',colors(C(line),:));
end

它不处理重叠。目前尚不清楚如何处理具有 3 个共线段的情况,其中第一个段和第二个段相交?是否需要同时考虑包含第一段和第三段的集合以及包含第二段和第三段的集合?

关于matlab - 识别所有共线线段(在 matlab 中),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8334636/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com