コード例 #1
0
def singleImageResult(image_file):
    image_name = os.path.basename(image_file)
    image_name = os.path.splitext(image_name)[0]

    image = loadRGB(image_file)

    som1D, som2D = setupSOM(image)

    fig = plt.figure(figsize=(10, 7))
    fig.subplots_adjust(left=0.05,
                        bottom=0.05,
                        right=0.95,
                        top=0.9,
                        wspace=0.1,
                        hspace=0.2)

    font_size = 15
    fig.suptitle("SOM-Color Manifolds for Single Image", fontsize=font_size)

    plt.subplot(231)
    h, w = image.shape[:2]
    plt.title("Original Image: %s x %s" % (w, h), fontsize=font_size)
    plt.imshow(image)
    plt.axis('off')

    print "  - Train 1D"
    som1D.trainAll()

    print "  - Train 2D"
    som2D.trainAll()

    som1D_plot = SOMPlot(som1D)
    som2D_plot = SOMPlot(som2D)
    plt.subplot(232)
    plt.title("SOM 1D", fontsize=font_size)
    som1D_plot.updateImage()
    plt.axis('off')

    plt.subplot(233)
    plt.title("SOM 2D", fontsize=font_size)
    som2D_plot.updateImage()
    plt.axis('off')

    ax1D = fig.add_subplot(235, projection='3d')
    plt.title("1D in 3D", fontsize=font_size)
    som1D_plot.plot3D(ax1D)

    ax2D = fig.add_subplot(236, projection='3d')
    plt.title("2D in 3D", fontsize=font_size)
    som2D_plot.plot3D(ax2D)

    result_file = resultFile("%s_single" % image_name)
    plt.savefig(result_file)
コード例 #2
0
def singleImageResult(image_file):
    image_name = os.path.basename(image_file)
    image_name = os.path.splitext(image_name)[0]

    image = loadRGB(image_file)

    som1D, som2D = setupSOM(image)

    fig = plt.figure(figsize=(10, 7))
    fig.subplots_adjust(left=0.05, bottom=0.05, right=0.95, top=0.9, wspace=0.1, hspace=0.2)

    font_size = 15
    fig.suptitle("SOM-Color Manifolds for Single Image", fontsize=font_size)

    plt.subplot(231)
    h, w = image.shape[:2]
    plt.title("Original Image: %s x %s" % (w, h), fontsize=font_size)
    plt.imshow(image)
    plt.axis('off')

    print "  - Train 1D"
    som1D.trainAll()

    print "  - Train 2D"
    som2D.trainAll()

    som1D_plot = SOMPlot(som1D)
    som2D_plot = SOMPlot(som2D)
    plt.subplot(232)
    plt.title("SOM 1D", fontsize=font_size)
    som1D_plot.updateImage()
    plt.axis('off')

    plt.subplot(233)
    plt.title("SOM 2D", fontsize=font_size)
    som2D_plot.updateImage()
    plt.axis('off')

    ax1D = fig.add_subplot(235, projection='3d')
    plt.title("1D in 3D", fontsize=font_size)
    som1D_plot.plot3D(ax1D)

    ax2D = fig.add_subplot(236, projection='3d')
    plt.title("2D in 3D", fontsize=font_size)
    som2D_plot.plot3D(ax2D)

    result_file = resultFile("%s_single" % image_name)
    plt.savefig(result_file)
コード例 #3
0
def multiImagesResult(data_name, data_ids):
    num_cols = len(data_ids)
    num_rows = 2

    fig = plt.figure(figsize=(12, 6))
    fig.subplots_adjust(left=0.05,
                        bottom=0.05,
                        right=0.95,
                        top=0.9,
                        wspace=0.1,
                        hspace=0.2)

    font_size = 15
    fig.suptitle("SOM-Color Manifolds for Multi Images", fontsize=font_size)

    color_samples = []
    col_id = 0
    for data_id in data_ids:
        image_file = dataFile(data_name, data_id)
        image_name = "%s_%s" % (data_name, data_id + 1)

        image = loadRGB(image_file)

        hist3D = Hist3D(image, num_bins=16)

        color_samples.extend(hist3D.colorCoordinates())

        plt.subplot2grid((num_rows, num_cols), (0, col_id))
        plt.title("%s" % image_name, fontsize=font_size)
        plt.imshow(image)
        plt.axis('off')

        col_id += 1

    color_samples = np.array(color_samples)
    print color_samples.shape

    som1D, som2D = setupSOM(color_samples)

    print "  - Train 1D"
    som1D.trainAll()

    print "  - Train 2D"
    som2D.trainAll()

    som1D_plot = SOMPlot(som1D)
    som2D_plot = SOMPlot(som2D)

    col_id = 1
    plt.subplot2grid((num_rows, num_cols), (1, col_id))
    plt.title("SOM 1D", fontsize=font_size)
    som1D_plot.updateImage()
    plt.axis('off')

    col_id += 1
    ax1D = plt.subplot2grid((num_rows, num_cols), (1, col_id),
                            projection='3d',
                            aspect='equal')
    plt.title("1D in 3D", fontsize=font_size)
    som1D_plot.plot3D(ax1D)

    col_id += 1
    plt.subplot2grid((num_rows, num_cols), (1, col_id))
    plt.title("SOM 2D", fontsize=font_size)
    som2D_plot.updateImage()
    plt.axis('off')

    col_id += 1
    ax2D = plt.subplot2grid((num_rows, num_cols), (1, col_id),
                            projection='3d',
                            aspect='equal')
    plt.title("2D in 3D", fontsize=font_size)
    som2D_plot.plot3D(ax2D)

    result_file = resultFile("%s_multi" % data_name)
    plt.savefig(result_file)