示例#1
0
def test_vst_estimation_movie(movie, idx=None, gt=None, filename=None):
    if idx is None:
        movie_train = movie[::200]
    else:
        movie_train = movie[idx]

    block_size = 8
    stride = 8

    t = timeit.default_timer()
    blocks_train = []
    for img in movie_train:
        blocks_train.append(im2col(img, block_size, stride))
    blocks_train = np.vstack(blocks_train)

    sigma_sq_init, alpha_init = est.initial_estimate_sigma_alpha(blocks_train)
    print('\tTime', timeit.default_timer() - t)
    print('\talpha = {}; sigma^2 = {}'.format(alpha_init, sigma_sq_init))

    t = timeit.default_timer()
    res = est.estimate_vst_movie(movie_train, stride=stride)
    print('\tTime', timeit.default_timer() - t)

    blocks = []
    for img in movie:
        blocks.append(im2col(img, block_size, stride))
    blocks = np.vstack(blocks)
    plot_vst_estimation(movie,
                        blocks,
                        sigma_sq_init,
                        alpha_init,
                        res,
                        0,
                        gt=gt,
                        filename=filename)
示例#2
0
def test_vst_estimation_frame(movie, idx=0, gt=None, filename=None):
    img = movie[idx]

    block_size = 8
    stride = 8

    t = timeit.default_timer()
    blocks = im2col(img, block_size, stride)
    sigma_sq_init, alpha_init = est.initial_estimate_sigma_alpha(blocks)
    print('\tTime', timeit.default_timer() - t)
    print('\talpha = {}; sigma^2 = {}'.format(alpha_init, sigma_sq_init))

    t = timeit.default_timer()
    res = est.estimate_vst_image(img, stride=stride)
    print('\tTime', timeit.default_timer() - t)

    plot_vst_estimation(movie,
                        blocks,
                        sigma_sq_init,
                        alpha_init,
                        res,
                        idx,
                        gt=gt,
                        filename=filename)
示例#3
0
def estimate_vst_image(img, block_size=8, stride=8):
    blocks = regions.im2col(img, block_size, stride)
    return estimate_vst_blocks(blocks)
示例#4
0
def estimate_vst_movie(movie, block_size=8, stride=8):
    blocks = []
    for img in movie:
        blocks.append(regions.im2col(img, block_size, stride))
    blocks = np.vstack(blocks)
    return estimate_vst_blocks(blocks)
def ground_truth_patchwise(dir_name, files, gt_means_means, gt_vars_means,
                           box=None, block_size=8, stride=8):
    colors = sns.color_palette('Pastel1', len(files))
    colors_means = sns.color_palette('Set1', len(files))

    with sns.axes_style("white"):
        fig, axes = plt.subplots(1, 1, figsize=(8, 4))
        for k, fn in enumerate(files):
            movie = tifffile.imread(dir_name + fn)
            if box is None:
                movie = movie[:, ::2, :]
            else:
                movie = movie[:, box[0]:box[1]:2, box[2]:box[3]]
            movie = movie.astype(np.float32)

            means = []
            variances = []
            for i in range(0, len(movie), 10):
                blocks_i = im2col(movie[i], block_size, stride)
                means_i, vars_i = compute_mean_var(blocks_i)
                means.append(means_i)
                variances.append(vars_i)

            means = np.hstack(means)
            variances = np.hstack(variances)

            axes.plot(means, variances, '.', alpha=0.7, color=colors[k],
                      markeredgecolor='none', zorder=10 - k, rasterized=True)

            axes.scatter(means.mean(), variances.mean(), marker='x', s=1000,
                         linewidth=2, color=colors_means[k],
                         edgecolor=colors_means[k], zorder=1000)

            axes.scatter(gt_means_means[k], gt_vars_means[k], marker='+',
                         s=1000, linewidth=2, color=colors_means[k],
                         edgecolor=colors_means[k], zorder=1000)

        axes.yaxis.set_major_formatter(
            plt_tick.FuncFormatter(lambda t, pos: fix_scientific_notation(t)))

        axes.set_xlabel('Mean', fontsize='large')
        axes.set_ylabel('Variance', fontsize='large')

        markers1 = [plt_lines.Line2D([], [], marker='o', color=colors[k],
                                     linestyle='None')
                    for k in range(len(files))]
        label1 = ['Movie {} - patch'.format(k+1)
                  for k in range(len(files))]
        markers2 = [plt_lines.Line2D([], [], marker='x', color=colors_means[k],
                                     mec=colors_means[k], linestyle='None',
                                     markersize=10, markeredgewidth=2)
                    for k in range(len(files))]
        label2 = ['Movie {} - patch AVG'.format(k+1)
                  for k in range(len(files))]
        markers3 = [plt_lines.Line2D([], [], marker='+', color=colors_means[k],
                                     mec=colors_means[k], linestyle='None',
                                     markersize=10, markeredgewidth=2)
                    for k in range(len(files))]
        label3 = ['Movie {} - pixel AVG'.format(k+1)
                  for k in range(len(files))]
        plt.legend(markers1 + markers2 + markers3, label1 + label2 + label3,
                   bbox_to_anchor=(1.01, 1), loc='best', fontsize='large')
        fig.tight_layout(rect=(0, 0, 0.7, 1))
        plt.savefig('ground_truth_patchwise.pdf')