def get_wcs_indicies(args_chroma): wcs_map = build_wcs_map() chips = build_chiplist() inidicies = np.empty((8*40)) color_rgb = np.empty((8*40, 3)) for row in xrange(1, 9): R = chr(ord('A') + row) for col in xrange(1, 41): idx = '%s%d' % (R, col) wcs_chip = wcs_map[idx] if args_chroma > 0: chroma = args_chroma do_fallback = True do_fallthrough = True else: chroma = wcs_chip['chroma'] do_fallback = True do_fallthrough = False chip = lookup_chip(wcs_chip['hue'], wcs_chip['value'], chroma, chips, fallback=do_fallback, fallthrough=do_fallthrough) inidicies[(row-1) * 40 + col-1] = chip['index'] lab = LabColor(*wcs_chip['Lab']) rgb = lab.convert_to('rgb', debug=False, illuminant='d50') color_rgb[(row-1) * 40 + col-1, :] = np.array([rgb.rgb_r, rgb.rgb_g, rgb.rgb_b]) return (inidicies, color_rgb)
def fade_colors_rgb(self,rgbcolor1,rgbcolor2,speed=0.1): """ Values for color conversion: Best result for me: target_illuminant=d50 target_rgb=sRGB target_illuminant= 'a' 'b' 'c' 'd50' 'd55' 'd65' 'd75' 'e' 'f2' 'f7' 'f11' target_rgb= 'adobe_rgb' 'apple_rgb' 'best_rgb' 'bruce_rgb' 'cie_rgb' 'colormatch_rgb' 'don_rgb_4' 'eci_rgb' 'ekta_space_ps5' 'ntsc_rgb' 'pal_secam_rgb' 'prophoto_rgb' 'smpte_c_rgb' 'srgb' 'wide_gamut_rgb' """ rgb1 = RGBColor(rgbcolor1[0],rgbcolor1[1],rgbcolor1[2]) rgb2 = RGBColor(rgbcolor2[0],rgbcolor2[1],rgbcolor2[2]) l1 = rgb1.convert_to('lab',target_illuminant='d50') l2 = rgb2.convert_to('lab',target_illuminant='d50') lab1 =[l1.lab_l,l1.lab_a,l1.lab_b] lab2 =[l2.lab_l,l2.lab_a,l2.lab_b] for i in range(0,self.fade_steps+1): l=self.transition3(i,self.fade_steps,lab1,lab2) lab=LabColor(l[0],l[1],l[2]) r=lab.convert_to('rgb') rgb=[r.rgb_r,r.rgb_g,r.rgb_b] self.set_color_rgb(rgb) sleep(speed)
def wcs_gen_chip(chip): lab = LabColor(*chip['Lab']) rgb = lab.convert_to('rgb', debug=False, illuminant='d50') img = np.ones((100, 100, 3)) img[:,:,0] *= rgb.rgb_r / 255.0 img[:,:,1] *= rgb.rgb_g / 255.0 img[:,:,2] *= rgb.rgb_b / 255.0 return img
def example_lab_to_xyz(): """ This function shows a simple conversion of an Lab color to an XYZ color with debugging on (to show verbose output so you can see what the library is doing for you). """ print "=== Simple Example: Lab->XYZ ===" # Instantiate an Lab color object with the given values. lab = LabColor(0.903, 16.296, -2.22) # Show a string representation. print lab # Convert to XYZ. xyz = lab.convert_to('xyz', debug=False) print xyz print "=== End Example ===\n"
def example_lab_to_xyz(): """ This function shows a simple conversion of an Lab color to an XYZ color with debugging on (to show verbose output so you can see what the library is doing for you). """ print "=== Simple Example: Lab->XYZ ===" # Instantiate an Lab color object with the given values. lab = LabColor(0.903, 16.296, -2.22) # Show a string representation. print lab # Convert to XYZ. xyz = lab.convert_to('xyz', debug=False) print xyz print "=== End Example ===\n"
def example_lab_to_rgb(): """ Conversions to RGB are a little more complex mathematically. There are also several kinds of RGB color spaces. When converting from a device-independent color space to RGB, sRGB is assumed unless otherwise specified with the target_rgb keyword arg. """ print "=== RGB Example: Lab->RGB ===" # Instantiate an Lab color object with the given values. lab = LabColor(0.903, 16.296, -2.217) # Show a string representation. print lab # Convert to XYZ. rgb = lab.convert_to('rgb', target_rgb='sRGB', debug=False) print rgb print "=== End Example ===\n"
def example_lab_to_rgb(): """ Conversions to RGB are a little more complex mathematically. There are also several kinds of RGB color spaces. When converting from a device-independent color space to RGB, sRGB is assumed unless otherwise specified with the target_rgb keyword arg. """ print "=== RGB Example: Lab->RGB ===" # Instantiate an Lab color object with the given values. lab = LabColor(0.903, 16.296, -2.217) # Show a string representation. print lab # Convert to XYZ. rgb = lab.convert_to('rgb', target_rgb='sRGB', debug=False) print rgb print "=== End Example ===\n"
def blend(color1, color2, percentColor1=0.5): percentColor2 = 1.0-percentColor1 # Convert from QColor to lab c1Alpha = color1.alpha() color1 = RGBColor(color1.red(),color1.green(),color1.blue()).convert_to('lab') c2Alpha = color2.alpha() color2 = RGBColor(color2.red(),color2.green(),color2.blue()).convert_to('lab') # Interpolate the colors in lab space result = LabColor(color1.lab_l*percentColor1+color2.lab_l*percentColor2, color1.lab_a*percentColor1+color2.lab_a*percentColor2, color1.lab_b*percentColor1+color2.lab_b*percentColor2) resultAlpha = c1Alpha*percentColor1 + c2Alpha*percentColor2 # Convert back to QColor result = result.convert_to('rgb') return QColor.fromRgba(result.rgb_r,result.rgb_g,result.rgb_b,resultAlpha)
def Msh_RGB(M,s,h): L,a,b = MSH_Lab(M,s,h) colour = LabColor(L,a,b,illuminant='d65') RGB = colour.convert_to('RGB') return RGB.rgb_r/255.,RGB.rgb_g/255.,RGB.rgb_b/255.
def lab_to_rgb(lab): labcolor = LabColor(*lab) rgbcolor = labcolor.convert_to('rgb') return (rgbcolor.rgb_r, rgbcolor.rgb_g, rgbcolor.rgb_b)
def lab_to_hsv(lab): labcolor = LabColor(*lab) hsvcolor = labcolor.convert_to('hsv') return (hsvcolor.hsv_h, hsvcolor.hsv_s, hsvcolor.hsv_v)