首页 \ 问答 \ 在图像对齐之前首先进行亮度/对比度校正,反之亦然?(Brightness/contrast correction first before image alignment or vice versa?)

在图像对齐之前首先进行亮度/对比度校正,反之亦然?(Brightness/contrast correction first before image alignment or vice versa?)

需要你的帮助以下。 我有3个相同的静止物体图像,每隔30分钟捕获一次。 我已将相机和物体锁定在适当的位置,房间仍然是黑暗的,但我仍然得到了3种不同的曝光/亮度/伽玛图像,物体也移动了一点。 Image1 Image2

我试图做的是调整对准,亮度/伽马/对比度第2和第3张图像参考第1张图像。 我有如何使用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图像对齐,以便我可以准确地调整图像的亮度/曝光吗?

要么

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

我仍在考虑参考第一张图像来调整我的第二和第三图像亮度/曝光。 任何想法都受到欢迎和赞赏!!!!


need your help with the following. I have 3 same stationary object image that were captured per 30mins interval. I have lock the camera and object in position and the room was left dark but still I ended up with 3 different exposure/brightness/gamma images and the object move a little as well. Image1 Image2

What I was trying to do is to adjust alignment, brightness/gamma/contrast 2nd and 3rd images in reference to 1st images. I have solution on how to align the image using ECCtransform method below:

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()

My question are, which is the better way to go? Is the sequence matter? By taking first image as standard reference:

Should I perform transformECC image alignment first so that I can adjust the brightness/exposure of my images accurately?

OR

I should adjust the brightness/exposure first so that I aligned the photo accurately?

I am still thinking way to adjust my 2nd and 3rd images brightness/exposure with reference to 1st images. Any ideas is welcomed and appreciated !!!!


原文:https://stackoverflow.com/questions/45179304
更新时间:2022-11-19 10:11

最满意答案

您需要在基类中使用虚拟析构函数,以便在运行时找到并调用派生类的析构函数。 有关详细信息,请参阅此问题和答案


You need a virtual destructor in the base class so the destructor of the derived class is found and called at runtime. See this question and answer for more detail.

相关问答

更多
  • 是的, 如果且仅当基类析构函数是虚拟的,那么这个工作将是基础类,而不是为IFoo基类。 如果基类析构函数是虚拟的,那么当在基类指针上调用operator delete时,它将使用动态调度来查找如何通过查找虚函数表中的派生类析构函数来删除该对象。 在多重继承的情况下,只有通过删除它的基类具有虚拟析构函数时,它才会工作; 其他基类没有虚拟析构函数可以,但只有当您不尝试通过其他基类指针删除任何派生对象时,才可以。 Yes, it will work, if and only if the base class d ...
  • 您需要在基类中使用虚拟析构函数,以便在运行时找到并调用派生类的析构函数。 有关详细信息,请参阅此问题和答案 。 You need a virtual destructor in the base class so the destructor of the derived class is found and called at runtime. See this question and answer for more detail.
  • 您的内存泄漏最有可能在析构函数中找到。 当队列消失时,队列中的对象会发生什么? Your memory leak can most likely be found in the destructor. What happens to the objects in the queue when the queue goes away?
  • 从你显示的内存管理似乎没有,似乎没有泄漏内存。 我是否释放了分配给旧指针的空间 是的,代码解除分配,释放到内存old点,这通常被称为分配给指针的内存 。 free(*old)不起作用,因为它不会编译,因为你试图将struct传递到预期指针的位置。 free(&old)不起作用,因为它会引发未定义的行为,因为代码试图释放堆栈上分配的内存,即指针变量old本身的内存。 From what you show the memory management seems OK and does not seem to l ...
  • reportError()应该在switchSystem声明为virtual,因为它在errorContainer 。 char*应该是std::string以避免所有不必要的工作。 是否有某些原因你不能使用std::vector而不是new[] ? 当指向静态文字字符串时,不应delete[] errorMessage 。 这导致未定义的行为。 (翻译:Bad Thing(TM)。) 为什么要迭代计算和复制char*的内容? 这是在乞求麻烦。 你没有做任何事来保护自己免受伤害。 ...
  • pArray仍然是DynamicArray类型,并且wiil调用正确的析构函数,这可能会泄漏: std::vector* wrong = static_cast*>(pArray); delete wrong; 编辑:正如Ben Voigt正确提到的那样,这个最后的代码片段实际上是未定义的行为,因为std::vector的析构函数不是虚拟的。 所以甚至不能保证这会泄漏 pArray is still of type DynamicArray ...
  • 首先,您只需要delete使用new创建的对象。 一般来说, new创建的对象没有顺序依赖。 但是,可能存在构造函数/析构函数依赖项,例如foo2在foo2的析构函数中调用foo1上的函数。 在这种情况下,破坏的顺序很重要。 其次,即使foo2中的foo1指针设置为null,这只是foo2中保存的指针的本地副本。 它不会影响指针的其他副本。 在foo2中将foo1设置为null并不是一个坏主意,因为它表示不应再使用该对象,但这与调用其析构函数或free它不同。 First, you only need to ...
  • 如果我正确理解你的问题,一个可能的解决方案是使用聚合而不是继承。 class Base {/*has only the data*/} class Derived { Base &base; Derived(Base &b) : base(b) {} //now methods from derived will use the data members from instance passed in constructor //if is possible the De ...
  • 这是未定义的行为。 C ++标准说 : 3.7.4.2解除分配功能 3 ...否则,如果标准库中提供给operator delete(void*)的值不是先前调用operator new(std::size_t)或operator new(std::size_t, const std::nothrow_t&)返回值)的返回值之一,则行为不确定标准库中的operator new(std::size_t, const std::nothrow_t&) ,如果标准库中提供给operator delete[](vo ...
  • IQueue *sq = new Queue(); IQueue *sq2 = new Queue(); sq2 = sq; 第一次内存泄漏。 你失去了指向sq2对象的指针。 IQueue *iq = new Queue(); IQueue *iq2 = new Queue(); iq2 = iq; 第二次内存泄漏。 与上面相同。 现在,如果删除指向iq1或iq2的指针,则会出现第三次泄漏,因为您的接 ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)