将具有完全匹配(像素到像素)重叠的图像拼接在一起

Muh*_*uhd 6 python java wolfram-mathematica image-processing image-stitching

我在一个文件夹中有一堆图像,它们实际上只是一个被分成重叠部分的图像的片段。如何快速并以编程方式重新组合这些图像以创建原始图像?

我更喜欢使用 python 或 mathematica(或者是现有应用程序)的解决方案,但我也愿意接受其他想法(我相当精通 Java)。

Muh*_*uhd 1

好吧,我不再需要这样做来完成我想做的事情,但我将分享如果我用 python(伪代码和 python 的混合)编写它,我将如何做到这一点。在这里,我假设后续图像的左上角始终是重叠点(在我的情况下是这样)。如果您想检测任何角落的重叠,则需要检测您所在的“角落”情况并为每个情况添加处理。

images = list of images to be stitched, loaded from directory
stitched_image = images[0]

for (image in images):
    if first image then skip it (continue)
    else combine_images(stitched_image, image)

def combine_images (stitched_image, image_to_add):
    top_left_corner = top left corner of image_to_add 
    // top_left_corner dimensions need to be big enough that you don't have a false positive, 
    // but not so big that the overlap doesn't exist
    coordinates = find_coordinates(stitched_image,top_left_corner)

    new_width = max(stitched_image.width,image_to_add.width + coordinates.x)
    new_height = max(stitched_image.height,image_to_add.width + coordinates.y)
    new_image = new Image(new_width,new_height) // See note 1
    new_image.paste(stitched_image,(0,0))
    new_image.paste(image_to_add,(coordinates.x,coordinates.y))

    stitched_image = new_image

def find_coordinates (image,sub_image):
    // See note 2 below for how to implement
Run Code Online (Sandbox Code Playgroud)

笔记:

  1. 创建图像并粘贴到其中可以使用 PIL 来完成:http://29a.ch/2009/5/14/concatenating-images-using-python

  2. 有关如何在图像中查找 sub_image 的信息,请参阅此问题(可能需要将图像转换为另一种表示形式):Finding a subimage inside a Numpy image。此外,对于任何熟练的程序员来说,手动检查像素矩阵中的像素以找到重叠部分并不困难。如果您通过简单地首先搜索更可能的区域来粗略地知道可能发生重叠的位置,则可以添加额外的优化。