English 中文(简体)
在双射物体内填充洞
原标题:Filling holes inside a binary object

I have a problem with filling white holes inside a black coin so that I can have only 0-255 binary images with filled black coins. I have used a Median filter to accomplish it but in that case connection bridge between coins grows and it goes impossible to recognize them after several times of erosion... So I need a simple floodFill like method in opencv

这里,我的形象是:

“entergraph

<>strong>EDIT:floodliver, 如同功能一样,必须填充大部件中的空洞,而无需打X, Y坐标为种子......

EDIT:我尝试使用<代码>cvDrawContours功能,但用斜体填充较大体内的轮.。

我的守则是:

        CvMemStorage mem = cvCreateMemStorage(0);
        CvSeq contours = new CvSeq();
        CvSeq ptr = new CvSeq();
        int sizeofCvContour = Loader.sizeof(CvContour.class);
        
        cvThreshold(gray, gray, 150, 255, CV_THRESH_BINARY_INV);
        
        int numOfContours = cvFindContours(gray, mem, contours, sizeofCvContour, CV_RETR_CCOMP, CV_CHAIN_APPROX_SIMPLE);
        System.out.println("The num of contours: "+numOfContours); //prints 87, ok
        
        Random rand = new Random();
        for (ptr = contours; ptr != null; ptr = ptr.h_next()) {
            Color randomColor = new Color(rand.nextFloat(), rand.nextFloat(), rand.nextFloat());
            CvScalar color = CV_RGB( randomColor.getRed(), randomColor.getGreen(), randomColor.getBlue());
            cvDrawContours(gray, ptr, color, color, -1, CV_FILLED, 8);
        }
        CanvasFrame canvas6  = new CanvasFrame("drawContours");
        canvas6.showImage(gray);

结果:(你可以看到每个硬币中的黑洞)

enter image description here

最佳回答

这样做有两种方法:

<>strong>1 Contour Filling:

首先,歪曲图像,在图像中找到镜子,用黑体和反面填充。

des = cv2.bitwise_not(gray)
contour,hier = cv2.findContours(des,cv2.RETR_CCOMP,cv2.CHAIN_APPROX_SIMPLE)

for cnt in contour:
    cv2.drawContours(des,[cnt],0,255,-1)

gray = cv2.bitwise_not(des)

塑造形象:

“entergraph

2

kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE,(3,3))
res = cv2.morphologyEx(gray,cv2.MORPH_OPEN,kernel)

由此形成的形象如下:

“entergraph

你可以看到,这两种情况都没有什么不同。

<<>NB:gray - graypl图像 所有法典都载于开放式公民委员会。


参考:

问题回答

我想象,一个简单的分裂和侵蚀会很好地缩小差距。 我认为,这或许是你所期待的。

更强有力的解决办法是对整个形象进行前沿检测,然后对圈子进行ough变。 快速通道显示,有各种语言的密码样本,可用来对使用ough变的圈子进行不间断的探测,因此希望能让你去做一些事情。

使用“ough变”的好处是,算法实际上将给你一个对每个圈子大小和位置的估计,以便你能够根据这一模式重建理想形象。 重叠也应当非常有力,特别是考虑到这里的投入形象的质量(即对不实正面的担忧较少),这样可以降低结果的门面。

您不妨查阅Fillhole transformation,应用形态图像重建。

这一转变将填补贵表层的漏洞,尽管也弥补了相邻组之间的所有漏洞。 其他海报建议的“粗略空间”或开放式解决办法可能给你更好的高级别承认结果。

Try using cvFindContours() 你们可以利用这一系统寻找相关部件。 有了正确的参数,这一职能将每个相关组成部分的轮.列入清单。

Find the contours which represent a hole. Then use cvDrawContours() to fill up the selected contour by the foreground color thereby closing the holes.

如果有人正在寻求执行,

            std::vector<std::vector<cv::Point> > contours_vector;

            cv::findContours(input_image, contours_vector, CV_RETR_LIST, CV_CHAIN_APPROX_NONE);

            cv::Mat contourImage(input_image.size(), CV_8UC1, cv::Scalar(0));
            for ( ushort contour_index = 0; contour_index < contours_vector.size(); contour_index++) {
                cv::drawContours(contourImage, contours_vector, contour_index, cv::Scalar(255), -1);
            }

            cv::imshow("con", contourImage);
            cv::waitKey(0);

enter image description here

“entergram

I think if the objects are touched or crowded, there will be some problems using the contours and the math morophology opening. Instead, the following simple solution is found and tested. It is working very well, and not only for this images, but also for any other images.

http://blogs.mathwork.com/steve/2008/08/05/meetinging-small-holes/“rel=“nofollow”>。

请注意: 投入图

1. filled_I = floodfill(I). // fill every hole in the image.
2. inverted_I = invert(I)`.   
3. holes_I = filled_I AND inverted_I. // finds all holes 
4. cc_list = connectedcomponent(holes_I) // list of all connected component in holes_I.
5. holes_I = remove(cc_list,holes_I, smallholes_threshold_size) // remove all holes from holes_I having size > smallholes_threshold_size.
6. out_I = I OR holes_I. // fill only the small holes.

简言之,算法只是找到所有的漏洞,然后将大的漏洞删除,然后只用原形象写小的。





相关问题
Resources for Image Recognition

I am looking for a recommendation for an introduction to image processing algorithms (face and shape recognition, etc.) and wondered if anyone had an good recommendations, either for books, ...

Good reference book for digital image processing? [closed]

I am learning digital image processing on my own and would like recomendations on good reference books. If you know of books to definately stay away from that would be useful as well. Thanks

Python Tesseract can t recognize this font

I have this image: I want to read it to a string using python, which I didn t think would be that hard. I came upon tesseract, and then a wrapper for python scripts using tesseract. So I started ...

What s the quickest way to parallelize code?

I have an image processing routine that I believe could be made very parallel very quickly. Each pixel needs to have roughly 2k operations done on it in a way that doesn t depend on the operations ...

Computing object statistics from the second central moments

I m currently working on writing a version of the MATLAB RegionProps function for GNU Octave. I have most of it implemented, but I m still struggling with the implementation of a few parts. I had ...

Viola-Jones face detection claims 180k features

I ve been implementing an adaptation of Viola-Jones face detection algorithm. The technique relies upon placing a subframe of 24x24 pixels within an image, and subsequently placing rectangular ...

热门标签