如何检测区域上下的点? [英] How to detect a point above and below a region?

查看:106
本文介绍了如何检测区域上下的点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这张图片:

其中红点是划分这个阿拉伯语单词段不同字母的坐标。

Where the red dots are coordinates that divide the different letters of this Arabic word segment.

我想检测点之间区域上方或下方的点。

I want to detect the dots above or below the areas between the dots.

点(从左到右)= [81,183; 80,217 ; 83,275; 83,314]

现在 [81,183] [80,217] 。类似地,在 [80,217] [83,275] 之间的部分上方有点,并且区域以下的点[83,275] [83,314]

Now there is a dot above the letter between [81,183] and [80,217]. Similarly there are dots above section between [80,217] and [83,275] and dots below region [83,275] and [83,314].

我想做的是假设在坐标上方检测到一个点,然后必须删除该坐标。
是否有可能在Matlab中检测到这些?

What I want to do is suppose a dot is detected above a coordinate then that coordinate must be deleted. Would it be possible to detect these in Matlab?

编辑:这是原始图像

第一张图片是只显示我感兴趣的区域

The first image is just a crop showing my region of interest

推荐答案

您可以使用 regionprops提取单个对象的坐标
以下是一个示例实现:

You can extract the coordinates of the individual objects with regionprops Here is an example implementation:

im=rgb2gray(imread('http://i.stack.imgur.com/jic1X.jpg'));
P=regionprops(~im2bw(im), 'All');

Areas=cell2mat({P.Area});
Centroids=cell2mat({P.Centroid}');

仅选择面积大于10但小于100的点:

Select only the points that have an area larger that 10 but smaller than 100:

Coord=Centroids(Areas< 100 & Areas > 10,:);

监控找到的点数:

imshow(im);
hold on
for k=1:length(Coord)
    plot(Coord(k,1), Coord(k,2), 'ro');
    hold on
end

结果:

然后你可以用以下内容对点进行排序:

You can then sort the points with something like:

Aboves=Coord(Coord(:,2) < 80,:);
Belows=Coord(Coord(:,2) > 80,:);

从这里开始,有很多方法可以解决您的问题,其中一个选项如下:

From here, there are many ways of solving your problem, one option is the following:

dots=[81,183;80,217;83,275;83,314];

DetectDots=zeros(length(dots)-1, 1); % Creating a vector of zeros corresponding to the gaps between the elements in 'dots' 
for k=1:size(dots,1)-1
    if ~isempty(find((Aboves(:,1) > dots(k,2) & Aboves(:,1) < dots(k+1,2)))) %*
        DetectDots(k)=1;
    elseif ~isempty(find((Belows(:,1) > dots(k,2) & Belows(:,1) < dots(k+1,2))))
        DetectDots(k)=-1;
    else
        DetectDots(k)=0;
    end

end

结果是向量 DetectDots ,值 [1,1,-1] 在这种情况下,表示两个第一点之间有点,以及第二个和第三个点之间,以及向量的第三个和最后一个点之间的点 dots

The result is a vector DetectDots with value [1,1,-1] in this case that indicates that there are dots above between the two first point, and between the second and third point, and dots below between the third and last point of the vector dots.

* find 返回一个逻辑数组,其中包含满足条件的数组。 isempty 检查 find 的输出是否至少有一个元素。因此,如果数组中至少有一个元素 Aboves Belows 符合条件,则条件为1 。 是逻辑NOT,因此〜= 表示不相等。 & 是逻辑AND。另请注意,图像和数组之间的坐标在matlab中反转。

*find returns a logical array with ones where the condition is met. isempty checks if the output of find has at least one element. As a result the condition is one if there is at least one element in the array Aboves or Belows that meets the criteria. ~ is the logical NOT, hence ~= means not equal. & is the logical AND. Note also that the coordinates between images and arrays are inverted in matlab.

这篇关于如何检测区域上下的点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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