Exemplo n.º 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)

    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("Palette Selection for Single Image", fontsize=font_size)

    fig.add_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')

    color_spaces = ["rgb", "Lab"]
    sigmas = [0.7, 70.0]

    plot_id = 232
    num_cols = 3

    for color_space, sigma in zip(color_spaces, sigmas):
        hist3D = Hist3D(image, num_bins=16, color_space=color_space)
        color_coordinates = hist3D.colorCoordinates()
        color_densities = hist3D.colorDensities()
        rgb_colors = hist3D.rgbColors()

        palette_selection = PaletteSelection(color_coordinates,
                                             color_densities, rgb_colors,
                                             num_colors=5, sigma=sigma)

        plt.subplot(plot_id)
        plt.title("Palette Colors from %s" % color_space)
        palette_selection.plot(plt)
        plt.axis('off')

        plot_id += 1

        ax = fig.add_subplot(plot_id, projection='3d')
        plt.title("%s 3D Histogram" % color_space, fontsize=font_size)
        hist3D.plot(ax)

        plot_id += num_cols - 1

    result_file = resultFile("%s_single" % image_name)
    plt.savefig(result_file)
Exemplo n.º 2
0
image = loadRGB(image_file)

# 16 bins, Lab color space
hist3D = Hist3D(image, num_bins=16, color_space='Lab')

color_coordinates = hist3D.colorCoordinates()
color_densities = hist3D.colorDensities()
rgb_colors = hist3D.rgbColors()

# 5 colors from Lab color samples.
palette_selection = PaletteSelection(color_coordinates,
                                             color_densities, rgb_colors,
                                             num_colors=5, sigma=70.0)

fig = plt.figure()

# Plot image.
fig.add_subplot(131)
plt.imshow(image)
plt.axis('off')

# Plot palette colors.
fig.add_subplot(132)
palette_selection.plot(plt)
plt.axis('off')

# Plot 3D color histogram.
ax = fig.add_subplot(133, projection='3d')
hist3D.plot(ax)

plt.show()
Exemplo n.º 3
0
# 16 bins, Lab color space
hist3D = Hist3D(image, num_bins=16, color_space='Lab')

color_coordinates = hist3D.colorCoordinates()
color_densities = hist3D.colorDensities()
rgb_colors = hist3D.rgbColors()

# 5 colors from Lab color samples.
palette_selection = PaletteSelection(color_coordinates,
                                     color_densities,
                                     rgb_colors,
                                     num_colors=5,
                                     sigma=70.0)

fig = plt.figure()

# Plot image.
fig.add_subplot(131)
plt.imshow(image)
plt.axis('off')

# Plot palette colors.
fig.add_subplot(132)
palette_selection.plot(plt)
plt.axis('off')

# Plot 3D color histogram.
ax = fig.add_subplot(133, projection='3d')
hist3D.plot(ax)

plt.show()
Exemplo n.º 4
0
def multiImagesResult(data_name, data_ids):

    num_cols = len(data_ids)
    num_rows = 2

    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("Palette Selection for Multi Images", fontsize=font_size)

    rgb_pixels = []
    plot_id = num_rows * 100 + 10 * num_cols + 1
    for data_id in data_ids:
        image_file = dataFile(data_name, data_id)
        image = loadRGB(image_file)

        rgb_pixels.extend(ColorPixels(image).rgb())

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

        plot_id += 1

    color_space = "Lab"
    sigma = 70.0

    plot_id = num_rows * 100 + 10 * num_cols + num_cols + 2

    rgb_pixels = np.array(rgb_pixels)

    multi_image = np.array(rgb_pixels).reshape(1, -1, 3)

    hist3D = Hist3D(multi_image, num_bins=16, color_space=color_space)
    color_coordinates = hist3D.colorCoordinates()
    color_densities = hist3D.colorDensities()
    rgb_colors = hist3D.rgbColors()

    palette_selection = PaletteSelection(color_coordinates,
                                         color_densities,
                                         rgb_colors,
                                         num_colors=5,
                                         sigma=sigma)

    plt.subplot(plot_id)
    plt.title("Palette Colors from %s" % color_space)
    palette_selection.plot(plt)
    plt.axis('off')

    plot_id += 1

    ax = fig.add_subplot(plot_id, projection='3d')
    plt.title("%s 3D Histogram" % color_space, fontsize=font_size)
    hist3D.plot(ax)

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