3

这是一张图片:

在此处输入图像描述

我想知道如何将黑色圆圈设置为白色,将其余部分设置为黑色。

(所以在白色区域内分割黑色圆圈)。

我知道我可以反转图像并且圆圈将是白色的......但是在这张图片中看到的整个黑色部分也是如此。

如果我必须在 matlab 中执行此操作,我将执行连接组件操作并检查 BLOB 的循环性。虽然我必须在 opencv 中执行此操作(准确地说是 javacv。)

在opencv(javacv)中有没有一种简单的方法来做到这一点。

提前谢谢

4

2 回答 2

2

在 OpenCV 中有一个简单的方法,使用findContours()drawContours()。如果您使用 的分层版本findContours(),则可以查看层次结构并仅绘制(填充)白色四边形的子轮廓。这还有一个额外的好处,即您可以在必要时进行一些完整性检查(例如,检查轮廓的大小以查看它是否与您期望的大小大致相同)。我对java或javacv一无所知,但也许你可以查看opencv附带的findcontours的c ++示例以获得灵感?

于 2012-03-31T21:09:17.233 回答
0

您可以使用openCV库(通过java适配器)检测图像上的图像对象;为此,您需要为圈子训练网络。

关于你的情况(可能这个解决方案不是通用的),你可以分割你的图像分段,并使用作为条件 - 颜色变化,请参见下面的伪代码:

//build color switching list
List<Point> colorSwitches = ...
for(each horizontal line from image){
    for(each pixel from line){
        if(color of previous pixel != color of current pixel){
            colorSwitches.add(currentPoint)
        }
    }    
}
// so, you have detected margins of your image objects; now we need to merge neighbor pixels into image objects, where image object is collection of margin points(you should create this class)
List<ImageObject> imageObjects = ...
for(each color switch){
    if(current pixel is connected with pixels from existing image objects){
        // returns image object neared with current point
        getRelatedImageObject(imageObjects).add(currentPoint);
    }else{
        imageObjects.add(new ImageObject(currentPixel));
    }
}
// now we have list of objects from image, and we need to match objects

好的,它的一般线路如何做你需要的,如果你需要更准确,我会尝试更详细地解释。也可以直接联系我

希望它会帮助你。

于 2012-03-31T20:17:43.040 回答