分段区域内的区域分割

时间:2012-03-31 19:07:49

标签: java image-processing opencv javacv

这是一张图片:

enter image description here

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

(因此将白色区域内的黑色圆圈分段)。

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

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

在opencv(javacv)中有一种简单的方法吗?

提前谢谢

2 个答案:

答案 0 :(得分:2)

使用findContours()drawContours()在OpenCV中有一种简单的方法。如果使用findContours()的分层版本,则可以查看层次结构并仅绘制(填充)白色四边形的子轮廓。这有一个额外的好处,你可以做一些健全性检查(例如检查轮廓的大小,看看它是否大约是你期望的大小),如果有必要的话。我对java或javacv一无所知,但也许你可以查看opencv中包含的findcontours的c ++示例以获得灵感?

答案 1 :(得分: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

好的,它的一般线条如何做你需要的,如果你需要更多的确切我将尝试解释更详细。您也可以直接与我联系

希望它会对你有所帮助。

相关问题