改进的高斯滤波+阈值法

2024-04-20 08:30:48 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在为一次物理体验制作一组图片:https://filesender.renater.fr/?s=download&token=f08936bf-074d-07e1-a2f7-5c93cf74c194

文件夹中有3个图像集。对于每一张照片,我们每毫秒都要拍很多照片,在每一张照片上,我们在白色背景上有4个黑点。 我的目的是通过测量上点和较平点之间的变形,以及从左到右的变形来得到一个图。你知道吗

import matplotlib.pyplot as plt
import scipy
from skimage import filters
from skimage import measure
from operator import itemgetter
import glob

plt.interactive(False)


def trouve(titre):
    #Extract time in the image title
    local_tiretbas = titre.rfind('_')+1
    local_tiff = titre.find('.tiff')
    return float(titre[local_tiretbas:local_tiff])


array_results = []

image_list = sorted(glob.glob('/home/nicolas/PycharmProjects/Imagerie/14/t1_ep_p/*.tiff'), key=trouve)

T = [] #TimeList
for i in range(len(image_list)):
   T.append(trouve(image_list[i]))
   picture = plt.imread(image_list[i])
   cutout = picture[900:1150, int(350 + i*2.8):int(650 + 3.2*i)]
   cutout_improved = filters.gaussian(cutout, sigma=3)
   val = filters.threshold_otsu(cutout_improved)
   mask = cutout_improved < val
   mask_filled = scipy.ndimage.morphology.binary_fill_holes(mask)
   I_label = measure.label(mask_filled,background=0)
   region_properties = measure.regionprops(I_label)


   l = []
for label in region_properties:
    centroid = label.centroid
    l.append(centroid)  
tuple_values = (max(l, key=itemgetter(1))[1]-min(l, key=itemgetter(1))[1], max(l, key=itemgetter(0))[0]-min(l, key=itemgetter(0))[0])
array_results.append(tuple_values)
l0 = array_results[0][0]
h0 = array_results[0][1]
DL = [i[0]/l0 for i in array_results]
DT = [i[1]/h0 for i in array_results]
plt.plot(T, DL, label='Déplacement longitudinal', color='green')
plt.plot(T, DT, label='Déplacement transversal', color='red')
plt.legend(loc='best')
plt.show()

我成功地得到的最好结果是一个数据集的这个图像。这并不完美,但很酷。但是对于剩下的两个,这个代码不起作用,我正在寻找一些提示来定位黑点。 到目前为止,我只使用了skimage,但如果openCV效果更好的话,我也可能会使用它。你知道吗

Here is the best result I get

Here is the expected result

如果你有任何想法来帮助我这个高斯滤波器和阈值,请随时! 我已经尝试了一个精明的边缘检测,但不幸的是,它不是一个很大的成功。你知道吗

致以最诚挚的问候, 尼古拉斯。你知道吗


Tags: keyinimageimportforlocalpltarray