コード例 #1
0
ファイル: utils.py プロジェクト: hminle/palette-app
def generateLocalPalettes(input_img, row_step, col_step, overlap_size, total_slides):
    count = 0
    localPalettesList = []
    height = input_img.shape[0]
    width = input_img.shape[1]
    for i in range(0, height, row_step):
        if i + row_step > height:
            continue
        else:
            for j in range(0, width, col_step):
                if j + col_step > width:
                    continue
                else:
                    count += 1
                    if count <= total_slides:
                        row_step_final = row_step if ((i + row_step + overlap_size) > height) else (row_step + overlap_size)
                        col_step_final = col_step if ((j + col_step + overlap_size) > width) else (col_step + overlap_size) 
                        sample_img = input_img[i : i + row_step_final, j : j + col_step_final, :]

                        hist3D = Hist3D(sample_img, num_bins=16, color_space='Lab')
                        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=70.0)
                        localPalettesList.append(palette_selection.paletteColors())
                    else: 
                        break
    return localPalettesList
コード例 #2
0
ファイル: utils.py プロジェクト: hminle/palette-app
def generateGlobalPalettes(input_img, palette_num=5):
    hist3D = Hist3D(input_img, num_bins=16, color_space='Lab')
    color_coordinates = hist3D.colorCoordinates()
    color_densities = hist3D.colorDensities()
    rgb_colors = hist3D.rgbColors()
    palette_selection = PaletteSelection(color_coordinates,
                                        color_densities, rgb_colors,
                                        num_colors=palette_num, sigma=70.0)
    return palette_selection.paletteColors()
コード例 #3
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)
コード例 #4
0
image_file = dataFile("flower", 0)

# Load image.
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.
コード例 #5
0
image_file = dataFile("flower", 0)

# Load image.
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')
コード例 #6
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)