def match(im): atlas = feature.im_read('scripts_testing/plate-34.jpg') if affine: kp, des = feature.extract_sift(im) kp2, des2 = feature.extract_sift(atlas) else: kp, des = sift.detectAndCompute(im, None) kp2, des2 = sift.detectAndCompute(atlas, None) match = feature.match(im, kp, des, atlas, kp2, des2) print("Matches: ", len(match.matches)) print("Inliers: ", match.inlier_count) plt.figure(figsize=(10,10)) plt.imshow(match.result) plt.figure(figsize=(10,10)) plt.imshow(match.result2) return match.H
filledLength = int(length * iteration // total) bar = fill * filledLength + '-' * (length - filledLength) print('\r%s |%s| %s%% %s' % (prefix, bar, percent, suffix), end='\r') # Print New Line on Complete if iteration == total: print() filename = 'atlas_swanson_regions/Level-34-Region.jpg' output_filename = 'results/Level-34-range2' points = 30 disp_range = range(30, 50) nissl_range = range(1, config.NISSL_COUNT + 1) print("***** Beginning batch processing") im = feature.im_read(filename) csv_filename = output_filename + "-" + str(points) + "pts.csv" with open(csv_filename, 'w') as csvfile: fieldnames = ['warp_points', 'warp_disp', 'plate', 'matches', 'inliers'] writer = csv.DictWriter(csvfile, fieldnames=fieldnames, delimiter=',', lineterminator='\n') writer.writeheader() for disp in disp_range: printProgressBar(int(disp / disp[0]), len(disp_range), prefix='Disp: ') # Warp image im_warp = feature.warp(im, points, None, None, disp, None)
def cv2_ransac(src_pts, dst_pts): import cv2 H, mask = cv2.findHomography(src_pts, dst_pts, cv2.RANSAC, config.RANSAC_REPROJ_TRESHHOLD, None, config.RANSAC_MAX_ITERS, config.RANSAC_CONFIDENCE) return { "homography": H, "inlier_mask": mask, "inlier_count": mask.ravel().sum(), "original_inlier_mask": None, "total_error": -1, "min_error": -1, "max_error": -1, 'metric': mask.ravel().sum() } import sys logbook.StreamHandler( sys.stdout, level=logbook.DEBUG, format_string=config.LOGGER_FORMAT_STRING).push_application() if __name__ == '__main__': import feature im_region = feature.im_read( 'C:/Users/xeroj/Desktop/Local_Programming/Vision-Rat-Brain/scripts_testing/region.jpg' ) feature.match_region_nissl(im_region, nissl_level=34)
else: kp, des = sift.detectAndCompute(im, None) kp2, des2 = sift.detectAndCompute(atlas, None) match = feature.match(im, kp, des, atlas, kp2, des2) print("Matches: ", len(match.matches)) print("Inliers: ", match.inlier_count) plt.figure(figsize=(10,10)) plt.imshow(match.result) plt.figure(figsize=(10,10)) plt.imshow(match.result2) return match.H filename = 'scripts_testing/region-70-HQ.jpg' im_region = feature.im_read(filename) im_region_gray = feature.im_read(filename, flags=cv2.IMREAD_GRAYSCALE) # *************** Resizing #im_region = misc.imresize(im_region, (170, 310)) im_region = misc.imresize(im_region, 10) # *************** Convolution #n = 6 #kernel = np.ones((n,n),np.float32)/(n**2) #dst = cv2.filter2D(im_region,-1,kernel) affine = True draw_kp(feature.im_read('scripts_testing/region-34.jpg')) draw_kp(im_region)
def refresh_image(self): im = feature.im_read(self.nissl_filename) self.canvas_input.imshow(im)