c# - 如何检测二值图像RGB中的圆?

标签 c# image-processing

我有以下图片:

https://www.upsieutoc.com/images/2014/10/18/binkq27dd30.png

我想计算图像中有多少个圆圈。我的图像是nxn 8位二进制图像,而不是0和1。 那么,我能做什么呢? 感谢您的阅读!

最佳答案

精简版:http://www.codeproject.com/Articles/36378/Optical-Mark-Recognition-with-DotImage

//Create a Bitmap object from an image file.
Bitmap myBitmap = new Bitmap("Answers.jpg");

//Check the pixels in the Bitmap for the circles:
for (int i = 0; i < myBitmap.Width;i++)
{
    for (int j = 0; j < myBitmap.Height;j++)
    {
        Color pixelColor = myBitmap.GetPixel(i, j);
        //Translate pixel to a 1 or 0 depending on if the pixel is black or white
        //This next line is psuedo code:
        boolArray[i][j] = pixelColour.R < 128 && pixelColour.G < 128 && pixelColour.B < 128;
    }
}

然后迭代 bool 数组,查看一行中以及上方和下方是否有三个或四个 1,例如:

if (boolArray[i][j] && boolArray[i + 1][j] && boolArray[i + 2][j])
{
   if (boolArray[i][j + 1] && boolArray[i][j + 2] && boolArray[i][j + 3])
   {
    //found an answer marked as a filled in circle
   }
}

注意:您应该检查同一嵌套循环中的 cicle。我只填充了一个多维 bool 数组,以便您可以看到这两个逻辑。

关于c# - 如何检测二值图像RGB中的圆?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26435974/

相关文章:

c# - System.Array 使用 LINQ 到 POCO

c# - 如何使用 BinaryReader 并将数据正确输入文件?

c# - ILogger 不需要配置?

python - 如何找到图像中所有矩形瓷砖?

python - 如何从背景和文本颜色相似的轮胎等图像中检测文本?

image-processing - 如何检测图像中存在哪个对象。?

c++ - 通过减去具有不同背景的两个图像来获得 alpha

c# - 在 .NET 中比较不同的数字类型(int、float、double、...)

python - NumPy 中的逐元素矩阵乘法

c# - DateTime 比较忽略类型?