Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/video/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 修改图像以获得清晰、无噪声的特征,用于光流/图像稳定_Python_Opencv_Image Processing_Image Stabilization - Fatal编程技术网

Python 修改图像以获得清晰、无噪声的特征,用于光流/图像稳定

Python 修改图像以获得清晰、无噪声的特征,用于光流/图像稳定,python,opencv,image-processing,image-stabilization,Python,Opencv,Image Processing,Image Stabilization,我正试图在Python中使用opencv开发一个稳定流体实验图像的管道。(实际尺寸:1920x1460) 该管道应能够稳定低频漂移和高频“抖动”,这在试验期间阀门打开/关闭时偶尔发生。我目前的方法是应用双边滤波器,然后进行自适应阈值处理,以显示图像中的通道。然后,我使用goodFeaturesToTrack在阈值图像中查找角点。然而,由于对比度较低,图像中存在大量噪声,图像角部存在一些光学效应。虽然我可以找到通道的各个角落,但它们在一帧一帧地移动。我跟踪了每个帧中相对于从calcOpticalF

我正试图在Python中使用opencv开发一个稳定流体实验图像的管道。(实际尺寸:1920x1460)

该管道应能够稳定低频漂移和高频“抖动”,这在试验期间阀门打开/关闭时偶尔发生。我目前的方法是应用双边滤波器,然后进行自适应阈值处理,以显示图像中的通道。然后,我使用goodFeaturesToTrack在阈值图像中查找角点。然而,由于对比度较低,图像中存在大量噪声,图像角部存在一些光学效应。虽然我可以找到通道的各个角落,但它们在一帧一帧地移动。我跟踪了每个帧中相对于从calcOpticalFlowPyrLK计算的第一帧的x和y像素偏移量,并使用EstimaterialGidTransform计算刚性变换。在这个图中,我可以看到0:200帧的低频漂移,以及第225帧附近的急剧跳跃。这些跳跃与视频中观察到的相符。但是,大量噪声(振幅约为5-10像素)与视频中观察到的不匹配。如果我将这些变换应用到我的图像堆栈中,反而会增加抖动,这不会稳定图像。此外,如果我尝试计算从一帧到下一帧(而不是从所有帧到第一帧)的变换,在处理少量帧后,我将得到刚性变换矩阵的
None
返回,这可能是因为噪声阻止了刚性变换的计算

下面是我如何计算转换的示例:

# Load required libraries
import numpy as np
from skimage.external import tifffile as tif
import os
import cv2
import matplotlib.pyplot as plt
from sklearn.externals._pilutil import bytescale

#Read in file and convert to 8-bit so it can be processed
os.chdir(r"C:\Path\to\my\processingfolder\inputstack")
inputfilename = "mytestfile.tif"
input_image = tif.imread(inputfilename)
input_image_8 = bytescale(input_image)
n_frames, vid_height, vid_width = np.shape(input_image_8)


transforms = np.zeros((n_frames-1,3),np.float32)
prev_image = starting_image
prev_f = cv2.bilateralFilter(prev_image,9,75,75)
prev_t = cv2.adaptiveThreshold(prev_f,255,cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY,49,2)
prev_pts = cv2.goodFeaturesToTrack(prev_t,maxCorners=100,qualityLevel=0.5,minDistance=10,blockSize=25,mask=None)

for i in range(1,n_frames-2):

    curr_image = input_image_8[i]
    curr_f = cv2.bilateralFilter(curr_image,9,75,75)
    curr_t = cv2.adaptiveThreshold(curr_f,255,cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY,49,2)

    #Detect features through optical flow:
    curr_pts, status, err = cv2.calcOpticalFlowPyrLK(prev_t,curr_t,prev_pts,None)

    #Sanity check 
    assert len(prev_pts) == len(curr_pts)
    #Filter to only the valid points
    idx = np.where(status==1)[0]
    prev_pts = prev_pts[idx]
    curr_pts = curr_pts[idx]

    #Find transformation matrix
    m = cv2.estimateRigidTransform(prev_pts,curr_pts, fullAffine=False) #will only work with OpenCV-3 or less

    # Extract translation
    dx = m[0,2]
    dy = m[1,2]

    # Extract rotation angle
    da = np.arctan2(m[1,0], m[0,0])

    # Store transformation
    transforms[i] = [dx,dy,da]

    print("Frame: " + str(i) +  "/" + str(n_frames) + " -  Tracked points : " + str(len(prev_pts)))
如何以不同的方式处理图像,以便在检测角点时不产生噪音的情况下挑出这些通道的线条?这种稳定/校准不需要在运行中进行,它可以在事后应用于整个堆栈