def query_rois_save_to_file(im, n=5): """ Save coordinates of the ROIs to use for pointing correction of a dataset. Args: im: path to the folder containing the Pleiades images. Be careful, the path should not end by a '/' n: number of ROIs to query Returns: nothing. It saves the (x, y, w, h) of each ROI in a txt file named pointing_correction_rois.txt, one per line """ rpc = '%s/../rpc/%s/rpc01.xml' % (os.path.dirname(im), os.path.basename(im)) prev = os.path.join(im, 'prev01.jpg') filename = os.path.join(im, 'pointing_correction_rois.txt') out = np.zeros((n, 4)) for i in range(n): x, y, w, h = common.get_roi_coordinates(rpc, prev) out[i, :] = x, y, w, h np.savetxt(filename, out, '%d')
def filtered_sift_matches_full_img(im1, im2, rpc1, rpc2, flag='automatic', prev1=None, a=1000, x=None, y=None, w=None, h=None, outfile=None, model='fundamental'): """ Computes a list of sift matches between two full Pleiades images. Args: im1, im2: paths to the two Pleiades images (usually jp2 or tif) rpc1, rpc2: two instances of the rpc_model.RPCModel class flag: 'automatic', 'interactive' or 'load', to decide if the five zones used to search keypoints are queried interactively, chosen automatically, or loaded from the file 'pointing_correction_rois.txt'. prev1 (optional): path to the jpg preview image of im1 (used in case of interactive mode) a: length of the squared tiles used to extract sift points, in the case of automatic mode x, y, w, h (optional): use a big ROI and extract the five tiles from there instead of from the full image. outfile (optional): path to a txt where to save the list of matches. model (optional, default is 'fundamental'): model imposed by RANSAC when searching the set of inliers Returns: matches: 2D numpy array containing a list of matches. Each line contains one pair of points, ordered as x1 y1 x2 y2. The coordinate system is that of the big images. If no sift matches are found, then an exception is raised. The keypoints are extracted from five zones in the first image. One in the center, and four in the corners. The matches are consistent with an epipolar model in each of the zones. """ # if no big ROI is defined, use the full image if x is None: x = 0 y = 0 w = rpc1.lastCol h = rpc1.lastRow # initialize output array out = np.zeros(shape = (1, 4)) if flag == 'automatic': # if roi size is too big wrt image size, take a smaller roi size if (min(h, w) < 4*a): a = round(min(h, w)/4) # central zone x0 = round((w-a)/2) + x y0 = round((h-a)/2) + y try: matches = filtered_sift_matches_roi(im1, im2, rpc1, rpc2, x0, y0, a, a, model) out = np.vstack((out, matches)) except Exception as e: print "no matches in the central zone" print e # corner zones x0 = round((1*w - 2*a)/4) + x y0 = round((1*h - 2*a)/4) + y try: matches = filtered_sift_matches_roi(im1, im2, rpc1, rpc2, x0, y0, a, a, model) out = np.vstack((out, matches)) except Exception as e: print "no matches in the corner 1" print e x0 = round((3*w - 2*a)/4) + x y0 = round((1*h - 2*a)/4) + y try: matches = filtered_sift_matches_roi(im1, im2, rpc1, rpc2, x0, y0, a, a, model) out = np.vstack((out, matches)) except Exception as e: print "no matches in the corner 2" print e x0 = round((1*w - 2*a)/4) + x y0 = round((3*h - 2*a)/4) + y try: matches = filtered_sift_matches_roi(im1, im2, rpc1, rpc2, x0, y0, a, a, model) out = np.vstack((out, matches)) except Exception as e: print "no matches in the corner 3" print e x0 = round((3*w - 2*a)/4) + x y0 = round((3*h - 2*a)/4) + y try: matches = filtered_sift_matches_roi(im1, im2, rpc1, rpc2, x0, y0, a, a, model) out = np.vstack((out, matches)) except Exception as e: print "no matches in the corner 4" print e if flag == 'interactive': for i in range(5): x, y, w, h = common.get_roi_coordinates(rpc1, prev1) try: matches = filtered_sift_matches_roi(im1, im2, rpc1, rpc2, x, y, w, h, model) out = np.vstack((out, matches)) except Exception as e: print "no matches in the selected roi" print e if flag == 'load': im = os.path.dirname(im1) fname = os.path.join(im, 'pointing_correction_rois.txt') rois = np.loadtxt(fname) for i in xrange(len(rois)): x, y, w, h = rois[i, :] try: matches = filtered_sift_matches_roi(im1, im2, rpc1, rpc2, x, y, w, h, model) out = np.vstack((out, matches)) except Exception as e: print "no matches in the selected roi" print e # save and return the full list of matches, only if there are enough if len(out) < 7: raise Exception("not enough matches") else: if outfile is not None: np.savetxt(outfile, out[1:, :]) return out[1:, :]