Opencv 图像处理、稀释、交集、补全 [英] Opencv Image processing, dilution, intersection, complement

查看:39
本文介绍了Opencv 图像处理、稀释、交集、补全的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从我阅读过的研究中得出的一个过程,并遇到了这个过程.我曾尝试阅读所涉及的流程,但我似乎无法理解它.

I'm trying out a process from a research that I've read and came across this procedure. I have tried reading about the processes involved but I can't seem to wrap my head around it.

  1. 取二进制图像I
  2. 创建一个灰度值255的标记图像F除了沿边界的那些像素之外的所有像素,这些像素不是细胞图像中的对象像素,它是 0.
  3. Dilate F by B,一个5×5掩码,所有像素的灰度值为0.让这个膨胀的图像成为F ⊕ B.
  4. IF⊕B的补码的交集.让它成为H.
  5. 使 F 等于 H.
  6. 重复上述步骤 3 到 5 t 次(实验-t 被视为 1000).
  7. I的补码和补码的交集H 的注释.这给了我们孔的图像.让这成为G.
  8. IG的并集得到最终图像,没有非外围孔.
  1. Take the binary image I
  2. Create a marker image F which has gray value 255 in all pixels except for those pixels along the boundary which are not object pixels in the cell image, where it is 0.
  3. Dilate F by B, a 5×5 mask that has gray value 0 in all pixels. Let this dilated image be F ⊕ B.
  4. Take intersection of complement of I and F ⊕ B. Let this be H.
  5. Make F equal to H.
  6. Repeat the above steps 3 to 5 for t times (experimen- tally, t is taken as 1000).
  7. Take intersection of complement of I and comple- ment of H. This gives us the image of holes. Let this be G.
  8. Take union of the I and G to get the final image, which is free of non peripheral holes.

这是他们过程的结果:

我想使用这个二进制图像获得相同的结果:

I wanted to have the same result using this binary image:

谁能解释一下完整的过程并达到相同的结果.

Can someone please explain the thorough process and achieve the same result.

这是我目前所在的位置:

This is where I'm currently at:

# LOAD IMAGE
img = cv2.imread('resources/rbc2.png')
# CONVERT TO GRAYSCALE
imgGray = cv2.cvtColor(imgBrightness, cv2.COLOR_BGR2GRAY)

# APPLY MEDIAN BLUR
medianImg = cv2.medianBlur(imgGray,9)

# OTSU THRESHOLDING
ret, otsu = cv2.threshold(medianImg,0,255,cv2.THRESH_BINARY + cv2.THRESH_OTSU)
complimentI = cv2.bitwise_not(otsu)

推荐答案

如果您只想填充掩码中的孔,我们可以通过使用 opencv 的 findContours 更简单地做到这一点.我们可以过滤小轮廓并在蒙版上填充这些轮廓.

If all you're looking to do is fill holes in a mask, we can do that much more simply by using opencv's findContours. We can filter for small contours and fill in those contours on the mask.

我使用的是 Opencv 3.4.如果您使用的是 Opencv 2.* 或 4.*,则 findContours 返回 2 个参数,并且应如下所示:

I am using Opencv 3.4. If you are using Opencv 2.* or 4.* then findContours returns 2 arguments and should look like this:

contours, _ = cv2.findContours(mask, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE);

填充面膜

import cv2

# load image
gray = cv2.imread("blobs.png", cv2.IMREAD_GRAYSCALE);

# mask with otsu
_, mask = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY+cv2.THRESH_OTSU);

# find contours
_, contours, _ = cv2.findContours(mask, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE);

# filter out contours by size
small_cntrs = [];
for con in contours:
    area = cv2.contourArea(con);
    if area < 1000: # size threshold
        small_cntrs.append(con);
cv2.drawContours(mask, small_cntrs, -1, (0), -1);

# show
cv2.imshow("mask", mask);
cv2.waitKey(0);

这篇关于Opencv 图像处理、稀释、交集、补全的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆