[英]Measuring feret diameter of microscopic particles using Python OpenCV
我正在嘗試使用 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, kernel, 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
請協助我測量蒙面區域的尺寸。 尤其是所有遮罩區域的費雷特直徑。
我剛剛發布了一個 python 模塊來計算二進制圖像的 feret 直徑,這將解決您的問題。
https://pypi.org/project/feret/
目前它無法處理具有多個區域的圖像,但如上所述,您可以使用此skimage 模塊來查找連接區域,然后只取這些區域的最大值和最小值來剪切圖像的區域。 如果您需要幫助,請告訴我。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.