Esempio n. 1
0
def analyze_contrast(gr_name, graph_axes, iceberg_slice=np.s_[:,:], set_name=None):
    gr_full = cv2.imread(gr_name, cv2.IMREAD_GRAYSCALE)
    gr = cv2.resize(gr_full, (0,0), fx=1/5, fy=1/5, interpolation=cv2.INTER_AREA)

    warped_images = np.empty((11),dtype=object)
    adjs = np.arange(-1,1.2,.2)

    ace_obj = HistogramWarpingACE(no_bits=8, tau=0.01, stretch_factor=1, debug=True, plot_histograms=False)
    v_k, a_k = ace_obj.compute_vk_and_ak(gr)


    for i, adj in enumerate(adjs):
        print(i,adj)
        outputs = ace_obj.compute_bk_and_dk(v_k, a_k, adjustment_factor=adj)
        warped_images[i], Tx = ace_obj.transform_image(*outputs, gr)

    fig,axes = plt.subplots(2,5, sharex=True, sharey=True)
    [axi.set_axis_off() for axi in axes.ravel()]
    warped_images_for_plot = np.delete(warped_images,5).reshape(2,5)
    adjs_display = np.delete(adjs,5)

    for adj, ax, img in zip(adjs_display, axes.ravel(), warped_images_for_plot.ravel()):
        ax.imshow(img, cmap='gray', vmin=0, vmax=255)
        ax.set_title("Adj factor = {:.2f}".format(adj))


    fig.subplots_adjust(left=0.05, bottom=0.1, right=0.99, top=.9, wspace=0.01, hspace=0.01)
    fig.suptitle(set_name)
    show_plot()

    full_img_gcfs = np.zeros(warped_images.shape)
    iceberg_slice_gcfs = np.zeros(warped_images.shape)

    for i, wimg in enumerate(warped_images):
        full_img_gcfs[i] = compute_global_contrast_factor(wimg)
        iceberg_slice_gcfs[i] = compute_global_contrast_factor(wimg[iceberg_slice])

    graph_axes.plot(adjs, full_img_gcfs, '.-',label=set_name+" Full Image" )
    graph_axes.plot(adjs, iceberg_slice_gcfs, '.-',label=set_name+" Iceberg Slice" )
    graph_axes.legend()

    fig2,axes2 = plt.subplots(2,5, sharex=True, sharey=True)
    fig2.suptitle(set_name)

    for adj, ax, img in zip(adjs_display, axes2.ravel(), warped_images_for_plot.ravel()):
        plot_harris_eig_vals(img, ax)
        #plot_harris_eig_vals(img, ax)
        ax.set_title("Adj factor = {:.2f}".format(adj))
        ax.set(adjustable='box', aspect='equal')
        ax.set_xlim(ax.set_ylim(0,None))
Esempio n. 2
0
def analyze_contrast(gr_name, graph_axes, iceberg_slice=np.s_[:,:], set_name=None):
    gr_full = cv2.imread(gr_name, cv2.IMREAD_GRAYSCALE)
    gr = cv2.resize(gr_full, (0,0), fx=1/5, fy=1/5, interpolation=cv2.INTER_AREA)

    adjs = np.arange(0,-1.2,-.2)
    sfs = np.arange(-1.0,0.2,.2)
    sfs_g, adj_g = np.meshgrid(sfs, adjs)

    ace_obj = HistogramWarpingACE(no_bits=8, tau=0.01, lam=5, adjustment_factor=-1.0, stretch_factor=-1.0,
                                  min_stretch_bits=4, downsample_for_kde=True,debug=False, plot_histograms=False)
    v_k, a_k = ace_obj.compute_vk_and_ak(gr)

    warped_images = np.empty(adj_g.shape,dtype=object)

    fig,axes = plt.subplots(*adj_g.shape, sharex=True, sharey=True)
    for axi in axes.ravel():
        axi.get_xaxis().set_ticks ([])
        axi.get_yaxis().set_ticks ([])
        axi.spines['left'].set_visible(False)
        axi.spines['right'].set_visible(False)
        axi.spines['bottom'].set_visible(False)
        axi.spines['top'].set_visible(False)

    for (i,j),adj in np.ndenumerate(adj_g):
        print(i,adj)
        outputs = ace_obj.compute_bk_and_dk(v_k, a_k, adjustment_factor=adj, stretch_factor=sfs_g[i,j])
        warped_images[i,j], Tx = ace_obj.transform_image(*outputs, gr)

        axes[i,j].imshow(warped_images[i,j], cmap='gray', vmin=0, vmax=255)
        #ax.set_title("Adj factor = {:.2f}".format(adj))

    for i, sf in enumerate(sfs):
        axes[-1,i].set_xlabel('Stretch: {:.2f}'.format(sf))


    for j, adj in enumerate(adjs):
        axes[j,0].set_ylabel('Adj: {:.2f}'.format(adj))


    fig.subplots_adjust(left=0.025, bottom=0.025, right=0.99, top=.9, wspace=0.00, hspace=0.00)
    fig.suptitle(set_name)
    show_plot()

    '''
Esempio n. 3
0
                              plot_histograms=False)
v_k, a_k = ace_obj.compute_vk_and_ak(gr)

adjs = np.arange(0, -1.05, -.05)
contrast_estimates = np.zeros((len(adjs), len(contrast_estimators)))
contrast_estimates_slice = np.zeros((len(adjs), len(contrast_estimators)))

warped_images = np.empty(adjs.shape, dtype=object)

for i, adj in enumerate(adjs):
    print(i, adj)
    outputs = ace_obj.compute_bk_and_dk(v_k,
                                        a_k,
                                        adjustment_factor=adj,
                                        stretch_factor=adj)
    warped_images[i], Tx = ace_obj.transform_image(*outputs, gr)
    contrast_estimates[i, :] = np.array(
        [ce(warped_images[i]) for nm, ce in contrast_estimators.items()])
    contrast_estimates_slice[i, :] = np.array([
        ce(warped_images[i][gr_slice])
        for nm, ce in contrast_estimators.items()
    ])

fig_imgs, axes_imgs = plt.subplots(*calculate_best_screen_packing(
    len(adjs), img_resolution=gr.shape),
                                   sharex=True,
                                   sharey=True)
fig_imgs.suptitle(gr_name)
[ax.set_axis_off() for ax in axes_imgs.ravel()]
fig_imgs.subplots_adjust(left=0.01,
                         bottom=0.1,