简体   繁体   English

OPENCV ::查找两个同心圆之间的所有点

[英]OPENCV :: Find all the points between two concentric circles

I have two concentric circles a and b, I detected the circles from the image, I know their Radii. 我有两个同心圆a和b,我从图像中检测到这些圆,我知道它们的半径。 What I want is the Points between the two concentric cirlces, So that I can extract the RGB values from those Points. 我想要的是两个同心圆之间的点,以便可以从这些点中提取RGB值。 Any help would be helpfull. 任何帮助将是有益的。

The indices ( x, y ) of the points between the two concentric circles (center ( x_0, y_0 ), radii r_0, r_1 with r_1 > r_0 ) have to fulfill the following condition: 两个同心圆之间的点的索引( x, y )(中心( x_0, y_0 ),半径r_0, r_1r_1 > r_0 )必须满足以下条件:

(x-x_0) * (x-x_0) + (y-y_0) * (y-y_0) >= r_0 * r_0
(x-x_0) * (x-x_0) + (y-y_0) * (y-y_0) <= r_1 * r_1

So when looping over all point of an image you can figure out which points to process: 因此,当遍历图像的所有点时,您可以确定要处理的点:

for (int x=0; x<img.rows; x++)
{
   for (int y=0; y<img.cols; y++)
   {
       double dd = (x-x_0) * (x-x_0) + (y-y_0) * (y-y_0);
       if (dd < r_0 * r_0 || dd > r_1 * r_1)
         continue;

       // Do what you have to do with the points between the two circles
   }
}

Pseudocode: 伪代码:

Make a Mat of the same size as your source image. 
Draw the two filled circles with the built-in OpenCV circle drawing routine. 
  (large circle in white, then the small in black) 
Use that as a mask, that you multiply on your source image. 
(Depending on which pixels you wish to keep, the mask may have to be inverted.)

If you need to visit all pixels and somehow gather their colour values, and you only want to visit the pixels in question as speed is crucial, I would suggest that you look into the midpoint circle algorithm authored by Bresenham . 如果您需要访问所有像素并以某种方式收集它们的颜色值,并且您只想访问有问题的像素,因为速度至关重要,那么我建议您研究一下Bresenham编写中点圆算法 You could specialize this so that you only get 2 or 4 points per pixel line, and traverse each line's pair(s) of points. 您可以对此进行专门化,以便每像素线仅获得2或4个点,并遍历每条线的成对点。 Should be possible O(n), where n is height in pixels (diameter, ie largest radius), so you'd look at o(m), m being the number of pixels between the two pixels, instead of n^2. 应该是O(n),其中n是以像素为单位的高度(直径,即最大半径),因此您将看到o(m),m是两个像素之间的像素数,而不是n ^ 2。 Would matter a lot if you have large images and radii close to each other. 如果大图像和半径彼此靠近,那将很重要。

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM