问题描述
我正在尝试使用Python OpenCV2测量沉积在玻璃上的微小颗粒的费雷特直径。目前,我有近150张图像需要自动执行此过程。为了进行测量,我编写了以下Python脚本:
import cv2
import numpy as np
import matplotlib.pyplot as plt
from skimage import io,color,measure
##step-1 reading the image
img = cv2.imread('1.tif',0)
pixel_2_micron = 1.75 #1 pixel is equal too 1.75 microns
#img = color.rgb2gray(io.imread('1.tif',0))
##step-2 selecting required region if necessary
cropped_img = img[0:1422,:]
#plt.hist(img.flat,bins=100,range=(0,255))
ret,thresh = cv2.threshold(cropped_img,162,217,cv2.THRESH_BINARY)
#Step-3
kernel = np.ones((3,3),np.uint8)
eroded = cv2.erode(thresh,kernel,iterations = 1)
dilated = cv2.dilate(eroded,iterations = 1)
#cv2.imshow("Original Image",img)
#cv2.imshow("Threshold Image",thresh)
#cv2.imshow("Eroded Image",eroded)
#cv2.imshow("Dilated Image",dilated)
#cv2.waitKey(0)
#step-4
mask = thresh == 217
io.imshow(mask) #show the masked image
请协助我测量遮罩区域的尺寸。尤其是所有遮盖区域的费雷直径。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)