【问题标题】:finding a valley with Matlab in a binary image用 Matlab 在二进制图像中找到一个山谷
【发布时间】:2016-04-08 21:39:38
【问题描述】:

我有一个像这样的二进制图像:

我知道黑色区域中一个点的位置(例如,X 点),我需要在同一黑色区域(在本例中为 O 点)找到山谷(Y 坐标最低的点) )。

图像中还有其他黑色区域。

如何使用 Matlab 做到这一点?

【问题讨论】:

  • 你的意思是最低的Y坐标?请向我们展示您目前所拥有的。
  • 是的,我的意思是最低的。对不起。我没有任何代码,我是图像处理新手,不知道如何开始。

标签: matlab image-processing


【解决方案1】:

给定一个起点 P=(x,y),你可以使用 imfill 来找到对应的连通分量,并结合 max 和 imfind 来找到其中的最低点。

%reads the image
I = imread('<your path>');

%sets an input point. For example: (250,100)
x = 100; y=250;

%Find the connected component of the given input point
BW2 = imfill(I,[y x]);
diffMat = BW2~=I;

%finds the minimal x and y indices of this connected component
[Y, X] = ind2sub(size(diffMat),find(diffMat));
maxInd = find(Y==max(Y),1,'first');

%prints the result
Y(maxInd)
X(maxInd)

给定以下输入:

结果是:

Y=313, X=304

请注意,此代码仅找到一个点作为山谷。如果你想找到更多的点,你可以在 find 函数中省略这个参数并接收所有的谷点。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2011-02-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-12-07
相关资源
最近更新 更多