Beispiel #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))
 def test_histogram_warping_plots(self):
     """
     Test the warping with plotting
     """
     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=True)
     for gr in self.gr_list:
         gr_warped = ace_obj.apply(gr)
         self.assertEqual(gr_warped.shape, gr.shape,
                          "Return image size incorrect")
Beispiel #3
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()

    '''
Beispiel #4
0
def compare_single_img(gr_raw_name, gr_bm_name):
    gr_raw = cv2.imread(gr_raw_name, cv2.IMREAD_GRAYSCALE)
    gr_bm = cv2.imread(gr_bm_name, cv2.IMREAD_GRAYSCALE)

    ace_obj = HistogramWarpingACE(no_bits=8, tau=0.01, stretch_factor=1,adjustment_factor=1, debug=True, plot_histograms=True)
    gr_warp,Tx = ace_obj.apply(gr_raw, return_Tx=True)

    fig = plt.figure(constrained_layout=True)
    gs = fig.add_gridspec(5, 3)
    axes = np.empty((4,3),dtype=object)
    axes[0,0] = fig.add_subplot(gs[0:2,0])
    axes[1,0] = fig.add_subplot(gs[2,0])
    axes[2,0] = fig.add_subplot(gs[3,0], sharex = axes[1,0])

    axes[0,1] = fig.add_subplot(gs[0:2,1], sharex = axes[0,0], sharey=axes[0,0])
    axes[1,1] = fig.add_subplot(gs[2,1], sharex = axes[1,0], sharey = axes[1,0])
    axes[2,1] = fig.add_subplot(gs[3,1], sharex = axes[1,1], sharey = axes[2,0])
    axes[3,1] = fig.add_subplot(gs[4,1])

    axes[0,2] = fig.add_subplot(gs[0:2,2])
    axes[1,2] = fig.add_subplot(gs[2,2], sharex = axes[1,0], sharey = axes[1,0])
    axes[2,2] = fig.add_subplot(gs[3,2], sharex = axes[1,2], sharey = axes[2,0])
    axes[3,2] = fig.add_subplot(gs[4,2], sharex = axes[3,1], sharey = axes[3,0])


    [axi.set_axis_off() for axi in axes[0,:].ravel()]
    [plt.setp(a.get_xticklabels(), visible=False) for a in axes[1:3,:].ravel()]
    [plt.setp(a.get_yticklabels(), visible=False) for a in axes[1:,1:].ravel()]

    plot_img_histograms(gr_raw, axes[:,0], title="Raw")
    plot_img_histograms(gr_warp, axes[:,1], title="cmtpy")
    plot_img_histograms(gr_bm, axes[:,2], title="Paper")

    axes[3,2].plot(gr_raw.flatten(), gr_bm.flatten(),'.',ms=.5)
    x = np.linspace(0,1, 256)
    axes[3,1].plot(x*255,Tx(x)*255,'.', ms=0.5)
    show_plot(fig)
Beispiel #5
0
    'RMS Contrast':
    lambda gr: cm.compute_rms_contrast(gr, debug=False),
    'Local box filt':
    lambda gr: cm.compute_box_filt_contrast(gr, kernel_size=17, debug=False),
    'Local gaussian filt':
    lambda gr: cm.compute_gaussian_filt_contrast(gr, sigma=5.0, debug=False),
    'Local bilateral filt':
    lambda gr: cm.compute_bilateral_filt_contrast(
        gr, sigmaSpace=5.0, sigmaColor=0.05, debug=False)
}

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)

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,
Beispiel #6
0
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Jun  8 10:39:08 2020

@author: vik748
"""
from cmtpy.histogram_warping_ace import HistogramWarpingACE
import cv2
import sys, os

data_fold = os.path.expanduser('~/data')

gr1_name = os.path.join(data_fold, 'Lars1_080818', 'G0287250.JPG')
gr2_name = os.path.join(data_fold, 'Lars2_081018', 'G0029490.JPG')
gr3_name = os.path.join(data_fold, 'chess_board', 'GOPR1488.JPG')

gr_full = cv2.imread(gr3_name, cv2.IMREAD_GRAYSCALE)
gr = cv2.resize(gr_full, (0, 0),
                fx=1 / 5,
                fy=1 / 5,
                interpolation=cv2.INTER_AREA)

ace_obj = HistogramWarpingACE(no_bits=8,
                              tau=0.01,
                              stretch_factor=-1,
                              adjustment_factor=-1,
                              debug=True,
                              plot_histograms=True)
ace_obj.apply(gr)