首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >迈克尔逊干涉仪条纹计数器

迈克尔逊干涉仪条纹计数器
EN

Stack Overflow用户
提问于 2019-10-23 22:08:50
回答 1查看 513关注 0票数 1

关于迈克尔逊干涉仪的实验室报告,我想在Python上写一个自动计数条纹的代码(现在我们必须手动计数,而且不是很精确)。我为了这个目的拍了一段视频。

A frame of the video

你将如何开始呢?非常感谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-10-23 22:13:37

我会查看openCV,这是一个用于python的开源计算机视觉库。由于条纹可能与背景有很大的不同,你可以取图像的导数(https://docs.opencv.org/2.4/doc/tutorials/imgproc/imgtrans/sobel_derivatives/sobel_derivatives.html),并计算有大梯度的地方。我对你发布的图片的解决方案如下所示。我认为这应该会让你走上正轨。

代码语言:javascript
复制
import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec
import numpy as np
import cv2
from scipy.signal import find_peaks
from scipy.ndimage.filters import gaussian_filter1d

fig = plt.figure(tight_layout=True)
gs = gridspec.GridSpec(2, 2)
ax1 = fig.add_subplot(gs[0, 0])
ax2 = fig.add_subplot(gs[0, 1])
ax3 = fig.add_subplot(gs[1, :])
ax1.set_xticks([])
ax1.set_yticks([])
ax2.set_yticks([])
ax2.set_xticks([])

img = cv2.imread('michelson.jpg', 0) # read in the image as grayscale

ax1.imshow(img, cmap='gray')
ax1.set_title("Original image (grayscale)")

img[img < 10] = 0 # apply some arbitrary thresholding (there's
# a bunch of noise in the image

yp, xp = np.where(img != 0)

xmax = max(xp)
xmin = min(xp)

target_slice = (xmax - xmin) / 2 + xmin # get the middle of the fringe blob

sobely = cv2.Sobel(img,cv2.CV_64F,0,1,ksize=5) # get the vertical derivative

sobely = cv2.blur(sobely,(7,7)) # make the peaks a little smoother

ax2.imshow(sobely, cmap='gray') #show the derivative (troughs are very visible)
ax2.plot([target_slice, target_slice], [img.shape[0], 0], 'r-')

slc = sobely[:, int(target_slice)]
slc[slc < 0] = 0
ax2.set_title("vertical derivative (red line indicating slice taken from image)")

slc = gaussian_filter1d(slc, sigma=10) # filter the peaks the remove noise,
# again an arbitrary threshold

ax3.plot(slc) 
peaks = find_peaks(slc)[0] # [0] returns only locations 

ax3.plot(peaks, slc[peaks], 'ro')
ax3.set_title('number of fringes: ' + str(len(peaks)))
plt.show()

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58524759

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档