Algorithm to detect overlapping rows of two images

后端 未结 5 1991
借酒劲吻你
借酒劲吻你 2020-12-14 13:28

Let\'s say I have 2 images A and B as below.

\"enter

Notice that the bottom of

5条回答
  •  [愿得一人]
    2020-12-14 13:55

    If I understood correctly, you probably want to look at normalized cross correlation of greyscale versions of the two images. Where you have large images, or large overlapping regions, this is done most efficiently in the frequency domain using the FFTs of the images (or overlap areas) and is called phase correlation.

    The basic steps I would take in your situation are as follows:

    1. Extract the bottom half of the first image and the top half of the second image.
    2. Convert both image patches to greyscale.
    3. Perform FFT on each image patch (there are some details here relating to windowing and padding).
    4. Calculate the complex conjugate of the two FFTs (same as correlation in spatial domain).
    5. Do inverse FFT on the result.
    6. Find the peak in the above to get the XY shift that best aligns the two images.

    Having found the relative offset between the top and bottom image patches, you can easily calculate n as you required.

    If you want to experiment without having to code the above from scratch, OpenCV has a number of functions for template matching, which you can easily try. See here for details.

    If part of either image has been changed - e.g. by a banner ad - the above procedure still gives the best match, and the magnitude of the peak you find in step 6 gives an indication of the match "confidence" - so you can get a rough idea of how similar the two areas are.

提交回复
热议问题