耳朵图像处理 - 在MATLAB中查找线和曲线的交点 [英] Ear Image Processing - Finding the point of intersection of line and curve in MATLAB

查看:520
本文介绍了耳朵图像处理 - 在MATLAB中查找线和曲线的交点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

1 我有耳朵的Canny边缘输出... i将最远的两个边界与一条线(绿色)连接起来。现在我想从该线的中点到外边界(左侧)绘制法线。
我写的代码帮助我绘制法线,但我希望红线完全符合白色边界。此外,我想要在它遇到的点处的交点。我也考虑过另一种相同的方法。通过改变50到60个像素(在代码中),红线穿过白色边界。如果我得到相同的交点,那么我可以很容易地绘制所需长度的线。我在互联网和Mathworks上找到了一些代码,但它是2行的交叉....任何人都可以帮助。

!1I have the Canny edge output of a ear... i have connected the farthest two boundaries with a line(green). Now I want to draw a normal from the midpoint of this line to the outer boundary(left side). The code i have written helps me to plot a normal but i want the red line to exactly meet the white boundary. Also I want the point of intersection at the point where it meets. I have also thought about another method for the same.By changing 50 to 60 pixels (in the code) the red line crosses the white boundary. If I get the point of intersection of the same then I can easily plot the line of the desired length. I found some code on the internet and Mathworks, but it is for intersection of 2 lines....Can anybody plz help.

for i=1:numel(p)
    x = [ p{i}(1), p{i}(3)];
    y = [p{i}(2), p{i}(4)];
   line(x,y,'color','g','LineWidth',2);
   m = (diff(y)/diff(x));
   minv = -1/m;
   line([mean(x) mean(x)-50],[mean(y) mean(y)-50*minv],'Color','red')
   axis equal

end ;

![] [2]

推荐答案

这里获取输入图像。

Picked up the input image from here.

这是获取交叉点并绘制它的代码 -

This is the code to get the intersection point and plot it-

%% Read image and convert to BW
img1 = imread('ear.png');
BW = im2bw(img1);

L = bwlabel(BW,8);
[bw_rows,bw_cols] =find(L==1);
bw_rowcol = [bw_rows bw_cols];
bw_rowcol(:,1) = size(BW,1) - bw_rowcol(:,1); % To offset for the MATLAB's terminology of showing height on graphs

%% Get the farthest two points on the outer curve and midpoint of those points
distmat = dist2s(bw_rowcol,bw_rowcol);
[maxdist_val,maxdist_ind] = max(distmat(:),[],1);
[R,C] = ind2sub(size(distmat),maxdist_ind);

farther_pt1 = bw_rowcol(R,:);
farther_pt2 = bw_rowcol(C,:);
midpoint = round(mean([farther_pt1 ; farther_pt2]));

%% Draw points on the normal from the midpoint across the image
slope_farthest_pts = (farther_pt1(1) - farther_pt2(1)) / (farther_pt1(2) - farther_pt2(2));
slope_normal = -1/slope_farthest_pts;

y1 = midpoint(1);
x1 = midpoint(2);
c1 = y1 -slope_normal*x1;

x_arr = [1:size(BW,2)]';
y_arr = slope_normal*x_arr + c1;
yx_arr = round([y_arr x_arr]);

%% Finally get the intersection point
distmat2 = dist2s(bw_rowcol,yx_arr);

[mindist_val2,mindist_ind2] = min(distmat2(:),[],1);
[R2,C2] = ind2sub(size(distmat2),mindist_ind2);

intersection_pt = bw_rowcol(R2,:); % Verify that this is equal to -> yx_arr(C2,:)

%% Plot
figure,imshow(img1)

hold on
x=[farther_pt1(2),farther_pt2(2)];
y=size(BW,1)-[farther_pt1(1),farther_pt2(1)];
plot(x,y)

hold on
x=[intersection_pt(2),midpoint(2)];
y=size(BW,1)-[intersection_pt(1),midpoint(1)];
plot(x,y,'r')
text(x(1),y(1),strcat('Int Pt = ','[',num2str(x(1)),',',num2str(y(1)),']'),'Color','green','FontSize',24,'EdgeColor','red','LineWidth',3)

不要忘记使用此相关功能 -

Don't forget to use this associated function-

function out = dist2s(pt1,pt2)

out = NaN(size(pt1,1),size(pt2,1));
for m = 1:size(pt1,1)
    for n = 1:size(pt2,1)
        if(m~=n)
            out(m,n) = sqrt( (pt1(m,1)-pt2(n,1)).^2 + (pt1(m,2)-pt2(n,2)).^2 );
        end
    end
end

return;

输出 -

希望这会有所帮助,让我们知道它去。有趣的项目!

Hope this helps and let us know it goes. Interesting project!

编辑1:根据下面编辑的照片,我收到了一些问题。

EDIT 1: Based on the edited photo shown below, I got few questions for you.

问题:你想要一条从PT1到MP的线路,让它在PT3上延伸并触摸外耳吗?如果是这样,你如何定义PT1?你如何区分PT1和PT2?您可能试图绘制从PT2到MP的线路并让它在其他位置触摸外耳,那么为什么PT2而不是PT1呢?

Questions: Do you want a line from PT1 to MP and let it extend and touch the outer ear at PT3? If so, how do you define PT1? How do you differentiate between PT1 and PT2? You could have tried to plot a line from PT2 to MP and let it touch the outer ear at some other point, so why not PT2 instead of PT1?

这篇关于耳朵图像处理 - 在MATLAB中查找线和曲线的交点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆