Exemplo n.º 1
0
                    'target_image': tgt
                })
            else:
                corr4d = model({'source_image': src, 'target_image': tgt})
                delta4d = None
            if args.benchmark:
                mid.record()

            # reshape corr tensor and get matches for each point in image B
            batch_size, ch, fs1, fs2, fs3, fs4 = corr4d.size()

            # pad image and plot
            if plot:
                h_max = int(np.max([src.shape[2], tgt.shape[2]]))
                im = plot_image(torch.cat(
                    (padim(src, h_max), padim(tgt, h_max)), dim=3),
                                return_im=True)
                plt.imshow(im)

            if matching_both_directions:
                (xA_, yA_, xB_, yB_,
                 score_) = corr_to_matches(corr4d,
                                           scale='positive',
                                           do_softmax=do_softmax,
                                           delta4d=delta4d,
                                           k_size=k_size)
                (xA2_, yA2_, xB2_, yB2_,
                 score2_) = corr_to_matches(corr4d,
                                            scale='positive',
                                            do_softmax=do_softmax,
                                            delta4d=delta4d,
Exemplo n.º 2
0
            yb = float(rowA[0][i])
            c = np.random.rand(3)
            # plt.gca().add_artist(plt.Circle((xa, ya), radius=3, color=c))
            # plt.gca().add_artist(plt.Circle((xb, yb), radius=3, color=c))
            # plt.plot([xa, xb], [ya, yb], c=c, linestyle='-', linewidth=1.5)

    # plt.axis('off')
    # plt.title('gridCellMatching')
    # plt.savefig('cell.png', dpi=300)
    # plt.show()

    ###############################################MatchingGridCellPoints##############################################

    # display result
    im = plot_image(torch.cat(
        (batch_tnf['target_image'], batch_tnf['source_image']), 3),
                    0,
                    return_im=True)
    tgt_pts[0, 0, :] = unnormalize_axis(tgt_pts[0, 0, :],
                                        tgt.shape[2])  # B points
    tgt_pts[0, 1, :] = unnormalize_axis(tgt_pts[0, 1, :], tgt.shape[1])
    src_pts[0, 0, :] = unnormalize_axis(src_pts[0, 0, :],
                                        src.shape[2])  # A points
    src_pts[0, 1, :] = unnormalize_axis(src_pts[0, 1, :], src.shape[1])
    warped_points[0, 0, :] = unnormalize_axis(warped_points[0, 0, :],
                                              src.shape[2])
    warped_points[0, 1, :] = unnormalize_axis(warped_points[0, 1, :],
                                              src.shape[1])  # 变形后的点坐标反归一化
    # cat image(B+A:tar+src)  # tranform B points to A
    # plt.imshow(im)
    # for i in range(tgt_pts.shape[2]):
    #     xa = float(tgt_pts[0, 0, i])