Opencv:獲取圖像中的段大小並刪除小段 (Opencv: Get segments sizes in image and remove small segments)


問題描述

Opencv:獲取圖像中的段大小並刪除小段 (Opencv: Get segments sizes in image and remove small segments)

我是 openCV 的新手(在 Android 上),找不到對二進製圖像進行基本分割並獲取片段(帶有黑色像素)大小的方法,然後從給定閾值的圖像中刪除小片段。請注意,我不需要只找到輪廓,我需要獲得完全連接的像素(段)大小。之後過濾小的。

示例圖像在下面

二值圖像


參考解法

方法 1:

I solved it with findContours (thanks to @Micka for pushing me).

Here are the code samples for parts which I needed. 1. I did inversion of binary image, because I needed to get black segments
2. Segmentation:



    Imgproc.findContours(mat, contours, mHierarchy, Imgproc.RETR_LIST, Imgproc.CHAIN_APPROX_NONE);

  1. remove small segments

    each = contours.iterator(); while (each.hasNext()) { MatOfPoint wrapper = each.next(); double area = Imgproc.contourArea(wrapper); if(area <= lengthThreshold){ each.remove(); } }

4. Draw new image with segments



    Imgproc.drawContours(newImg, contours, ‑1, new Scalar(0, 0, 0), 1);
    Imgproc.fillPoly(newImg, contours, new Scalar(0, 0, 0));

(by g.hakobyang.hakobyan)

參考文件

  1. Opencv: Get segments sizes in image and remove small segments (CC BY‑SA 2.5/3.0/4.0)

#image-processing #image-segmentation #Android #OpenCV






相關問題

在 matlab 中用 imread 讀取圖像文件會給出什麼樣的表示? (reading a image file with imread in matlab gives what kind of representation?)

使用 CRF 的圖像標記性能 (Image labeling performance using CRF)

Opencv:獲取圖像中的段大小並刪除小段 (Opencv: Get segments sizes in image and remove small segments)

將 PHP 頁面作為圖像返回 (Return a PHP page as an image)

我在哪裡可以找到有關雙三次插值和 Lanczos 重採樣的好讀物? (Where can I find a good read about bicubic interpolation and Lanczos resampling?)

從圖像中刪除白色背景 (Remove white backgrounds from images)

如何填充投影圖像的空白部分? (How to fill empty parts of a projected image?)

如何使圖像亮度均勻(使用 Python/PIL) (How to Make an Image Uniform Brightness (using Python/PIL))

圖像處理公式可生成類似通過 Mac 相機拍攝的照片的效果 (Image manipulation formula to generate effects like pictures taken via Mac's camera)

從照片生成漂亮的直方圖? (generating nice looking histogram from photo?)

使用 DjVu 工具進行背景/前景分離? (Using the DjVu tools to for background / foreground seperation?)

如何操縱跟踪器區域使其變成方形? (How can I manipulate the tracker area to make it into a square shape?)







留言討論