python - 在图像对齐之前先进行亮度/对比度校正,反之亦然?

标签 python opencv image-processing pillow scikit-image

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

我试图做的是引用第一张图像调整第二张和第三张图像的对齐、亮度/ Gamma /对比度。我有关于如何使用下面的 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 图像对齐,以便准确调整图像的亮度/曝光吗?

或者

我应该先调整亮度/曝光,以便准确对齐照片?

我仍在考虑引用第一张图像调整我的第二张和第三张图像亮度/曝光的方法。欢迎和赞赏任何想法!!!!

最佳答案

对于大多数用于对齐的成本函数,我鼓励您进行预处理(值得注意的异常(exception)包括互信息)。然而,findTransformEcc 使用的增强互相关似乎对光度失真具有鲁棒性(引用 http://ieeexplore.ieee.org/abstract/document/4515873/:“在这项工作中,我们建议使用相关系数的修改版本作为图像对齐问题的性能标准。建议修改具有相对于光度失真不变的理想特性。”)因此,在之前或之后进行光度调整应该没问题。

关于python - 在图像对齐之前先进行亮度/对比度校正,反之亦然?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45179304/

相关文章:

algorithm - k表示使用现有信息进行分割

python - 如何在 Beautifulsoup 的 find_all() 函数中过滤没有属性的标签?

JavaCV将3 channel IplImage转换为4 channel IplImage

opencv - 如何在 Haskell 中使用 fromPtr 正确构建 Accelerate 数组?

python - 频域上的同态滤波(Python 和 OpenCV)

perl - ImageMagick:寻找一种快速模糊图像的方法

python - 使用乘法和减法加密和解密图像

Python:从列表动态生成属性

python - 用第二个数组的两个值替换数组的数据

python - 如何通过 C API 在 Python 类中创建静态变量?