使用Matlab检测十字中心点 [英] Detecting center point of cross using Matlab

查看:1822
本文介绍了使用Matlab检测十字中心点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我有一个如上所示的图像。我可以检测十字架的中心点,并使用Matlab输出结果吗?感谢。

Hello, I have an image as shown above. Is it possible for me to detect the center point of the cross and output the result using Matlab? Thanks.

推荐答案

在这里。我假设你有图像工具箱,因为如果你不然,你可能不应该试图做这种事情。然而,所有这些功能可以用我相信的卷积来实现。我对上面提供的图像进行了这个过程,并获得了点(139,286),其中138是行,268是列。

Here you go. I'm assuming that you have the image toolbox because if you don't then you probably shouldn't be trying to do this sort of thing. However, all of these functions can be implemented with convolutions I believe. I did this process on the image you presented above and obtained the point (139,286) where 138 is the row and 268 is the column.

1.将图像转换为二进制映像:

1.Convert the image to a binary image:

bw = bw2im(img, .25);

其中img是原始图像。根据图像,您可能需要调整第二个参数(范围从0到1),以便只能获取交叉。不要担心十字架没有完全连接,因为我们会在下一步中纠正错误。

where img is the original image. Depending on the image you might have to adjust the second parameters (which ranges from 0 to 1) so that you only get the cross. Don't worry about the cross not being fully connected because we'll remedy that in the next step.

2.放大图像以加入零件。我不得不这样做两次,因为我必须设置阈值这么低的二进制图像转换(你的图像的一些部分非常暗)。扩展本质上只是增加现有白色像素周围的像素(我也将反转二进制图像,因为我将它发送到bwmorph,因为操作是作用于白色像素的值为1)。

2.Dilate the image to join the parts. I had to do this twice because I had to set the threshold so low on the binary image conversion (some parts of your image were pretty dark). Dilation essentially just adds pixels around existing white pixels (I'll also be inverting the binary image as I send it into bwmorph because the operations are made to act on white pixels which are the ones that have a value of 1).

bw2 = bwmorph(~bw, 'dilate', 2);

最后一个参数表示扩张操作的次数。

The last parameter says how many times to do the dilation operation.

3.将图像缩小到一个点。

3.Shrink the image to a point.

bw3 = bwmorph(bw2, 'shrink',Inf);

同样,最后一个参数表示执行操作的次数。在这种情况下,我放在Inf中收缩,直到只有一个像素是白色(换句话说1)。

Again, the last parameter says how many times to perform the operation. In this case I put in Inf which shrinks until there is only one pixel that is white (in other words a 1).

4.找到仍然是一个像素1。

4.Find the pixel that is still a 1.

[i,j] = find(bw3);

这里,i是行,j是bw3中像素的列,使得bw3 ,j)等于1.所有其他像素在bw3中应该为0.

Here, i is the row and j is the column of the pixel in bw3 such that bw3(i,j) is equal to 1. All the other pixels should be 0 in bw3.

可能有其他方法来使用bwmorph,但我认为这样工作相当不错。您可能需要根据图片进行调整。如果需要,我可以添加每个步骤的图片。

There might be other ways to do this with bwmorph, but I think that this way works pretty well. You might have to adjust it depending on the picture too. I can include images of each step if desired.

这篇关于使用Matlab检测十字中心点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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