In order to see negative regions of my warped image I shifted them by minx and miny…
- User
In order to see negative regions of my warped image I shifted them by min_x and min_y values. Now I can see negative regions however my image merging code was taking warped images and adding them on top of each other. Since the region of interest was almost at the top most part of the image it was aligning perfectly. However in order to see negative regions and rest of the data, we also shifted the region of interest. So my image merging code, when it adds images on top of one another as they are, now they do not align. I need a solution which will account for the warped images shift and when constructing panorama, aligns them on top of one another. We can calculate where the region of interest simply by looking at the min_x and min_y value as they are used for shifting. However another side note is the panorama image at the end result should also show the negative regions. I will give you my full code, so look in to a solution please: "import numpy as np import cv2 import os import glob import matplotlib.pyplot as plt import time from kayla_tools import *
def compute_homography_matrix(src_pts, dst_pts): def normalize_points(pts): pts_homogeneous = np.hstack((pts, np.ones((pts.shape[0], 1)))) centroid = np.mean(pts, axis=0) scale = np.sqrt(2) / np.mean(np.linalg.norm(pts - centroid, axis=1)) T = np.array([[scale, 0, -scale * centroid[0]], [0, scale, -scale * centroid[1]], [0, 0, 1]]) normalized_pts = (T @ pts_homogeneous.T).T return normalized_pts[:, :2], T
codesrc_pts_normalized, T1 = normalize_points(src_pts) dst_pts_normalized, T2 = normalize_points(dst_pts) A = [] for p1, p2 in zip(src_pts_normalized, dst_pts_normalized): x1, y1 = p1 x2, y2 = p2 A.append([0, 0, 0, -x1, -y1, -1, y2 * x1, y2 * y1, y2]) A.append([x1, y1, 1, 0, 0, 0, -x2 * x1, -x2 * y1, -x2]) A = np.array(A) try: _, _, VT = np.linalg.svd(A) except np.linalg.LinAlgError: return None h = VT[-1] H_normalized = h.reshape(3, 3) H = np.linalg.inv(T2) @ H_normalized @ T1 if np.abs(H[-1, -1]) > 1e-6: H = H / H[-1, -1] else: return None return Hdef filter_matches(matches, ratio_thres=0.7): filtered_matches = [] for match in matches: good_match = [] for m, n in match: if m.distance < ratio_thres * n.distance: good_match.append(m) filtered_matches.append(good_match)
codereturn filtered_matchesdef find_homography(keypoints, filtered_matches): homographies = [] skipped_indices = [] # Keep track of skipped images and their indices
- Assistant
You can try the following code modifications in your merging function. It adds the image shifts defined by their respective min_x and min_y values based on the warping.
- User
your idea is nice but I got error in image_merging(images, homographies) 213 mask = np.all(img == 0, axis=-1) 214 merged_image_slice = merged_image[y_offset:y_offset + img_h, x_offset:x_offset + img_w] --> 215 merged_image_slice[~mask] = img[~mask] 216 217 return merged_image
IndexError: boolean index did not match indexed array along dimension 1; dimension is 995 but corresponding boolean dimension is 1068
- Assistant
I apologize for the confusion. It seems that the dimensions of the mask and the merged_image_slice do not match. To fix this issue, you can update the 'image_merging()' function as follows:
python
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.