如何使用python脚本正确校正XY图像漂移?

如何使用python脚本正确校正XY图像漂移?,python,image-processing,fft,scikit-image,cross-correlation,Python,Image Processing,Fft,Scikit Image,Cross Correlation,我是新的编码,这是我的第一篇文章! 作为第一个严肃的任务,我正在尝试用python实现一个简单的图像漂移校正例程(因此我不需要依赖ImageJ插件),使用诸如寄存器转换和傅立叶移位之类的略读功能 下面你可以找到我到目前为止所做的, 但以下是我关于该方法的主要问题: 移位校正是否应用良好 .当我们通过FFT应用互相关峰值来识别相对位移时,我不清楚的一件事是,这种方法如何区分“伪影”图像漂移和真实物体运动?(即实际像素强度偏移) 。我测量了每两幅连续图像的漂移,并相应地校正了时间推移。有更好的方法吗

我是新的编码,这是我的第一篇文章! 作为第一个严肃的任务,我正在尝试用python实现一个简单的图像漂移校正例程(因此我不需要依赖ImageJ插件),使用诸如寄存器转换和傅立叶移位之类的略读功能

下面你可以找到我到目前为止所做的, 但以下是我关于该方法的主要问题:

移位校正是否应用良好

.当我们通过FFT应用互相关峰值来识别相对位移时,我不清楚的一件事是,这种方法如何区分“伪影”图像漂移和真实物体运动?(即实际像素强度偏移)

。我测量了每两幅连续图像的漂移,并相应地校正了时间推移。有更好的方法吗

。到目前为止,我认为我至少部分地纠正了我的电影中的漂移,但最终输出仍然显示随机方向上的1像素漂移,并且我的tiff电影看起来像是“闪烁”(由于像素)。但是我应该用另一种方式应用漂移修正

期待有一些见解,不仅是针对我的具体问题,而且是针对这个主题的总体看法

# import the basics

import numpy as np
import matplotlib.pyplot as plt
from skimage import data
from skimage.feature import register_translation
from scipy.ndimage import fourier_shift
from skimage import io

'''  register translation estimates the cross-correlation peak by an FFT
i.e, identifies the relative shift between two similar-sized images
using cross-correlation in Fourier space '''

movie = mymovie
shifts = []
corrected_shift_movie = []

for img in range(0,movie.shape[0]):
    if img < movie.shape[0] - 1:

        shift, error, diffphase = register_translation(movie[0], movie[img + 1])

        img_corr = fourier_shift(np.fft.fftn(movie[img + 1]), shift)
        img_corr = np.fft.ifftn(img_corr)

        shifts.append(shift)
        corrected_shift_movie.append(img_corr.real)


# for plotting the xy shifts over time

shifts = np.array(shifts)
corrected_shift_movie = np.array(corrected_shift_movie)

x_drift = [shifts[i][0] for i in range(0,shifts.shape[0])]
y_drift = [shifts[i][1] for i in range(0,shifts.shape[0])]

plt.plot(x_drift, '--g' , label = ' X drift')
plt.plot(y_drift, '--r' , label = ' Y drfit')
plt.legend()

# checking drift for the new corrected movie

movie = corrected_shift_movie
shifts_corr = []

for img in range(0,movie.shape[0]):
    if img < movie.shape[0] - 1:

        shift, error, diffphase = register_translation(movie[0], movie[img + 1])
        shifts_corr.append(shift)

shifts_corr = np.array(shifts_corr)

x_drift = [shifts_corr[i][0] for i in range(0,shifts_corr.shape[0])]
y_drift = [shifts_corr[i][1] for i in range(0,shifts_corr.shape[0])]

plt.plot(x_drift, '--g' , label = ' X drift')
plt.plot(y_drift, '--r' , label = ' Y drfit')
plt.legend()

# saving the new corrected movie

import tifffile as tiff
movie_to_save = corrected_shift_movie

with tiff.TiffWriter('drift_correction.tif', bigtiff=True) as tif:
        for new_image in range(movie_to_save.shape[0]):
            tif.save(movie_to_save[new_image], compress=0)

#导入基础知识
将numpy作为np导入
将matplotlib.pyplot作为plt导入
从浏览导入数据
从skimage.feature导入寄存器\u翻译
从scipy.ndimage导入傅立叶移位
从撇渣进口io
''寄存器转换通过FFT估计互相关峰值
i、 e,标识两个大小相似的图像之间的相对偏移
在傅里叶空间“”中使用互相关
电影=我的电影
移位=[]
已更正的\u shift\u movie=[]
对于范围内的img(0,movie.shape[0]):
如果img
请阅读您的问题非常广泛。。。好的问题零到一块显示代码的金块上,这样透视助手就可以收集知识,并因此在阅读和回答问题时获得奖励。。。同样,这样一个有重点的问题更容易被问类似问题的人搜索和发现。。。把一个好问题看作一个单一目的的方法或功能。。。欢迎来到SOi了解我下次应该更具体,对此我很抱歉:/我的目标是了解在python中实现移位校正的更有效的方法。