def main(): folder = 'test_img/' filename = '1Hill.JPG' img_left = Image.open(folder + filename).convert('RGB') img_left = np.array(img_left) filename = '2Hill.JPG' img_center = Image.open(folder + filename).convert('RGB') img_center = np.array(img_center) filename = '3Hill.JPG' img_right = Image.open(folder + filename).convert('RGB') img_right = np.array(img_right) imgs = np.array(np.zeros((3)), dtype=object) imgs[0] = img_left imgs[1] = img_center imgs[2] = img_right img_mosaic = mymosaic(imgs) plt.title('Final image') plt.imshow(img_mosaic) plt.show()
def stitching(): # load images print("Opening images...") sample1 = np.array(Image.open("test_img/1L.jpg").convert('RGB')) sample2 = np.array(Image.open("test_img/1M.jpg").convert('RGB')) sample3 = np.array(Image.open("test_img/1R.jpg").convert('RGB')) philly1 = np.array(Image.open("images/philly-3.jpg").convert('RGB')) philly2 = np.array(Image.open("images/philly-4.jpg").convert('RGB')) philly3 = np.array(Image.open("images/philly-5.jpg").convert('RGB')) # First mosaic: sample pics image_inputs = np.array([sample1, sample2, sample3]).astype(np.ndarray) mosaic1 = mymosaic(image_inputs) # Second mosaic: custom pics image_inputs = np.array([philly1, philly2, philly3]).astype(np.ndarray) mosaic2 = mymosaic(image_inputs)
im_path = os.path.join(folder, filename) reader = imageio.get_reader(im_path) # if it is the first video if numV == 0: for i, im in enumerate(reader): img_input.append([im]) lastone = im lennow = len(reader) while lennow < maxi: img_input.append([lastone]) lennow = lennow + 1 numV = numV + 1 # next videos else: for i, im in enumerate(reader): img_input[i].append(im) lastone = im lennow = len(reader) while lennow < maxi: img_input[lennow].append(lastone) lennow = lennow + 1 img_input1 = [] for i in range(0, len(img_input) // 5): img_input1.append(img_input[i * 5]) print("import video done!") img_mosaic = mymosaic(img_input1) myvideomosaic(img_mosaic)
import numpy as np from PIL import Image from mymosaic import mymosaic import scipy.misc if __name__ == '__main__': I0 = np.array(Image.open("Test1_left.jpg").convert('RGB')) I0 = scipy.misc.imresize(I0, [300, 400]) I1 = np.array(Image.open("Test1_middle.jpg").convert('RGB')) I1 = scipy.misc.imresize(I1, [300, 400]) I2 = np.array(Image.open("Test1_right.jpg").convert('RGB')) I2 = scipy.misc.imresize(I2, [300, 400]) input_img = [I0, I1, I2] mymosaic(input_img)
x1 = x1[goodmask] y1 = y1[goodmask] X1 = np.copy(x1) Y1 = np.copy(y1) X2 = np.zeros((x1.shape)) Y2 = np.zeros((y1.shape)) X2 = x2[npgood] Y2 = y2[npgood] H32, inlier_ind = ransac_est_homography(X1, Y1, X2, Y2, 0.7) print(H32) plot_image_matching(X1, Y1, X2, Y2, img3_cyl, img2_cyl) ################################################################################ # img1 = cv2.imread('hill1.jpg') # img2 = cv2.imread('hill2.jpg') # img3 = cv2.imread('hill3.jpg') # img1 = cv2.imread('.png') # img2 = cv2.imread('hill2_cyl.png') # img3 = cv2.imread('hill3_cyl.png') finalOP = mymosaic(img1_cyl, img2_cyl, img3_cyl, H12, H32) cv2.imwrite("collegeGreen_affine_final_uncarved.jpg", finalOP) # if __name__ == '__main__': # img1 = cv2.imread('hill1_cyl.png') # img2 = cv2.imread('hill2_cyl.png') # img3 = cv2.imread('hill3_cyl.png')
def main(): max_pts = 1000 left_image_filename = 'building1.JPG' middle_image_filename = 'building2.JPG' right_image_filename = 'building3.JPG' img_left, gray_left = open_image(left_image_filename) img_middle, gray_middle = open_image(middle_image_filename) img_right, gray_right = open_image(right_image_filename) corners_left = corner_detector(gray_left) corners_middle = corner_detector(gray_middle) corners_right = corner_detector(gray_right) plotting_img_left = np.copy(img_left) plotting_img_middle = np.copy(img_middle) plotting_img_right = np.copy(img_right) print('co', corners_left, corners_left.shape) plotting_img_left[corners_left >= 0.01 * np.max(corners_left)] = [ 255, 0, 0 ] plotting_img_middle[corners_middle >= 0.01 * np.max(corners_left)] = [ 255, 0, 0 ] plotting_img_right[corners_right >= 0.01 * np.max(corners_left)] = [ 255, 0, 0 ] plot_corner_harris(plotting_img_left, 'corner_harris_left_2') plot_corner_harris(plotting_img_middle, 'corner_harris_middle_2') plot_corner_harris(plotting_img_right, 'corner_harris_right_2') x_left, y_left = anms(corners_left, max_pts) x_middle, y_middle = anms(corners_middle, max_pts) x_right, y_right = anms(corners_right, max_pts) plot_anms(img_left, x_left, y_left) plot_anms(img_middle, x_middle, y_middle) plot_anms(img_right, x_right, y_right) desc_left = feat_desc(gray_left, x_left, y_left) desc_middle = feat_desc(gray_middle, x_middle, y_middle) desc_right = feat_desc(gray_right, x_right, y_right) matched_index_left_middle = feat_match(desc_left, desc_middle) x1 = x_left[matched_index_left_middle != -1] y1 = y_left[matched_index_left_middle != -1] x2 = x_middle[matched_index_left_middle[matched_index_left_middle != -1]] y2 = y_middle[matched_index_left_middle[matched_index_left_middle != -1]] thresh = 0.5 H12, inlier_ind = ransac_est_homography(x1, y1, x2, y2, thresh) bx1 = x1[inlier_ind == 0] by1 = y1[inlier_ind == 0] bx2 = x2[inlier_ind == 0] by2 = y2[inlier_ind == 0] x1 = x1[inlier_ind != 0] y1 = y1[inlier_ind != 0] x2 = x2[inlier_ind != 0] y2 = y2[inlier_ind != 0] plot_image_matching(x1, y1, x2, y2, bx1, by1, bx2, by2, img_left, img_middle) matched_index_right_middle = feat_match(desc_right, desc_middle) x1 = x_right[matched_index_right_middle != -1] y1 = y_right[matched_index_right_middle != -1] x2 = x_middle[matched_index_right_middle[matched_index_right_middle != -1]] y2 = y_middle[matched_index_right_middle[matched_index_right_middle != -1]] thresh = 1 H32, inlier_ind = ransac_est_homography(x1, y1, x2, y2, thresh) bx1 = x1[inlier_ind == 0] by1 = y1[inlier_ind == 0] bx2 = x2[inlier_ind == 0] by2 = y2[inlier_ind == 0] x1 = x1[inlier_ind != 0] y1 = y1[inlier_ind != 0] x2 = x2[inlier_ind != 0] y2 = y2[inlier_ind != 0] plot_image_matching(x1, y1, x2, y2, bx1, by1, bx2, by2, img_right, img_middle) mymosaic(img_left, img_middle, img_right, H12, H32)