I have 2 images of size 1920*1080 and I want to try image-stitching on them. These are images (images are from wind turbine blade.)

This is the first image

image 1

And the second image.

image 2

I already have found and used plenty of github repositoties that have implemented the image stitching on directory of images, but my images as you can see are very similar and I decided to do it myself. one thing that might come in handy is that image 2 has to be stitched in bottom of image 1 in the way that remove the overlapped parts.

How can I use this point to use in my code here:


import os
import argparse
import logging

import cv2

import image_stitching

if __name__ == '__main__':
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument('image_paths', type=str, nargs='+', help="paths to one or more images or image directories")
    parser.add_argument('-b', '--debug', dest='debug', action='store_true', help='enable debug logging')
    parser.add_argument('-q', '--quiet', dest='quiet', action='store_true', help='disable all logging')
    parser.add_argument('-d', '--display', dest='display', action='store_true', help="display result")
    parser.add_argument('-s', '--save', dest='save', action='store_true', help="save result to file")
    parser.add_argument("--save_path", dest='save_path', default="stitched.png", type=str, help="path to save result")
    parser.add_argument('-k', '--knn', dest='knn', default=2, type=int, help="Knn cluster value")
    parser.add_argument('-l', '--lowe', dest='lowe', default=0.7, type=float, help='acceptable distance between points')
    parser.add_argument('-m', '--min', dest='min_correspondence', default=10, type=int, help='min correspondences')
    args = parser.parse_args()

    if args.debug:
    logger = logging.getLogger("main")

    logging.info("beginning sequential matching")

    if image_stitching.helpers.is_cv2():
        sift = cv2.SIFT()
    elif image_stitching.helpers.is_cv3():
        sift = cv2.xfeatures2d.SIFT_create()
        raise RuntimeError("error! unknown version of python!")

    result = None
    result_gry = None

    flann = cv2.FlannBasedMatcher({'algorithm': 0, 'trees': 5}, {'checks': 50})

    image_paths = args.image_paths
    image_index = -1
    for image_path in image_paths:
        if not os.path.exists(image_path):
            logging.error('{0} is not a valid path'.format(image_path))
        if os.path.isdir(image_path):
            extensions = [".jpeg", ".jpg", ".png"]
            for file_path in os.listdir(image_path):
                if os.path.splitext(file_path)[1].lower() in extensions:
                    image_paths.append(os.path.join(image_path, file_path))

        logging.info("reading image from {0}".format(image_path))
        image_colour = cv2.imread(image_path)
        image_gray = cv2.cvtColor(image_colour, cv2.COLOR_RGB2GRAY)

        image_index += 1

        if image_index == 0:
            result = image_colour
            result_gry = image_gray

        logger.debug('computing sift features')
        features0 = sift.detectAndCompute(result_gry, None)
        features1 = sift.detectAndCompute(image_gray, None)

        matches_src, matches_dst, n_matches = image_stitching.compute_matches(features0, features1, flann, knn=args.knn)

        if n_matches < args.min_correspondence:
            logger.error("error! too few correspondences")

        logger.debug("computing homography between accumulated and new images")
        H, mask = cv2.findHomography(matches_src, matches_dst, cv2.RANSAC, 5.0)
        result = image_stitching.combine_images(image_colour, result, H)

        if args.display and not args.quiet:
            image_stitching.helpers.display('result', result)
            if cv2.waitKey(25) & 0xFF == ord('q'):

        result_gry = cv2.cvtColor(result, cv2.COLOR_RGB2GRAY)

    logger.info("processing complete!")

    if args.display and not args.quiet:
    if args.save:
        logger.info("saving stitched image to {0}".format(args.save_path))
        image_stitching.helpers.save_image(args.save_path, result)
  • $\begingroup$ Are the two images cross registered already? $\endgroup$ – A_A May 23 at 10:01
  • $\begingroup$ There are total number of 15 images. the images above are the shots right behind each other. As I mentioned in question "image 2 has to be stitched in bottom of image 1". $\endgroup$ – Masoud Masoumi Moghadam May 23 at 10:05
  • $\begingroup$ @MasoudMasoumiMoghadam that doesn't answer A_A's question, sadly. $\endgroup$ – Marcus Müller May 23 at 17:28
  • $\begingroup$ @MarcusMüller Sorry.I don't know what does cross-registered mean! $\endgroup$ – Masoud Masoumi Moghadam May 23 at 17:58
  • $\begingroup$ It means that you have determined points in both images that are the the same points. $\endgroup$ – Marcus Müller May 24 at 14:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.