Brightness/contrast 在图像对齐之前先校正还是反之?

Brightness/contrast correction first before image alignment or vice versa?

在以下方面需要您的帮助。我有 3 个相同的静止物体图像,每 30 分钟间隔捕获一次。我已将相机和物体锁定到位,房间里一片漆黑,但我仍然得到了 3 张不同的 exposure/brightness/gamma 图像,并且物体也稍微移动了一点。 Image1 Image2

我想做的是调整对齐方式,brightness/gamma/contrast 第二张和第三张图片参考第一张图片。我有关于如何使用下面的 ECCtransform 方法对齐图像的解决方案:

import os, sys
import cv2
from PIL import Image
import numpy as np

path = "C:\Users\xxxx\Desktop\"
path1 = "C:\Users\xxxx\Desktop\aligned\"

def alignment():
    for i in range(1,4):
        # Read the images to be aligned
        im1 =  cv2.imread(path + '1.png')
        im2 =  cv2.imread(path + '%d.png' %(i))
        print(i)

        # Convert images to grayscale
        im1_gray = cv2.cvtColor(im1,cv2.COLOR_BGR2GRAY)
        im2_gray = cv2.cvtColor(im2,cv2.COLOR_BGR2GRAY)

        # Find size of image1
        sz = im1.shape

        # Define the motion model
        warp_mode = cv2.MOTION_TRANSLATION

        # Define 2x3 or 3x3 matrices and initialize the matrix to identity
        if warp_mode == cv2.MOTION_HOMOGRAPHY :
            warp_matrix = np.eye(3, 3, dtype=np.float32)
        else :
            warp_matrix = np.eye(2, 3, dtype=np.float32)
        # Specify the number of iterations.
        number_of_iterations = 5000;

        # Specify the threshold of the increment
        # in the correlation coefficient between two iterations
        termination_eps = 1e-10;

        # Define termination criteria
        criteria = (cv2.TERM_CRITERIA_EPS | cv2.TERM_CRITERIA_COUNT, number_of_iterations,  termination_eps)

        # Run the ECC algorithm. The results are stored in warp_matrix.
        (cc, warp_matrix) = cv2.findTransformECC(im1_gray, im2_gray, warp_matrix, warp_mode, criteria)


        if warp_mode == cv2.MOTION_HOMOGRAPHY :
            # Use warpPerspective for Homography 
            im2_aligned = cv2.warpPerspective (im2, warp_matrix, (sz[1],sz[0]), flags=cv2.INTER_LINEAR + cv2.WARP_INVERSE_MAP)
        else :
            # Use warpAffine for Translation, Euclidean and Affine
            im2_aligned = cv2.warpAffine(im2, warp_matrix, (sz[1],sz[0]), flags=cv2.INTER_LINEAR + cv2.WARP_INVERSE_MAP);

        cv2.imwrite(path1 + "%d.png" % (i), im2_aligned )

alignment()

我的问题是,哪种方式更好?顺序重要吗? 以第一张图为标准参考:

我是否应该先执行 transformECC 图像对齐,以便我可以准确调整图像的 brightness/exposure?

我应该先调整 brightness/exposure 以便准确对齐照片吗?

我还在想办法参考第一张图片调整我的第二张和第三张图片brightness/exposure。欢迎和赞赏任何想法!!!!

对于用于对齐的大多数成本函数,我鼓励您进行预处理(值得注意的例外情况包括互信息)。然而,findTransformEcc 使用的增强互相关似乎对光度失真具有鲁棒性(引用http://ieeexplore.ieee.org/abstract/document/4515873/:"In this work we propose the use of a modified version of the correlation coefficient as a performance criterion for the image alignment problem. The proposed modification has the desirable characteristic of being invariant with respect to photometric distortions.")因此,在之前或之后进行光度调整应该没问题。