-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMatchImages - Copy.py
73 lines (55 loc) · 2.24 KB
/
MatchImages - Copy.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import os
#import cv2
import numpy as np
import matplotlib.pyplot as plt
from skimage.color import rgb2gray
import time
from skimage.feature import ORB, match_descriptors
from skimage.measure import ransac
from skimage.transform import SimilarityTransform
from skimage.transform import warp
from skimage.io import imread, imsave
########################################################################33
def alignImages(image0, image1):
image0 = rgb2gray(image0)
image1 = rgb2gray(image1)
orb = ORB(n_keypoints=500, fast_threshold=0.05)
print(" detect im0")
orb.detect_and_extract(image0)
keypoints1 = orb.keypoints
descriptors1 = orb.descriptors
print(" detect im1")
orb.detect_and_extract(image1)
keypoints2 = orb.keypoints
descriptors2 = orb.descriptors
matches12 = match_descriptors(descriptors1, descriptors2, cross_check=True)
# Select keypoints from the source (image to be registered)
# and target (reference image)
src = keypoints2[matches12[:, 1]][:, ::-1]
dst = keypoints1[matches12[:, 0]][:, ::-1]
model_robust, inliers = ransac((src, dst), SimilarityTransform,
min_samples=4, residual_threshold=1, max_trials=300)
print("Matched points found = {}".format(inliers.size))
return (model_robust)
###################################################################################
if __name__ == "__main__":
image_files = sorted(os.listdir("input"))
for img in image_files:
if img.split(".")[-1].lower() not in ["jpg", "jpeg", "png"]:
image_files.remove(img)
images = []
for img in image_files:
print ("Reading in file {}".format(img))
images.append(imread("input/{}".format(img)))
n = 0
print("Image {}".format(n))
imsave("aligned/aligned{:02d}.jpg".format(n), images[n])
for n in range (1, len(images) ):
print("Image align {}".format(n))
model_robust = alignImages(images[n-1], images[n])
print(" warping")
images[n] = warp(images[n], model_robust.inverse)
images[n] = np.uint8(images[n]*255.0)
imsave("aligned/aligned{:02d}.jpg".format(n), images[n])
print(" Image save {}".format(n))
print ("That's All Folks!")