边缘检测 - 去除背景

问题描述

想要在显微镜图像上使用边缘检测使背景变白。 这是我到目前为止的代码,这有用吗?

代码

import cv2 
import numpy as np 
import matplotlib.pyplot as plt
def simple_edge_detection(image): 
   edges_detected = cv2.Canny(image,100,200) 
   images = [image,edges_detected]
   location = [121,122] 
   for loc,edge_image in zip(location,images): 
      plt.subplot(loc) 
      plt.imshow(edge_image,cmap='gray')
   cv2.imwrite('edge_detected.png',edges_detected)
   plt.savefig('edge_plot.png')
   plt.show()
   
img = cv2.imread('gay2.0.jpg',0)
simple_edge_detection(img)

result of the code:

result wished:

解决方法

使用 Canny 过滤器并使用足以去除大部分背景的阈值进行二值化。

移除小斑点并检测图像边界上的小斑点(可能填充它们的孔)。这些定义了感兴趣对象周围的蒙版(不要担心图片中的绿色斑点和橙色线条)。

您可以添加一些预处理或后处理以移除支架。

enter image description here