Example #1
0
def plot_images(folder, labels, targets, title):
    subs = {
        0: 'Hands',
        1: 'Objects-Scenes',
        2: 'Humans',
        3: 'Faces',
        4: 'Animals',
        5: 'Animal Faces',
        6: 'Monkey Faces',
        7: 'Fruits-Vegetables',
    }
    fig = plt.figure()
    images = list(glob.iglob(folder))
    labels_correct = [i == j for i, j in zip(labels, targets)]
    labels = [subs.get(item, item) for item in labels]
    for i, file in enumerate(images):
        sub = fig.add_subplot(12, 10, i + 1)
        img = plt.imread(file)
        sub.axis('off')
        sub.set_title(labels[i], fontsize=8, y=-.28)
        if not labels_correct[i]:
            sub.title.set_color('red')
        sub.imshow(img)
    plt.suptitle(title)
    plt.subplot_tool()
    plt.show()
Example #2
0
    def plot_data(self, data):
        plt.clf()
        x = [i for i in range(4096)]
        y = []

        for elt in x:
            y.append(data.value[elt])

        N = 50
        cumsum, y_mean = [0], []

        for i, yy in enumerate(y, 1):
            cumsum.append(cumsum[i - 1] + yy)

            if i >= N:
                mean = (cumsum[i] - cumsum[i - N]) / N
                y_mean.append(mean)

        plt.scatter(x, y, s=0.1, c="r")
        plt.plot(x[int(N / 2):-(int(N / 2) - 1)], y_mean)
        plt.ylabel('Hits/h')
        plt.xlabel('Channel')
        plt.subplot_tool()

        plt.gcf()

        App.get_running_app().graphWidget.draw_idle()
Example #3
0
def blackwhite_colorized_comparison(dir_color):
    images = os.listdir(dir_color)

    # dfine plot
    num_col = 6
    num_rows = math.ceil(len(images) * 2 / num_col)
    plt.figure(figsize=(num_col * 2.5 + 1, (num_rows + 2) * 2.5 + 1))
    gs1 = gridspec.GridSpec(num_rows + 2, num_col, width_ratios=[1] * num_col,
                            wspace=0.03, hspace=0.03, top=1, bottom=0, left=0, right=1)

    # make plots
    for i, image in enumerate(images):
        image1 = load_images(dir_color, image)

        # plot image
        ax1 = plt.subplot(gs1[i * 2])
        ax1.imshow(image1[:, :, 0], cmap='gray')
        ax2 = plt.subplot(gs1[i * 2 + 1])
        ax2.imshow(color.lab2rgb(image1))
        ax1.axis('off')
        ax2.axis('off')



    plt.subplot_tool()
    plt.savefig("../../../black-colored-comparison.jpg", bbox_inches='tight')
    plt.close()
Example #4
0
def main():

    parser = argparse.ArgumentParser()
    parser.add_argument('-i', '--image', type=str, help='input image path')

    args = parser.parse_args()

    image_name = args.image

    img = cv2.imread(image_name, 0)

    Kernel_K = np.array([[2, 4, 5, 4, 2], [4, 9, 12, 9, 4], [5, 12, 15, 12, 5],
                         [4, 9, 12, 9, 4], [2, 4, 5, 4, 2]], np.float32) / 159

    Kernel_Gx = np.array([[-1, 0, 1], [-2, 0, 2], [-1, 0, 1]], np.float32)

    Kernel_Gy = np.array([[-1, -2, -1], [0, 0, 0], [1, 2, 1]], np.float32)

    img_smooth = filterKernel(img, Kernel_K)

    img_smooth = img_smooth.astype(np.uint8)

    img_x = filterKernel(img_smooth, Kernel_Gx)
    img_y = filterKernel(img_smooth, Kernel_Gy)
    img_cover = np.sqrt(np.square(img_x) + np.square(img_y))
    img_cover = img_cover.astype(np.uint8)

    for i in np.arange(img_cover.shape[0]):
        for j in np.arange(img_cover.shape[1]):
            if img_cover[i, j] > 100 and img_cover[i, j] < 200:
                img_cover[i, j] = 255
            else:
                img_cover[i, j] = 0
            # curr = img_cover[i-1:i+2,j-1:j+2]
            # curr[curr < 100] = 0
            # curr[curr > 200] = 0
            # img_cover[i-1:i+2,j-1:j+2]=curr

    # cv2.imwrite("gr_img.jpg", img_cover)

    # cv2.imshow('Original', img)
    # cv2.imshow("Smooth", img_smooth)
    # cv2.imshow('Gradient', img_cover)

    plt.figure()

    plt.subplot(131)
    plt.imshow(img, cmap='gray')

    plt.subplot(132)
    plt.imshow(img_smooth, cmap='gray')

    plt.subplot(133)
    plt.imshow(img_cover, cmap='gray')

    plt.subplot_tool()
    plt.show()
Example #5
0
def plot_latencies(ip_addresses, values):

    fig, ax = plt.subplots(nrows=1, ncols=1)
    plt.subplots_adjust(wspace=0.6, hspace=0.6, left=0.1, bottom=0.35, right=0.96, top=0.90)
    plt.xticks(range(len(ip_addresses)), ip_addresses, rotation=90)
    fig.suptitle('Latency by video IP address')
    plt.xlabel('Video IP address')
    plt.ylabel('Ping average (ms)')
    plt.plot(ip_addresses, values)
    plt.subplot_tool()

    fig.savefig('resources/plots/latency_pytomo.png')
    plt.close(fig)
Example #6
0
def 工具栏():
    fig, axs = plt.subplots(2, 2)

    axs[0, 0].imshow(np.random.random((100, 100)))

    axs[0, 1].imshow(np.random.random((100, 100)))

    axs[1, 0].imshow(np.random.random((100, 100)))

    axs[1, 1].imshow(np.random.random((100, 100)))

    plt.subplot_tool()
    plt.show()
Example #7
0
def compute_and_diplay_saliency_map(layer_unit_1):

    try:

        fig, axs = mplt.subplots(2, 2)
        axs[0, 0].imshow(layer_unit_1[0, :, :, 0], cmap="hot")
        axs[0, 1].imshow(layer_unit_1[1, :, :, 0], cmap="hot")
        axs[1, 0].imshow(layer_unit_1[2, :, :, 0], cmap="hot")
        axs[1, 1].imshow(layer_unit_1[3, :, :, 0], cmap="hot")

        mplt.subplot_tool()
        mplt.show()

    except Exception as e:
        print(e)
Example #8
0
def render_chars(chars):
    fig, axs = plt.subplots(1,len(chars))
    for ix, char in enumerate(chars):
        axs[ix].imshow(char)
    plt.subplot_tool()
    plt.show()
Example #9
0
    except:
        #fig.savefig('mbotEXCEPTION.tiff')
        #print("an exception occurred",exception)
        
    #fig.savefig('mbot.tiff')
    #fig2.savefig('mbottt.tiff')
    '''
    def animate(i):
        x = np.linspace(0, 2, 1000)
        y = np.sin(2 * np.pi * (x - 0.01 * i))
        line.set_data(x, y)
        return line,
    try:
        # call the animator.  blit=True means only re-draw the parts that have changed.
        anim = animation.FuncAnimation(fig, animate, init_func=init,
                                       frames=20, interval=20, blit=True)

        # save the animation as an mp4.  This requires ffmpeg or mencoder to be
        # installed.  The extra_args ensure that the x264 codec is used, so that
        # the video can be embedded in html5.  You may need to adjust this for
        # your system: for more information, see
        # http://matplotlib.sourceforge.net/api/animation_api.html
        anim.save('basic_animation.mp4', fps=10, extra_args=['-vcodec', 'libx264'])
    except:
        print("an exception ocurred in animate().")
        '''
    plt.subplot_tool(targetfig=fig)
    print("Done.") #plt.show()
    
Example #10
0
        return fname
    imgx = 20
    imgy = 0
    def pltshow(plt, dpi=150):
        global imgx, imgy
        temppath = tempimage()
        plt.savefig(temppath, dpi=dpi)
        dx,dy = imagesize(temppath)
        w = min(W,dx)
        image(temppath,imgx,imgy,width=w)
        imgy = imgy + dy + 20
        os.remove(temppath)
        size(W, HEIGHT+dy+40)
else:
    def pltshow(mplpyplot):
        mplpyplot.show()
# nodebox section end

fig, axs = plt.subplots(2, 2)

axs[0, 0].imshow(np.random.random((100, 100)))

axs[0, 1].imshow(np.random.random((100, 100)))

axs[1, 0].imshow(np.random.random((100, 100)))

axs[1, 1].imshow(np.random.random((100, 100)))

plt.subplot_tool()
pltshow(plt)
Example #11
0
"""
===============
Subplot Toolbar
===============

Matplotlib has a toolbar available for adjusting subplot spacing.
"""
import matplotlib.pyplot as plt
import numpy as np

# Fixing random state for reproducibility
np.random.seed(19680801)

fig, axs = plt.subplots(2, 2)

axs[0, 0].imshow(np.random.random((100, 100)))

axs[0, 1].imshow(np.random.random((100, 100)))

axs[1, 0].imshow(np.random.random((100, 100)))

axs[1, 1].imshow(np.random.random((100, 100)))

plt.subplot_tool()
plt.show()
Example #12
0
def subplot_tool(*args,**kwargs):
	return plt.subplot_tool(*args,**kwargs)
Example #13
0
lista_alpha0 = [1]
sangre(lista_alpha0, 0)
plt.subplot(2, 3, 4)
plt.title("Pregunta 2.A.2(alpha = 1/2)")
plt.stem(n, lista_alpha0)

lista_alpha1 = [1]
sangre(lista_alpha1, 1)
plt.subplot(2, 3, 5)
plt.title("Pregunta 2.A.2(alpha = 1/3)")
plt.stem(n, lista_alpha1)

N = np.arange(1, 50, 1)
n = np.arange(0, 50, 1)
lista_alpha2 = [1]
sangre(lista_alpha2, 2)
plt.subplot(2, 3, 6)
plt.title("Pregunta 2.A.2(alpha = 7/8)")
plt.stem(n, lista_alpha2)

#######################################################################################
#A.3
#  PARA alpha = 1/2 ----> lim n->00 y[n] = 2
#  PARA alpha = 1/3 ----> lim n->00 y[n] = 1.5
#  PARA alpha = 7/8 ----> lim n->00 y[n] = 8

plt.subplot_tool(
)  # Esto abre una ventana para poder visualizar mejor los graficos, puedes ajustarlos como quieras.

plt.show()
    'gyrox': 10,
    'gyroy': 11,
    'gyroz': 12,
}

if __name__ == "__main__":

    pickle_gauss = open("results_Gaussian.pickle", "rb")
    results_Gaussian = pickle.load(pickle_gauss)
    pickle_gauss.close()
    pickle_gmm = open("results_GMM.pickle", "rb")
    results_GMM = pickle.load(pickle_gmm)
    pickle_gmm.close()

    fig1 = plt.figure(1)
    plt.subplot_tool(targetfig=fig1)
    for i, result in enumerate(results_GMM):
        plt.subplot(4, 3, i + 1)
        plt.imshow(result['img'])
        plt.title(result['title'])
        plt.subplot(4, 3, i + 4)
        colors = ["blue"] * 25 + ["green"] * 20 + ["red"] * 20
        x = np.arange(len(colors))
        y = result['scores'][9]  #log prob of user 9
        plt.scatter(x, y, c=colors)
        plt.title(result['title'])
    for i, result in enumerate(results_Gaussian):
        plt.subplot(4, 3, i + 7)
        plt.imshow(result['img'])
        plt.title(result['title'])
        plt.subplot(4, 3, i + 10)
Example #15
0
def subplot_tool(*args, **kwargs):
    return plt.subplot_tool(*args, **kwargs)
Example #16
0
def main():

    # path_test = '/home/sushobhan/caffe/data/ptychography/databases/Test42_Set91_img512_patch48/test_images/'
    # path_test =  "/home/sushobhan/Documents/data/ptychography/Test42_Set91_img512_patch48/test_images/"
    # path_test = "/home/sushobhan/Documents/data/ptychography/"
    path_test = "/home/sushobhan/Documents/data/ptychography/Test40_Set91_img512_patch48/test_images/"
    home = "/home/sushobhan/Documents/research/ptychography/"
    model_name = sys.argv[1]
    crop_size = 4

    border_mode = 'valid'

    # file_name = 'lena_1.h5'
    # file_name = 'resChart.h5'
    file_name = 'set_1.h5'

    file = h5py.File(path_test + file_name, 'r')
    ks = file.keys()
    print ks

    data = file['data']
    label = file['label']
    # data = np.max(data) - data
    # label = np.max(label) - label

    if file_name == "lena.h5" or file_name == "resChart.h5" or file_name == "lena_1.h5":

        data = np.expand_dims(file['data'], axis=0)
        label = np.expand_dims(np.expand_dims(file['label'], axis=0), axis=0)
    # label = np.transpose(label,(0,1,3,2))

    # im.imsave('label.png',label[0,0,],cmap=plt.cm.gray)
    # im.imsave('data.png',data[0,24,],cmap=plt.cm.gray)

    model = load_model(home + 'models/' + model_name + '.h5')
    y_output = np.array(model.predict(data))

    if border_mode == 'valid':
        data = crop(data, crop_size)
        label = crop(label, crop_size)

    print np.max(data), np.max(label)

    print y_output.shape, np.max(y_output)
    print data.shape, label.shape

    im.imsave('label.png', label[0, 0, ], cmap=plt.cm.gray)
    im.imsave('data.png', data[0, 24, ], cmap=plt.cm.gray)
    im.imsave('output.png', y_output[0, 0, ], cmap=plt.cm.gray)

    fig = plt.figure(0)
    m, n = 2, 2
    for i in range(0, 1):
        # print i
        j, k = i // n, i % n
        # print j,k
        plt.subplot2grid((m, n), (j, k))
        plt.imshow(label[i, 0, ], cmap=plt.cm.gray)
        # print j+2, k
        plt.subplot2grid((m, n), (j + 1, k))
        plt.imshow(y_output[i, 0, ], cmap=plt.cm.gray)

        plt.subplot2grid((m, n), (j, k + 1))
        plt.imshow(data[i, 24, ], cmap=plt.cm.gray)

        print compare_psnr(label[i, 0, ], y_output[i, 0, ])
        print compare_psnr(label[i, 0, ], data[i, 24, ])
    plt.subplot_tool()
    plt.savefig(model_name + '.jpg')

    psnr_center = []
    psnr_output = []

    for i in range(data.shape[0]):
        psnr_center.append(compare_psnr(label[i, 0, ], data[i, 24, ]))
        psnr_output.append(compare_psnr(label[i, 0, ], y_output[i, 0, ]))

    print np.mean(psnr_output)
    print np.mean(psnr_center)