def displayimage(path_pixels, control_points_1d):
    if path_pixels=="Not found the path":
        print("Sorry Unable to find the path")
        return 0
    im=Image.open("dataset/terrain.png")
    pixelMap = im.load()
    img = Image.new(im.mode, im.size)
    pixelsNew = img.load()
     
        
    for i in range(img.size[1]):
        for j in range(img.size[0]):
            pixelsNew[j,i] = pixelMap[j,i]
    for pixel in  path_pixels:
        
            
        j=pixel%width
        i=int(pixel/width)
        if pixel in control_points_1d:
           
            rgb=hex2rgb('#000000')
        else:
            rgb=hex2rgb('#FF0000')
        pixelsNew[j,i]=(rgb[0], rgb[1], rgb[2], 255)
    img.show()       
Example #2
0
def performChecks(image, minchocochips=5):
    '''
    Checks weather the cookie matches the specifications given
    '''

    returnlst = {}

    hori, verti = finddiameter(image)
    if abs(hori - verti) > 1: returnlst.update({'diameter': 'False'})
    else: returnlst.update({'diameter': 'True'})

    countofchoco = countchoco(image)
    if countofchoco < minchocochips:
        returnlst.update({'numberofchips': 'False'})
    else:
        returnlst.update({'numberofchips': 'True'})

    hexcodes = hex_cookie(image)
    flag = True
    for i in hexcodes:
        r, g, b = hex2rgb(i)
        if r < 40 and g < 40 and b < 40:
            flag = False
            break
    if flag: returnlst.update({'color': 'True'})
    else: returnlst.update({'color': 'False'})

    return returnlst
Example #3
0
    def __convert_color(self) -> None:
        """
        Convert color to notation if one is empty
        :return: None
        """

        self.__rgb_color = colormap.hex2rgb("#" + self.__hex_color)
def match_foundation_shade(face_hex, foundation_hex_lst):
    """return the 6 closest distance hex codes"""

    # https://stackoverflow.com/questions/44428315/similar-color-detection-in-python

    # turn face_hex into rgb
    face_rgb = hex2rgb(face_hex)
    # turn this rgb color into a numpy array
    face_arr = np.uint8(np.asarray([[face_rgb]]))
    # convert to lab space
    face_lab = rgb2lab(face_arr)

    rgb_lst = []
    # append each rgb color to a list
    for hex_code in foundation_hex_lst:
        foundation_rgb = hex2rgb(hex_code)
        rgb_lst.append(foundation_rgb)

    # make this spectrum of foundation colors a numpy array
    foundation_arr = np.uint8(np.asarray([rgb_lst]))

    #convert the array to lab space
    foundation_lab = rgb2lab(foundation_arr)

    # get the distance between the face and each foundation color in the lab space
    distance_colors = deltaE_cie76(face_lab, foundation_lab)

    # sort the distance from smallest to biggest
    # the distance will not correspond with your foundation_hex_lst
    # so we have to use argsort, indexes where the distance was before we sorted it
    # back when the distance corresponded with the foundation hex list
    sort_distance = np.argsort(distance_colors)

    sort_distance = sort_distance.squeeze()

    # list of the indexes of the top 6 closest distances, where they were when they lined up
    # with the foundation_hex_lst
    closest_6 = sort_distance[0:6]

    top_6_hex = []

    # no we have to find out which foundation corresponds to these indexes
    for index in closest_6:
        top_6_hex.append(foundation_hex_lst[index])

    return top_6_hex
Example #5
0
def tone_match(color, color_ref='tones.csv', index_name='color_name', color_col='rgb_hex'):
    color_ref = read_csv(color_ref, index_col=index_name)
    
    try:
        rgb_hex = hex2rgb('#'+color if not '#' in color else color) #change hex to decimal for input from user
    except ValueError:
        raise ValueError(f"{color} is not valid hexadecimal color.")

    color_ref[color_col] = color_ref[color_col].apply(hex2rgb) #change hex to decimal in dataframe
    for color_name, color_diff in color_ref[color_col].apply(compare_color, color = rgb_hex).argsort().items():
        if color_diff == 0:
            return color_name
Example #6
0
def transition_values(value_from, value_to, steps=10):
    print('Transition from ' + value_from + ' to ' +
          value_to + ' in ' + str(steps) + ' steps...')
    from_r = hex2rgb(value_from)[0]
    from_g = hex2rgb(value_from)[1]
    from_b = hex2rgb(value_from)[2]
    to_r = hex2rgb(value_to)[0]
    to_g = hex2rgb(value_to)[1]
    to_b = hex2rgb(value_to)[2]
    diff_r = to_r - from_r
    diff_g = to_g - from_g
    diff_b = to_b - from_b
    values = []
    for i in range(steps - 1):
        color = rgb2hex(int(from_r + ((diff_r / steps) * (i + 1))), int(from_g +
                        ((diff_g / steps) * (i + 1))), int(from_b + ((diff_b / steps) * (i + 1))))
        values.append(color)
    values.append(value_to)
    return values
Example #7
0
def lighten_color_hex(col, factor):
    return rgb2hex(*lighten_color(*hex2rgb(col), factor))
Example #8
0
from pathlib import Path
import json

import plot_helpers as helpers

helpers.setup_matplotlib()

covid_textwidth = 469.75499

# `pip install colormap`
from colormap import hex2rgb
muted_colours_list = [
    "#4878D0", "#D65F5F", "#EE854A", "#6ACC64", "#956CB4", "#8C613C",
    "#DC7EC0", "#797979", "#D5BB67", "#82C6E2"
]
muted_colours_list = np.asarray([hex2rgb(_c)
                                 for _c in muted_colours_list]) / 256
muted_colours_dict = {
    'blue': muted_colours_list[0],
    'red': muted_colours_list[1],
    'orange': muted_colours_list[2],
    'green': muted_colours_list[3],
    'purple': muted_colours_list[4],
    'brown': muted_colours_list[5],
    'pink': muted_colours_list[6],
    'gray': muted_colours_list[7],
    'yellow': muted_colours_list[8],
    'eggsh': muted_colours_list[9]
}

Example #9
0
import os

from copy import deepcopy as dc

# Import SEIR module.
import seir as seir

# Limit the number of simulations we plot.
n_sims_to_plot = 100
_sims_to_plot = np.random.randint(0, 1000, n_sims_to_plot)

# `pip install colormap; pip install easydev`
from colormap import hex2rgb
muted_colours_list = ["#4878D0", "#D65F5F", "#EE854A", "#6ACC64", "#956CB4",
                      "#8C613C", "#DC7EC0", "#797979", "#D5BB67", "#82C6E2"]
muted_colours_list = np.asarray([hex2rgb(_c) for _c in muted_colours_list]) / 256
muted_colours_dict = {'blue':   muted_colours_list[0],
                      'red':    muted_colours_list[1],
                      'orange': muted_colours_list[2],
                      'green':  muted_colours_list[3],
                      'purple': muted_colours_list[4],
                      'brown':  muted_colours_list[5],
                      'pink':   muted_colours_list[6],
                      'gray':   muted_colours_list[7],
                      'yellow': muted_colours_list[8],
                      'eggsh':  muted_colours_list[9]}
mcd = muted_colours_dict

# Real misc stuff.
fig_size_wide = (12, 3)
fig_size_small = (4, 4)
Example #10
0
 def fromRGB(hex_color: str):
     return hex2rgb(hex_color)
Example #11
0
    def HexToRGB(self, hex):
        if "#" not in hex:
            hex = "#{}".format(hex)

        return hex2rgb(hex, normalise=False)
Example #12
0
    def display_melon(self):
        # Ref: http://pixelartmaker.com/art/d8f3ce82dd215ed
        self.clear()
        red = (255,0,0)
        black = (0,0,0)
        lila = hex2rgb("#ff99dd") #(255,100,200) #ff99dd
        green1 = hex2rgb("#118233") #COLORS.lime)
        green2 = hex2rgb("#089c48") #COLORS.limegreen

        for h in ["C1","D1","E1","F1","G1"]:
            self.layout.set(self.MAPPING[h], green2)
        for h in ["B2","H2"]:
            self.layout.set(self.MAPPING[h], green2)
        for h in ["C2","D2","E2","F2","G2"]:
            self.layout.set(self.MAPPING[h], green1)
        for h in ["A3","I3"]:
            self.layout.set(self.MAPPING[h], green2)
        for h in ["H3"]:
            self.layout.set(self.MAPPING[h], green1)
        for h in ["B3","C3","D3","E3","F3","G3"]:
            self.layout.set(self.MAPPING[h], lila)
        for h in ["A4","C4","D4","E4","F4","G4"]:
            self.layout.set(self.MAPPING[h], red)
        for h in ["H4"]:
            self.layout.set(self.MAPPING[h], lila)
        for h in ["I4"]:
            self.layout.set(self.MAPPING[h], green1)
        for h in ["J4"]:
            self.layout.set(self.MAPPING[h], green2)
        for h in ["A5","B5","C5","E5","G4"]:
            self.layout.set(self.MAPPING[h], red)
        for h in ["H5"]:
            self.layout.set(self.MAPPING[h], lila)
        for h in ["I5"]:
            self.layout.set(self.MAPPING[h], green1)
        for h in ["J5"]:
            self.layout.set(self.MAPPING[h], green2)
        for h in ["B6","C6","D6","E6","F6","G6"]:
            self.layout.set(self.MAPPING[h], red)
        for h in ["H6"]:
            self.layout.set(self.MAPPING[h], lila)
        for h in ["I6"]:
            self.layout.set(self.MAPPING[h], green1)
        for h in ["J6"]:
            self.layout.set(self.MAPPING[h], green2)
        for h in ["C7","D7","F7","G7"]:
            self.layout.set(self.MAPPING[h], red)
        for h in ["H7"]:
            self.layout.set(self.MAPPING[h], lila)
        for h in ["I7"]:
            self.layout.set(self.MAPPING[h], green1)
        for h in ["J7"]:
            self.layout.set(self.MAPPING[h], green2)
        for h in ["D8","E8","F8"]:
            self.layout.set(self.MAPPING[h], red)
        for h in ["H8"]:
            self.layout.set(self.MAPPING[h], lila)
        for h in ["I8"]:
            self.layout.set(self.MAPPING[h], green1)
        for h in ["J8"]:
            self.layout.set(self.MAPPING[h], green2)
        for h in ["E9","F9"]:
            self.layout.set(self.MAPPING[h], red)
        for h in ["G9"]:
            self.layout.set(self.MAPPING[h], lila)
        for h in ["H9"]:
            self.layout.set(self.MAPPING[h], green1)
        for h in ["I9"]:
            self.layout.set(self.MAPPING[h], green2)
        for h in ["F10"]:
            self.layout.set(self.MAPPING[h], lila)
        for h in ["G10"]:
            self.layout.set(self.MAPPING[h], green1)
        for h in ["H10"]:
            self.layout.set(self.MAPPING[h], green2)

        self.layout.push_to_driver()
        time.sleep(10)