matlab - 寻找图像中的凹坑

标签 matlab opencv image-processing computer-vision scikit-image

我的一个 friend 正在从事以下项目:

下面是不锈钢表面的显微 (SEM) 图像。

enter image description here

但是你可以看到,它被腐 eclipse 了一点(在长时间暴露在海洋环境之后)并且在表面形成了一些凹坑。一些坑被标记为红色圆圈。

他需要找出图像中的凹坑数量,他正在手动计算(想象一下,有将近 150 张图像)。因此,我想到使用任何图像处理工具自动执行此过程。

Question:

How can I find the number of pits in this image?


我尝试了什么:

作为第一步,我通过关闭操作稍微提高了对比度。

import numpy as np
import cv2
from matplotlib import pyplot as plt

img = cv2.imread('6.jpg')
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE,(11,11))

close = cv2.morphologyEx(gray, cv2.MORPH_CLOSE, kernel)

close2 = cv2.add(close,1)
div = (np.float32(gray)+1)/(close2)
div2 = cv2.normalize(div,None, 0,255, cv2.NORM_MINMAX)
div3 = np.uint8(div2)

结果:

enter image description here

然后我为 127 应用了一些阈值并在其中找到轮廓。后来这些轮廓根据它们的面积进行过滤(没有关于面积的具体信息,我取了1-10的范围作为经验值)。

ret, thresh = cv2.threshold(div3, 127,255, cv2.THRESH_BINARY_INV)
temp, contours, hierarchy = cv2.findContours(thresh, cv2.RETR_LIST, cv2.CHAIN_APPROX_NONE)

res = np.zeros(gray.shape,np.uint8)

for cnt in contours:
    if 1.0 < cv2.contourArea(cnt) < 10.0:
        res = cv2.drawContours(res, [cnt], 0, 255, -1)

plt.subplot(121); plt.imshow(img, 'gray'); plt.subplot(122); plt.imshow(res,'gray'); plt.show() 

但它最终带来了很多额外的噪音。查看下面的结果:

enter image description here


附加信息:

一些测试图片:

enter image description here enter image description here

最佳答案

你的案例让我想起了一篇论文 ( Human Detection Using a Mobile Platform and Novel Features Derived From a Visual Saliency Mechanism ),它基于中心神经节细胞概念计算图像的显着性,即一种检测被黑暗区域包围的明亮像素的方法(或相反的称为偏离中心的细胞) ).

Ganglion cells

要近似这些单元格,您可以使用矩形区域。通过使用积分图像,您可以加快该过程。查看论文了解详情。

还有一个想法是复合过滤器的卷积。找到一个非常接近每个坑的模板,并将模板与图像相关联(或使用多个过滤器进行比例/形式变化)。

关于matlab - 寻找图像中的凹坑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23516870/

相关文章:

c++ - matlab R2013a 和 MS VC++ 2013 之间的链接错误

matlab - 如何在matlab中显示多个不同颜色的二值图像?

使用 MAT2CELL 的 MATLAB

python - 向量化像素化分配,用于分割蒙版的颜色映射

performance - 如何构建减少迭代次数的循环

matlab - 通过 ssh 运行 Matlab GUI?

python - 使用 FFMPEG 提取帧?

android - 在Android中使用openCV检测特定颜色的区域

java - 查找图像中重复的对象

python - TensorFlow 中的图像变形