简体   繁体   English

使用 python 的图像处理检测图像中的点

[英]Detect dots in a image using image processing with python

I need to identify the following dots in the given images.我需要识别给定图像中的以下点。 But it doesn't give correct detection.但它没有给出正确的检测。 Can someone give a methodology to identify these dots in an image like this?有人可以提供一种方法来识别这样的图像中的这些点吗? 在此处输入图像描述

I have done some enhancement to this as follows,我对此做了一些改进,如下所示, 在此处输入图像描述

  • enhanced image, by dilation followed by sharpened增强图像,先膨胀再锐化

    I Used template matching for detecting these dots in the image.我使用模板匹配来检测图像中的这些点。 But it didn't work well.但效果并不好。 Code is as follows.代码如下。 Is there any other way to detect these?有没有其他方法可以检测到这些?

import cv2 import numpy as np导入 cv2 导入 numpy 作为 np

img_rgb = cv2.imread(file)
cv2.imwrite("D:/4/Detect/"+str(i)+".0.jpg",img_rgb)
img_gray = cv2.cvtColor(img_rgb, cv2.COLOR_BGR2GRAY)

template = cv2.imread('a.jpg',0)
w, h = template.shape[::-1]

res = cv2.matchTemplate(img_gray,template,cv2.TM_CCOEFF_NORMED)
threshold = 0.455
loc = np.where( res >= threshold)

for pt in zip(*loc[::-1]):
    cv2.rectangle(img_rgb, pt, (pt[0] + w, pt[1] + h), (0,255,255), 0)

cv2.imshow('Detected',img_rgb)
cv2.imwrite("D:/4/Detect/"+str(i)+".1.jpg",img_rgb)
cv2.waitKey(0)
cv2.destroyAllWindows()

Here's the main part of the code for better result (shown in the image below), that I developed quickly:这是我快速开发的代码的主要部分以获得更好的结果(如下图所示):

import cv2 as cv
img = cv.imread('med.jpg',0)
th2 = cv.adaptiveThreshold(img,255,cv.ADAPTIVE_THRESH_MEAN_C,\
            cv.THRESH_BINARY,11,2)
th3 = cv.adaptiveThreshold(img,255,cv.ADAPTIVE_THRESH_GAUSSIAN_C,\
            cv.THRESH_BINARY,11,2)
titles = ['Adaptive Mean Thresholding', 'Adaptive Gaussian Thresholding']
images = [th2, th3]
inv = ~th3
res = cv.bitwise_and(img,inv)
cv.imshow(titles[1],res)
cv.waitKey(0)
cv.imwrite("result.jpg",res)
cv.destroyAllWindows()

在此处输入图像描述

Tune the parameters for desired result.调整参数以获得所需的结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM