def show_transform(self, transform_, date_='new'): logging.info('Showing transform: ' + self._fmt_transform(transform_, date_)) self._transform_date = date_ self._selected_transform = transform_ self.im_reg = warp_int(self.im1_sel.img, self._selected_transform.inverse) self._checkerboard()
transforms = np.recfromcsv(fname, names=None) imgs = [] for t in transforms: data = list(t) date, target, ref = data[:3] imgs.append((target, ref, data[3:])) for img, ref, params in imgs: im = io.imread(os.path.join(path_src,img)) matrix = np.array(params).reshape(3,3) trans = transform.AffineTransform(matrix=matrix) img_reshaped = warp_int(im, trans.inverse) save_dir = os.path.join(path_target, ref) if not os.path.exists(save_dir): os.makedirs(save_dir) file_path = os.path.join(save_dir, img) i = 1 while os.path.exists(file_path): root, ext = os.path.splitext(img) img_name = "".join([root , "_reg%d" % i, ext]) file_path = os.path.join(save_dir, img_name) i+=1
def transform_and_compare(img, img_ref, params, f_cmp=mean_sq_diff): new_transform = get_transform(params) img_new = warp_int(img, new_transform.inverse) return f_cmp(img_new, img_ref)