def get_pairs(imgs, unique_pairs, offsets, subsample_factor, overlap_pixels, n_kp): """Create inlier keypoint pairs.""" orb = ORB(n_keypoints=n_kp, fast_threshold=0.05) k = gaussian(offsets * 2 + 1, 1, sym=True) tf = SimilarityTransform # tf = RigidTransform tf0 = SimilarityTransform() # FIXME: is there no rigid model in scikit-image??? # this is needed for input to RANSAC pairs = [] init_tfs = np.empty([n_slcs, n_tiles, 3]) for p in unique_pairs: pair_tstart = time() full_im1, full_im2 = subsample_images(p, imgs, subsample_factor) part_im1, part_im2 = select_imregions(p[2], full_im1, full_im2, overlap_pixels) keyp_im1, desc_im1 = get_keypoints(orb, part_im1) keyp_im2, desc_im2 = get_keypoints(orb, part_im2) keyp_im1, keyp_im2 = reset_imregions(p[2], keyp_im1, keyp_im2, overlap_pixels, full_im1.shape) matches = match_descriptors(desc_im1, desc_im2, cross_check=True) dst = keyp_im1[matches[:, 0]][:, ::-1] src = keyp_im2[matches[:, 1]][:, ::-1] model, inliers = ransac((src, dst), tf, min_samples=4, residual_threshold=2, max_trials=300) w = k[offsets - (p[1][0] - p[0][0])] pairs.append((p, src[inliers], dst[inliers], model, w)) if (p[0][1] == 0) & (p[0][0] == p[1][0] ): # referenced to tile 0 within the same slice tf1 = tf0.__add__(model) itf = [ math.acos(min(tf1.params[0, 0], 1)), # FIXME!!! with RigidTransform tf1.params[0, 2], tf1.params[1, 2] ] init_tfs[p[1][0], p[1][1], :] = np.array(itf) if (p[0][1] == p[1][1] == 0) & ( p[1][0] - p[0][0] == 1): # if [slcX,tile0] to [slcX-1,tile0] tf0 = tf0.__add__(model) plot_pair_ransac(p, full_im1, full_im2, keyp_im1, keyp_im2, matches, inliers) print('Pair done in: %.2f s' % (time() - pair_tstart, )) return pairs, init_tfs
def generate_init_tfs(pairs, n_slcs, n_tiles): """Find the transformation of each tile to tile[0,0].""" tf0 = SimilarityTransform() init_tfs = np.empty([n_slcs, n_tiles, 3]) for pair in pairs: p, _, _, model, _ = pair if (p[0][1] == 0) & (p[0][0] == p[1][0] ): # referenced to tile 0 within the same slice tf1 = tf0.__add__(model) itf = [ math.acos(min(tf1.params[0, 0], 1)), # FIXME!!! with RigidTransform tf1.params[0, 2], tf1.params[1, 2] ] init_tfs[p[1][0], p[1][1], :] = np.array(itf) if (p[0][1] == p[1][1] == 0) & ( p[1][0] - p[0][0] == 1): # if [slcX,tile0] to [slcX-1,tile0] tf0 = tf0.__add__(model) return init_tfs
def test_union_differing_types(): tform1 = SimilarityTransform() tform2 = PolynomialTransform() with pytest.raises(TypeError): tform1.__add__(tform2)
def test_union_differing_types(): tform1 = SimilarityTransform() tform2 = PolynomialTransform() with testing.raises(TypeError): tform1.__add__(tform2)