def get_best_same_color_text(web_hex_str, lum_min=0.1): '''Returns biggest YIQ contrast''' r, g, b = hex_to_rgb(web_hex_str) r, g, b = scale_rgb_tuple((r, g, b), down=True) y, i, q = colorsys.rgb_to_yiq(r, g, b) if y > 0.5: rgb_float = colorsys.yiq_to_rgb(lum_min, i, q) else: rgb_float = colorsys.yiq_to_rgb(1.0 - lum_min, i, q) #print 'y,i,q=',y,i,q, ' rgb_float=',rgb_float return rgbfloat_to_hex(rgb_float)
def get_best_same_color_text(web_hex_str, lum_min=0.1): '''Returns biggest YIQ contrast''' r,g,b = hex_to_rgb(web_hex_str) r,g,b = scale_rgb_tuple((r,g,b), down=True) y,i,q = colorsys.rgb_to_yiq( r,g,b ) if y>0.5: rgb_float = colorsys.yiq_to_rgb(lum_min,i,q) else: rgb_float = colorsys.yiq_to_rgb(1.0-lum_min,i,q) #print 'y,i,q=',y,i,q, ' rgb_float=',rgb_float return rgbfloat_to_hex(rgb_float)
def test_yiq(): a = [0,0,0,0,0,0] a[0] = (145, 149, 152) a[1] = (151, 155, 158) a[2] = (127, 131, 134) a[3] =(86, 90, 93) a[4] = (61, 66, 70) a[5] = (57, 62, 2) for nn in a: n = [float(m)/255 for m in nn] yiq = colorsys.rgb_to_yiq(*n) #r = (int(yiq[0]),int(yiq[1]),int(yiq[2])) rgb = colorsys.yiq_to_rgb(*yiq) r = (int(rgb[0]*255), int(rgb[1]*255), int(rgb[2]*255)) print n, yiq, colorsys.yiq_to_rgb(*yiq), r, nn
def background_color(self): try: hex_color = self.info['background_color'] except KeyError: return TingApp.default_background_color try: color = _hex_color_to_tuple(hex_color) except: logging.exception('Failed to parse hex color, using default') return TingApp.default_background_color # colorsys works with colors between 0 and 1 fractional_color = _color_multiply(color, 1/255.0) y, i, q = colorsys.rgb_to_yiq(*fractional_color) if y > 0.6: y = 0.6 fractional_color = colorsys.yiq_to_rgb(y, i, q) color = _color_multiply(fractional_color, 255) logging.warning( 'Background color was too bright (white text must be visible on top of this ' 'color), color "%s" was darkened to "%s"' % (hex_color, _tuple_to_hex_color(color))) return color
def rgb_shader(t, t_min=0, t_max=1, color1=(0.94, 0.02, 0.55), color2=(0.11, 0.78, 0.72)): """ Linear interpolation between 2 colors `color1` and `color2` :param t: variable :param t_min: lower bound of variable `t` :param t_max: upper bound of variable `t` :param color1: hex or float color in RGB :param color2: hex or float color in RGB :return: float color in RGB """ # proportion of `t` t = (t - t_min) / (t_max - t_min) # if input colors are hex strings, convert them to float triples if isinstance(color1, str): color1 = hex2float(color1) if isinstance(color2, str): color2 = hex2float(color2) # convert `color1` and `color2` to yiq space for better gradient visuals color1 = cs.rgb_to_yiq(*color1) color2 = cs.rgb_to_yiq(*color2) # return color at `t` using linear interpolation return cs.yiq_to_rgb( *[t * c2 + (1.00 - t) * c1 for (c1, c2) in zip(color1, color2)])
def add_rgb(self, add_val: ColSpaceVal, color_space: str = 'hsv', quiet: bool = True) -> None: """ Add new color to color dictionary. Key will be hex rgb string, value will be original color map value or yiq if orig is rgb. :param add_val: Three element tuple of color in given color space. :param color_space: Name of color space used to generate colors. :param quiet: More output if True """ if color_space == 'yiq': rgb_tup = colorsys.yiq_to_rgb(*add_val) self.maps[1] = 'yiq' elif color_space == 'rgb': rgb_tup = add_val add_val = colorsys.rgb_to_yiq(*add_val) self.maps[1] = 'yiq' else: rgb_tup = colorsys.hsv_to_rgb(*add_val) self.maps[1] = 'hsv' if rgb_tup[0] < 0 or rgb_tup[1] < 0 or rgb_tup[2] < 0: print('RGB error: {}'.format(rgb_tup)) return hex_rgb = '#{:02x}{:02x}{:02x}'.format(int(rgb_tup[0]*255), int(rgb_tup[1]*255), int(rgb_tup[2]*255)) if not quiet: print('rgb: {}, {}: ({:.2f}, {:.2f}, {:.2f})'.format(hex_rgb, self.maps[1], *add_val)) self.colors.update({hex_rgb: add_val}) self.counter += 1 return
def yiq_to_rgb(YIQ): RGBn = np.zeros((ancho, alto, dim)) for x in range(ancho): for y in range(alto): RGBn[x, y, :] = cs.yiq_to_rgb(YIQ[x, y, 0], YIQ[x, y, 1], YIQ[x, y, 2]) return RGBn
def yiq2rgb(image): """ Converts image from YIQ colorscheme to RGB. """ return np.array([ colorsys.yiq_to_rgb(*pixel) for pixel in image.reshape([-1, 3]) ]).reshape(image.shape)
def test_yiq_roundtrip(self): for r in frange(0.0, 1.0, 0.2): for g in frange(0.0, 1.0, 0.2): for b in frange(0.0, 1.0, 0.2): rgb = (r, g, b) self.assertTripleEqual( rgb, colorsys.yiq_to_rgb(*colorsys.rgb_to_yiq(*rgb)))
def __style__(self): """ Generate the color associated to the symbol's namespace. The color is generated using the md5-encoding of the namespace and is uniform in the YIQ color space where Y=0.5 (Y being the brightness, so the color should contrast nicely on a white background). """ if isinstance(self.label, Symbol): return self.label.__style__() hn = int(md5(self.namespace.encode()).hexdigest(), 16) # The offsets were cherry-picked to make global::builtin blue. hn1 = ((hn >> 32) & 0xFF) / 256 hn2 = ((hn >> 16) & 0xFF) / 256 y = 0.5 i = (hn1 * 2 - 1) * 0.5957 q = (hn2 * 2 - 1) * 0.5226 r, g, b = colorsys.yiq_to_rgb(y, i, q) r = int(r * 256) g = int(g * 256) b = int(b * 256) style = f'color:rgb({r}, {g}, {b})' if self.namespace.startswith('global:'): style += ';font-style:italic' return style
def background_color(self): try: hex_color = self.info['background_color'] except KeyError: return TingApp.default_background_color try: color = _hex_color_to_tuple(hex_color) except: logging.exception('Failed to parse hex color, using default') return TingApp.default_background_color # colorsys works with colors between 0 and 1 fractional_color = _color_multiply(color, 1 / 255.0) y, i, q = colorsys.rgb_to_yiq(*fractional_color) if y > 0.6: y = 0.6 fractional_color = colorsys.yiq_to_rgb(y, i, q) color = _color_multiply(fractional_color, 255) logging.warning( 'Background color was too bright (white text must be visible on top of this ' 'color), color "%s" was darkened to "%s"' % (hex_color, _tuple_to_hex_color(color))) return color
def yiq_mixer(color1, color2): rgb1, rgb2 = hex_to_rgb(color1), hex_to_rgb(color2) x1, y1, z1 = colorsys.rgb_to_hls(rgb1) x2, y2, z2 = colorsys.rgb_to_hls(rgb2) ans = ((x1 + x2)/2, (y1 + y2)/2 , (z1 + z2)/2) ans = _hls_to_yiq(*ans) ans = colorsys.yiq_to_rgb(*ans) return "#%02x%02x%02x" % ans
def yiq(start, amount, saturation, luminosity): step = 360/amount ans = ((start + i*step, luminosity, saturation) for i in range(amount)) ans = (_hls_to_yiq(H, L, S) for H, L, S in ans) ans = (colorsys.yiq_to_rgb(y, i, q) for y, i, q in ans) ans = (_rgb1_to_rgb255(r, g, b) for r, g, b in ans) ans = (("#%02x%02x%02x" % (r, g, b), r, g, b) for r, g, b in ans) return ans
def parse_yiq(data): """ Parses YIQ color bytes and returns fill style list. """ y = ord(data[0]) / 255.0 i = 2.0 * ord(data[1]) / 255.0 - 1.0 q = 2.0 * ord(data[2]) / 255.0 - 1.0 r, g, b = yiq_to_rgb(y, i, q) return [uc2const.COLOR_RGB, [r, g, b], 1.0, '']
def cconvert(s): # Try HTML and CSS names. 'webcolors' returns as $RRGGBB. rgbString = None if (s in webcolors.HTML4_NAMES_TO_HEX): rgbString = webcolors.HTML4_NAMES_TO_HEX[s] #print("Found '%s' in HTML4 colors. Got: %s." % (s, rgbString)) elif (s in webcolors.CSS2_NAMES_TO_HEX): rgbString = webcolors.CSS2_NAMES_TO_HEX[s] #print("Found '%s' in CSS2 colors. Got: %s." % (s, rgbString)) elif (s in webcolors.CSS21_NAMES_TO_HEX): rgbString = webcolors.CSS21_NAMES_TO_HEX[s] #print("Found '%s' in CSS2.1 colors. Got: %s." % (s, rgbString)) elif (s in webcolors.CSS3_NAMES_TO_HEX): rgbString = webcolors.CSS3_NAMES_TO_HEX[s] #print("Found '%s' in CSS3 colors. Got: %s." % (s, rgbString)) if (rgbString is not None): s = rgbString # Try functional notations, like 'rgb(12, 50%, 0xA0)' mat = re.match(functionExpr, s) if (mat): #print("functional") func = mat.group(1) a1 = convertNumber(mat.group(2)) a2 = convertNumber(mat.group(3)) a3 = convertNumber(mat.group(4)) # TODO: Do something with alpha.... # if (mat.group(5)): alpha = convertNumber(mat.group(5)) # else: alpha = 0 if (func == 'rgb' or func == 'rgba'): rgbTriple = [ a1, a2, a3 ] elif (func == 'hls'): rgbTriple = colorsys.hls_to_rgb(a1, a2, a3) elif (func == 'hsv'): rgbTriple = colorsys.hsv_to_rgb(a1, a2, a3) elif (func == 'yiq'): rgbTriple = colorsys.yiq_to_rgb(a1, a2, a3) else: raise ValueError('Unrecognized scheme "%s".' % (func)) # Try the #RRGGBB types (including re-processing ones from names!) elif (s.startswith('#')): if (len(s) % 3 != 1): raise ValueError('Bad length for #rgb color.') per = int(len(s)/3) #print("rgb%d" % (per)) rgbTriple = [ ] for i in range(3): piece = s[per*i+1:per*i+per+1] if (len(piece)==1): piece += piece rgbTriple.append(convertNumber('0x' + piece)) else: raise ValueError('Unrecognized syntax: "%s".' % (s)) return(rgbTriple)
def test_yiq_roundtrip(self): for r in frange(0.0, 1.0, 0.2): for g in frange(0.0, 1.0, 0.2): for b in frange(0.0, 1.0, 0.2): rgb = (r, g, b) self.assertTripleEqual( rgb, colorsys.yiq_to_rgb(*colorsys.rgb_to_yiq(*rgb)) )
def transform(self, default_value, add_luma=0.0): if self.inverted: dy, di, dq = colorsys.rgb_to_yiq(*hex_to_rgb(default_value)) dy = 1 - dy if dy < 0.5: dy += add_luma r, g, b = colorsys.yiq_to_rgb(dy, di, dq) return rgb_to_hex(r, g, b) return default_value
def transform(self, default_value, add_luma=0.0): if self.inverted: dy, di, dq = hex_to_yiq(default_value) dy = 1 - dy if dy < 0.5: dy += add_luma r, g, b = colorsys.yiq_to_rgb(dy, di, dq) return rgb_to_hex(r, g, b) return default_value
def parse_yiq(data): """ Parses YIQ color bytes and returns fill style list. """ y = data[0] / 255.0 i = 2.0 * data[1] / 255.0 - 1.0 q = 2.0 * data[2] / 255.0 - 1.0 r, g, b = yiq_to_rgb(y, i, q) return [uc2const.COLOR_RGB, [r, g, b], 1.0, '']
def YIQ_to_RGB(self, components): # same comments as above apply I_max = colorsys.rgb_to_yiq(1, 0, 0)[1] Q_max = colorsys.rgb_to_yiq(1, 0, 1)[2] normalised = tuple(x / u for x, u in zip(components, self.supported_colour_models['YIQ'].maximum)) normalised = (normalised[0], normalised[1] * I_max, normalised[2] * Q_max) changed = colorsys.yiq_to_rgb(*normalised) denormalised = [l + x * (u - l) for x, l, u in zip(changed, self.supported_colour_models['RGB'].minimum, self.supported_colour_models['RGB'].maximum)] return [round(item) for item in denormalised]
def yuv_channels_to_rgb(cY, cU, cV): ansRGB = [ colorsys.yiq_to_rgb(cY[i], cU[i], cV[i]) for i in range(len(ansY)) ] ansRGB = np.array(ansRGB) pic_ansRGB = np.zeros(pic_yuv.shape) pic_ansRGB[:, :, 0] = ansRGB[:, 0].reshape(pic_rows, pic_cols, order='F') pic_ansRGB[:, :, 1] = ansRGB[:, 1].reshape(pic_rows, pic_cols, order='F') pic_ansRGB[:, :, 2] = ansRGB[:, 2].reshape(pic_rows, pic_cols, order='F') return pic_ansRGB
def transform(self, default_value, add_luma=0.0): if default_value == IGNORE_COLOR_VALUE: return IGNORE_COLOR_VALUE if self.inverted: dy, di, dq = hex_to_yiq(default_value) dy = 1 - dy if dy < 0.5: dy += add_luma r, g, b = colorsys.yiq_to_rgb(dy, di, dq) return rgb_to_hex(r, g, b) return default_value
def forceBrightness(color, brightness): src_r, src_g, src_b = color u = ledstrip.NCOLS - 1 src_ar = float(src_r) / u src_ag = float(src_g) / u src_ab = float(src_b) / u # converts to yiq and replaces luma (y) with specified brightness _y, i, q = colorsys.rgb_to_yiq(src_ar, src_ag, src_ab) dst_ar, dst_ag, dst_ab = colorsys.yiq_to_rgb(brightness, i, q) return (int(round(dst_ar * u)), int(round(dst_ag * u)), int(round(dst_ab * u)))
def pixelsToPoints(im, pixels): #default background color is black for p in pixels: if type(p[0][0]) == float: #YIQ value im.putpixel( p[1], tuple([ int(v * 255) for v in colorsys.yiq_to_rgb(p[0][0], p[0][1], p[0][2]) ])) else: im.putpixel(p[1], p[0])
def test_yiq_values(self): values = [((0.0, 0.0, 0.0), (0.0, 0.0, 0.0)), ((0.0, 0.0, 1.0), (0.11, -0.3217, 0.3121)), ((0.0, 1.0, 0.0), (0.59, -0.2773, -0.5251)), ((0.0, 1.0, 1.0), (0.7, -0.599, -0.213)), ((1.0, 0.0, 0.0), (0.3, 0.599, 0.213)), ((1.0, 0.0, 1.0), (0.41, 0.2773, 0.5251)), ((1.0, 1.0, 0.0), (0.89, 0.3217, -0.3121)), ((1.0, 1.0, 1.0), (1.0, 0.0, 0.0)), ((0.5, 0.5, 0.5), (0.5, 0.0, 0.0))] for rgb, yiq in values: self.assertTripleEqual(yiq, colorsys.rgb_to_yiq(*rgb)) self.assertTripleEqual(rgb, colorsys.yiq_to_rgb(*yiq))
def imageAnalogy(A_RGB,A_PRIME_RGB,B_RGB): ### return values #### B_PRIME_RGB = np.zeros(B_RGB.shape,dtype=np.float32) B_PRIME_RGB_SAVE = np.zeros(B_RGB.shape,dtype=np.float32) ######### convert each image to YIQ format ########### A_Y = np.zeros(A_RGB.shape[0:2], dtype=np.float32) A_PRIME_Y = np.zeros(A_PRIME_RGB.shape[0:2], dtype=np.float32) B_Y = np.zeros(B_RGB.shape[0:2], dtype=np.float32) A_I = np.zeros(A_RGB.shape[0:2], dtype=np.float32) A_PRIME_I = np.zeros(A_PRIME_RGB.shape[0:2], dtype=np.float32) B_I = np.zeros(B_RGB.shape[0:2], dtype=np.float32) A_Q = np.zeros(A_RGB.shape[0:2], dtype=np.float32) A_PRIME_Q = np.zeros(A_PRIME_RGB.shape[0:2], dtype=np.float32) B_Q = np.zeros(B_RGB.shape[0:2], dtype=np.float32) B_PRIME_Y = np.zeros(B_RGB.shape[0:2],dtype=np.float32) h,w = B_RGB.shape[0:2] S_Y = np.zeros((h,w,2),dtype=np.uint16) A_Y,A_I,A_Q = convertToYIQ(A_RGB) B_Y,B_I,B_Q = convertToYIQ(B_RGB) A_PRIME_Y,A_PRIME_I,A_PRIME_Q=convertToYIQ(A_PRIME_RGB) luminanceRemap(A_Y,B_Y) luminanceRemap(A_PRIME_Y,B_Y) s_map = createImageAnalogy(A_Y,A_PRIME_Y,B_Y,B_PRIME_Y,S_Y) #from last stage of pyramid,copy the calculated feature h,w = B_RGB.shape[0:2] for i in range(h): for j in range(w): source = s_map[i,j] y = A_PRIME_Y[source[0],source[1]] ii = B_I[i,j] q = B_Q[i,j] #i = A_PRIME_I[source[0],source[1]] #q = A_PRIME_Q[source[0],source[1]] r,g,b = colorsys.yiq_to_rgb(y,ii,q) B_PRIME_RGB[i,j] = b,g,r B_PRIME_RGB_SAVE[i,j] = B_PRIME_RGB[i,j]*255 return B_PRIME_RGB,B_PRIME_RGB_SAVE
def callahan_colour_table(): from colorsys import yiq_to_rgb colour_table = np.ones((16, 4), dtype=np.uint8) for iv in range(16): a = iv & 1 b = (iv >> 1) & 1 c = (iv >> 2) & 1 d = (iv >> 3) & 1 y = (a + b + c + d) / 4.0 i = ((a - b) + (c - d)) / 3.0 q = ((a - c) + (b - d)) / 3.0 colour_table[iv, :3] = [int(x * 255) for x in yiq_to_rgb(y, i, q)] return colour_table
def if_darker(ArregloImagen1,ArregloImagen2,ancho,alto,RGBnuevo,RGBnormalizado1,RGBnormalizado2,YIQ_1,YIQ_2,YIQ): for x in range(ancho): for y in range(alto): YIQ_1[x,y,:]=cs.rgb_to_yiq(RGBnormalizado1[x,y,0],RGBnormalizado1[x,y,1],RGBnormalizado1[x,y,2]) YIQ_2[x,y,:]=cs.rgb_to_yiq(RGBnormalizado2[x,y,0],RGBnormalizado2[x,y,1],RGBnormalizado2[x,y,2]) if YIQ_1[x,y,0]<=YIQ_2[x,y,0]: YIQ=YIQ_1 else: YIQ=YIQ_2 RGBnuevo[x,y]=cs.yiq_to_rgb(YIQ[x,y,0],YIQ[x,y,1],YIQ[x,y,2]) plt.imshow(RGBnuevo) plt.imsave('if_darker.jpg',RGBnuevo)
def load_textmate_scheme(tmtheme): themeDict = plistlib.readPlist(tmtheme) all_settings = themeDict['settings'] used_scopes = set() default_settings = find_by_scope(all_settings, None) if not default_settings: print "Cannot find default settings" return default_settings = default_settings['settings'] text.value = attr_from_textmate(default_settings, None, None) background = default_settings['background'] all_colors['CARET_COLOR'] = color_from_textmate(default_settings['caret']) all_colors['INDENT_GUIDE'] = color_from_textmate(default_settings['invisibles'], background) all_colors['SELECTED_INDENT_GUIDE'] = all_colors['INDENT_GUIDE'] all_colors['WHITESPACES'] = color_from_textmate(default_settings['invisibles'], background) all_colors["GUTTER_BACKGROUND"] = color_from_textmate(background) all_colors["LINE_NUMBERS_COLOR"] = color_from_textmate(default_settings['foreground']) selection_background = color_from_textmate(default_settings['selection'], background) caret_row_color = color_from_textmate(default_settings['lineHighlight'], background) if selection_background == caret_row_color: y, i, q = hex_to_yiq(caret_row_color) if y < 0.5: y /= 2 else: y += 0.2 caret_row_color = rgb_to_hex(*colorsys.yiq_to_rgb(y, i, q)) all_colors['CARET_ROW_COLOR'] = caret_row_color all_colors['SELECTION_BACKGROUND'] = selection_background all_colors['CONSOLE_BACKGROUND_KEY'] = text.value.background blend_spy_js_attributes(background) for attr in all_attributes: if attr.scope: settings = find_by_scope(all_settings, attr.scope) if settings: the_scope = settings['scope'] if the_scope: print "converting attribute " + attr.id + " from TextMate scope " + the_scope used_scopes.add(the_scope) attr.value = attr_from_textmate(settings['settings'], attr.value, background) else: print "[!] scope not found: " + attr.scope return all_settings, used_scopes
def yiqtorgb(yiq): """ Convert the given colour in YIQ space to RGB space Argument is a 3-tuple of float YIQ values in the range (0~1, -1~1, -1~1). Return a 3-tuple of float RGB values in the range 0~1. """ if len(yiq) != 3: raise ValueError("expected a 3-tuple") if yiq[0] < 0 or yiq[0] > 1: raise ValueError("expected luma value in the range 0~1") for i in yiq[1:]: if i < -1 or i > 1: raise ValueError("expected chrominance values in the range 0~1") return colorsys.yiq_to_rgb(*yiq)
def set_v1_colors(self): rclr = self.cmx_model.chunk_map[cmx_const.RCLR_ID] colors = rclr.data['colors'] for model, _pal, vals in colors: model = cmx_const.COLOR_MODEL_MAP.get(model, cmx_const.CMX_INVALID) clr = sk2const.CMYK_BLACK if model == cmx_const.CMX_CMYK: vals = cms.val_100_to_dec(vals) clr = [uc2const.COLOR_CMYK, vals, 1.0, ''] elif model == cmx_const.CMX_CMYK255: vals = cms.val_255_to_dec(vals) clr = [uc2const.COLOR_CMYK, vals, 1.0, ''] elif model == cmx_const.CMX_CMY: vals = cms.val_255_to_dec(vals) + (0.0, ) clr = [uc2const.COLOR_CMYK, vals, 1.0, ''] elif model == cmx_const.CMX_RGB: vals = cms.val_255_to_dec(vals) clr = [uc2const.COLOR_RGB, vals, 1.0, ''] elif model == cmx_const.CMX_HSB: first = vals[0] * 255 + vals[1] \ if self.rifx else vals[0] + vals[1] * 255 vals = (first / 360.0, vals[2] / 255.0, vals[3] / 255.0) r, g, b = colorsys.hsv_to_rgb(*vals) clr = [uc2const.COLOR_RGB, [r, g, b], 1.0, ''] elif model == cmx_const.CMX_HLS: first = vals[0] * 255 + vals[1] \ if self.rifx else vals[0] + vals[1] * 255 vals = (first / 360.0, vals[2] / 255.0, vals[3] / 255.0) r, g, b = colorsys.hls_to_rgb(*vals) clr = [uc2const.COLOR_RGB, [r, g, b], 1.0, ''] elif model == cmx_const.CMX_BW: vals = [1.0, 1.0, 1.0] if vals[0] else [0.0, 0.0, 0.0] clr = [uc2const.COLOR_RGB, vals, 1.0, ''] elif model == cmx_const.CMX_GRAY: clr = [uc2const.COLOR_GRAY, [ vals[0] / 255.0, ], 1.0, ''] elif model == cmx_const.CMX_YIQ255: y = vals[0] / 255.0 i = 2.0 * vals[1] / 255.0 - 1.0 q = 2.0 * vals[2] / 255.0 - 1.0 r, g, b = colorsys.yiq_to_rgb(y, i, q) clr = [uc2const.COLOR_RGB, [r, g, b], 1.0, ''] elif model == cmx_const.CMX_LAB: vals = cms.val_255_to_dec(vals) clr = [uc2const.COLOR_LAB, vals, 1.0, ''] self._colors.append(clr)
def test_yiq_values(self): values = [ # rgb, yiq ((0.0, 0.0, 0.0), (0.0, 0.0, 0.0)), # black ((0.0, 0.0, 1.0), (0.11, -0.3217, 0.3121)), # blue ((0.0, 1.0, 0.0), (0.59, -0.2773, -0.5251)), # green ((0.0, 1.0, 1.0), (0.7, -0.599, -0.213)), # cyan ((1.0, 0.0, 0.0), (0.3, 0.599, 0.213)), # red ((1.0, 0.0, 1.0), (0.41, 0.2773, 0.5251)), # purple ((1.0, 1.0, 0.0), (0.89, 0.3217, -0.3121)), # yellow ((1.0, 1.0, 1.0), (1.0, 0.0, 0.0)), # white ((0.5, 0.5, 0.5), (0.5, 0.0, 0.0)), # grey ] for (rgb, yiq) in values: self.assertTripleEqual(yiq, colorsys.rgb_to_yiq(*rgb)) self.assertTripleEqual(rgb, colorsys.yiq_to_rgb(*yiq))
def load_textmate_scheme(tmtheme): themeDict = plistlib.readPlist(tmtheme) all_settings = themeDict['settings'] used_scopes = set() default_settings = find_by_scope(all_settings, None) if not default_settings: print "Cannot find default settings" return default_settings = default_settings['settings'] text.value = attr_from_textmate(default_settings, None, None) background = default_settings['background'] all_colors['CARET_COLOR'] = color_from_textmate(default_settings['caret']) all_colors['INDENT_GUIDE'] = color_from_textmate(default_settings['invisibles'], background) all_colors['SELECTED_INDENT_GUIDE'] = all_colors['INDENT_GUIDE'] all_colors['WHITESPACES'] = color_from_textmate(default_settings['invisibles'], background) all_colors["GUTTER_BACKGROUND"] = color_from_textmate(background) all_colors["LINE_NUMBERS_COLOR"] = color_from_textmate(default_settings['foreground']) selection_background = color_from_textmate(default_settings['selection'], background) caret_row_color = color_from_textmate(default_settings['lineHighlight'], background) if selection_background == caret_row_color: y, i, q = hex_to_yiq(caret_row_color) if y < 0.5: y /= 2 else: y += 0.2 caret_row_color = rgb_to_hex(*colorsys.yiq_to_rgb(y, i, q)) all_colors['CARET_ROW_COLOR'] = caret_row_color all_colors['SELECTION_BACKGROUND'] = selection_background all_colors['CONSOLE_BACKGROUND_KEY'] = text.value.background for attr in all_attributes: if attr.scope: settings = find_by_scope(all_settings, attr.scope) if settings: the_scope = settings['scope'] if the_scope: print "converting attribute " + attr.id + " from TextMate scope " + the_scope used_scopes.add(the_scope) attr.value = attr_from_textmate(settings['settings'], attr.value, background) else: print "[!] scope not found: " + attr.scope return all_settings, used_scopes
def pixelsToImage(im, pixels): outimg = Image.new("RGB", im.size) #list element 0, tuple value 0, inner tuple value 0 if type(pixels[0][0][0]) == float: #dealing with YIQ print("yiq") yiq_out = [] for p in pixels: r, g, b = colorsys.yiq_to_rgb(p[0][0], p[0][1], p[0][2]) #rgb comes out of conversion as 0-1 float r, g, b = int(r * 255), int(g * 255), int(b * 255) yiq_out.append((r, g, b)) outimg.putdata(yiq_out) #end for p in pixels: else: #dealing with RGB outimg.putdata([p[0] for p in pixels]) #outimg.show() return outimg
def interpolacion_yiq(ArregloImagen1,ArregloImagen2,ancho,alto,RGBnuevo,RGBnormalizado1,RGBnormalizado2,YIQ_1,YIQ_2,YIQ): for x in range(ancho): for y in range(alto): YIQ_1[x,y,:]=cs.rgb_to_yiq(RGBnormalizado1[x,y,0],RGBnormalizado1[x,y,1],RGBnormalizado1[x,y,2]) YIQ_2[x,y,:]=cs.rgb_to_yiq(RGBnormalizado2[x,y,0],RGBnormalizado2[x,y,1],RGBnormalizado2[x,y,2]) if YIQ_1[x,y,0]+YIQ_2[x,y,0] != 0: YIQ[x,y,0]=(YIQ_1[x,y,0]+YIQ_2[x,y,0])/2 YIQ[x,y,1]=(YIQ_1[x,y,0]*YIQ_1[x,y,1]+YIQ_2[x,y,0]*YIQ_2[x,y,1])/(YIQ_1[x,y,0]+YIQ_2[x,y,0]) YIQ[x,y,2]=(YIQ_1[x,y,0]*YIQ_1[x,y,2]+YIQ_2[x,y,0]*YIQ_2[x,y,2])/(YIQ_1[x,y,0]+YIQ_2[x,y,0]) else: YIQ[x,y,0]=0 YIQ[x,y,1]=0 YIQ[x,y,2]=0 RGBnuevo[x,y]=cs.yiq_to_rgb(YIQ[x,y,0],YIQ[x,y,1],YIQ[x,y,2]) plt.imshow(RGBnuevo) plt.imsave('interpolacion_yiq.jpg',RGBnuevo)
def rgb(self): """Generate an RGB color string for this group.""" # We generate the color in the YIQ space first because the Y component, # corresponding to brightness, is fairly accurate, so we can easily # restrict it to a range that looks decent on a white background, and # then convert to RGB with the standard colorsys package. The IQ # components control hue and have bizarre valid ranges. h = self.hash # 0.3 <= Y <= 0.6 y = 0.3 + ((h & 0xFF) / 0xFF) * 0.4 h >>= 16 i = (((h & 0xFF) - 0x80) / 0x80) * 0.5957 h >>= 16 q = (((h & 0xFF) - 0x80) / 0x80) * 0.5226 r, g, b = colorsys.yiq_to_rgb(y, i, q) r = int(r * 255) g = int(g * 255) b = int(b * 255) return f"rgb({r}, {g}, {b})"
def initcmap(ybits, ibits, qbits, chrompack): if ybits + ibits + qbits > 11: raise 'Sorry, 11 bits max' maxy = pow(2, ybits) maxi = pow(2, ibits) maxq = pow(2, qbits) for i in range(2048, 4096 - 256): mapcolor(i, 0, 255, 0) for y in range(maxy): yv = float(y) / float(maxy - 1) for i in range(maxi): if maxi == 1: iv = 0 else: iv = (float(i) / float(maxi - 1)) - 0.5 for q in range(maxq): if maxq == 1: qv = 0 else: qv = (float(q) / float(maxq - 1)) - 0.5 index = 2048 + y + (i << ybits) + (q << (ybits + ibits)) rv, gv, bv = colorsys.yiq_to_rgb(yv, iv, qv) r, g, b = int(rv * 255.0), int(gv * 255.0), int(bv * 255.0) if index < 4096 - 256: mapcolor(index, r, g, b)
def from_yiq(cls, y, i, q): """Construct a color from components in the YIQ color space. Parameters ---------- y : float Luma. i : float Orange-blue chroma. q : float Purple-green chroma. Returns ------- :class:`compas.colors.Color` See Also -------- https://en.wikipedia.org/wiki/YIQ """ r, g, b = colorsys.yiq_to_rgb(y, i, q) return cls(r, g, b)
# conversion back from YIQ to RGB start_time = time.time() BBB = B_YIQ.copy() # B_prime_Y to B_prime_YIQ for i in xrange(heightB): for j in xrange(widthB): temparray = BBB[i,j] temparray[0] = B_prime_Y[i,j] B_prime_YIQ[i,j] = temparray # B_prime_YIQ to B_prime_RGB for i in xrange(heightB): for j in xrange(widthB): colors = B_prime_YIQ[i,j] RGB = colorsys.yiq_to_rgb(colors[0],colors[1],colors[2]) B_prime_RGB[i,j] = RGB stop_time = time.time() print "conversion to RGB complete" print "Serial: %f" % (stop_time - start_time) borderless = B_prime_RGB[3:heightB-2,3:widthB-2] borderlessoriginal = imageB[3:heightB-2,3:widthB-2] result = plt.imshow(borderless) plt.show() scipy.misc.imsave(B_prime_name,borderless) # scipy.misc.imsave(B_name_1,borderlessoriginal)
def drawMod(self, this, area): darkmulti = (1 - self.darkness / 10) self.uptime += 1 gc = self.brush self.bgcolor = self.mod.style.bg[gtk.STATE_NORMAL] redf = self.bgcolor.red greenf = self.bgcolor.green bluef = self.bgcolor.blue #logger.info(greenf) this = self.mod gc.foreground = this.get_colormap().alloc_color(0x0000, 0x0000, 0x0000) track = self.player.current if self.theme: flatcolor1r, flatcolor1g, flatcolor1b = colorsys.yiq_to_rgb( 0.5, self.ivalue, self.qvalue) flatcolor2r, flatcolor2g, flatcolor2b = colorsys.yiq_to_rgb( 0.5 * darkmulti, self.ivalue, self.qvalue) else: flatcolor1r = flatcolor1g = flatcolor1b = 0.5 flatcolor2r = flatcolor2g = flatcolor2b = 0.5 * darkmulti try: if not self.get_size() == self.modwidth: self.buff = self.genBuff() if (not self.defaultstyle == self.defaultstyle_old or not self.theme == self.theme_old or not self.flat == self.flat_old or not self.color == self.color_old or not self.darkness == self.darkness_old or not self.cursor == self.cursor_old): self.buff = self.genBuff() if (self.haveMod): this.props.window.draw_drawable(gc, self.pixmap, 0, 0, 0, 0, self.modwidth, 24) else: if not self.defaultstyle: for i in range(5): gc.foreground = this.get_colormap().alloc_color( int(flatcolor1r * 0xFFFF * i / 5 + redf * ((5 - float(i)) / 5)), int(flatcolor1g * 0xFFFF * i / 5 + greenf * ((5 - float(i)) / 5)), int(flatcolor1b * 0xFFFF * i / 5 + bluef * ((5 - float(i)) / 5))) this.props.window.draw_rectangle(gc, True, 0, 0 + i, self.modwidth, 24 - i * 2) if self.modTimer and track.is_local(): gc.foreground = this.get_colormap().alloc_color( int(flatcolor2r * 0xFFFF), int(flatcolor2g * 0xFFFF), int(flatcolor2b * 0xFFFF)) this.props.window.draw_rectangle(gc, True, (self.modwidth / 10) * (self.uptime % 10), 5, self.modwidth / 10, 14) if self.defaultstyle: gc.foreground = this.get_colormap().alloc_color( int(flatcolor1r * 0xFFFF), int(flatcolor1g * 0xFFFF), int(flatcolor1b * 0xFFFF)) this.props.window.draw_rectangle(gc, True, 0, 12, self.modwidth, 2) except: for i in range(5): gc.foreground = this.get_colormap().alloc_color( int(0xFFFF * i / 5), 0x0000, 0x0000) this.props.window.draw_rectangle(gc, True, 0, 0 + i, self.modwidth, 24 - i * 2) #if track and track.is_local(): #self.lookformod(track) return False track = self.player.current if not track or not (track.is_local() or \ track.get_tag_raw('__length')): return if self.modTimer: if self.cursor: if not self.haveMod: if not self.defaultstyle: for i in range(5): gc.foreground = this.get_colormap().alloc_color( int(flatcolor2r * 0xFFFF * i / 5 + int(redf * ( (5 - float(i)) / 5))), int(flatcolor2g * 0xFFFF * i / 5 + int(greenf * ( (5 - float(i)) / 5))), int(flatcolor2b * 0xFFFF * i / 5 + int(bluef * ( (5 - float(i)) / 5)))) this.props.window.draw_rectangle( gc, True, 0, 0 + i, int(self.curpos * self.modwidth), 24 - i * 2) else: gc.foreground = this.get_colormap().alloc_color( int(flatcolor2r * 0xFFFF), int(flatcolor2g * 0xFFFF), int(flatcolor2b * 0xFFFF)) this.props.window.draw_rectangle( gc, True, 0, 12, int(self.curpos * self.modwidth), 2) else: this.props.window.draw_drawable(gc, self.pixmap2, 0, 0, 0, 0, int(self.curpos * self.modwidth), 24) else: gc.foreground = self.bgcolor gc.line_width = 2 this.props.window.draw_arc( gc, True, int(self.curpos * self.modwidth) - 15, -5, 30, 30, 60 * 64, 60 * 64) gc.foreground = this.get_colormap().alloc_color(0x0000, 0x0000, 0x0000) this.props.window.draw_line( gc, int(self.curpos * self.modwidth), 10, int(self.curpos * self.modwidth) - 10, -5) this.props.window.draw_line( gc, int(self.curpos * self.modwidth), 10, int(self.curpos * self.modwidth) + 10, -5) length = self.player.current.get_tag_raw('__length') seconds = self.player.get_time() remaining_seconds = length - seconds text = ("%d:%02d / %d:%02d" % (seconds // 60, seconds % 60, remaining_seconds // 60, remaining_seconds % 60)) gc.foreground = this.get_colormap().alloc_color(0x0000, 0x0000, 0x0000) this.pangolayout.set_text(text) this.props.window.draw_layout(gc, int(self.modwidth / 2) - 35, 4, this.pangolayout) this.props.window.draw_layout(gc, int(self.modwidth / 2) - 37, 2, this.pangolayout) this.props.window.draw_layout(gc, int(self.modwidth / 2) - 35, 2, this.pangolayout) this.props.window.draw_layout(gc, int(self.modwidth / 2) - 37, 4, this.pangolayout) gc.foreground = this.get_colormap().alloc_color(0xFFFF, 0xFFFF, 0xFFFF) this.props.window.draw_layout(gc, int(self.modwidth / 2) - 36, 3, this.pangolayout)
def genBuff(self): width = self.get_size() self.modwidth = width darkmulti = (1 - self.darkness / 10) #logger.info(darkmulti) hh = [0.2, 0.4, 0.7, 0.8, 0.9, 1, 1, 0.98, 0.93, 0.85, 0.80, 0.80, 0.80, 0.85, 0.93, 0.98, 1, 1, 0.9, 0.8, 0.7, 0.6, 0.4, 0.2] #hh=[0.5,0.55,0.6,0.65,0.7,1,0.95,0.92,0.88,0.84,0.80,0.80, #0.80,0.84,0.88,0.92,0.95,1,0.7,0.65,0.6,0.55,0.5,0.45] #hh=[0.2,0.4,0.7,0.8,0.9,1,1,1,1,1,1,1,1,1,1,1,1,1,0.9,0.8, # 0.7,0.6,0.4,0.2] self.defaultstyle_old = self.defaultstyle self.theme_old = self.theme self.flat_old = self.flat self.color_old = self.color self.darkness_old = self.darkness self.cursor_old = self.cursor gc = self.brush self.bgcolor = self.mod.style.bg[gtk.STATE_NORMAL] redf = self.bgcolor.red / 255 greenf = self.bgcolor.green / 255 bluef = self.bgcolor.blue / 255 colortheme = gtk.gdk.Color(self.color) c1, self.ivalue, self.qvalue = colorsys.rgb_to_yiq( float(colortheme.red) / 256 / 256, float(colortheme.green) / 256 / 256, float(colortheme.blue) / 256 / 256) gc.foreground = self.bgcolor gc.line_width = 1 self.pixmap = gtk.gdk.Pixmap(self.mod.window, width, 24) self.pixmap2 = gtk.gdk.Pixmap(self.mod.window, width, 24) self.pixmap.draw_rectangle(gc, True, 0, 0, self.modwidth, 24) self.pixmap2.draw_rectangle(gc, True, 0, 0, self.modwidth, 24) if self.flat: if self.theme: flatcolor1r = float(colortheme.red) / 256 / 256 flatcolor1g = float(colortheme.green) / 256 / 256 flatcolor1b = float(colortheme.blue) / 256 / 256 flatcolor2r = darkmulti * float(colortheme.red) / 256 / 256 flatcolor2g = darkmulti * float(colortheme.green) / 256 / 256 flatcolor2b = darkmulti * float(colortheme.blue) / 256 / 256 else: flatcolor1r = flatcolor1g = flatcolor1b = 0.5 flatcolor2r = flatcolor2g = flatcolor2b = 0.5 * darkmulti #render --------------------------------------------------------- for x in range(width): #reading color r = float(ord(self.moodbar[int(x * 1000 / width) * 3])) / 256 g = float(ord(self.moodbar[int(x * 1000 / width) * 3 + 1])) / 256 b = float(ord(self.moodbar[int(x * 1000 / width) * 3 + 2])) / 256 if (self.theme or self.defaultstyle): c1, c2, c3 = colorsys.rgb_to_yiq(r, g, b) if (self.theme): c2 = c2 + self.ivalue if c2 > 1: c2 = 1 if c2 < -1: c2 = -1 c3 = c3 + self.qvalue if c3 > 1: c3 = 1 if c3 < -1: c3 = -1 if self.defaultstyle: r, g, b = colorsys.yiq_to_rgb(0.5, c2, c3) waluelength = int(c1 * 24) else: if self.theme: r, g, b = colorsys.yiq_to_rgb(c1, c2, c3) if not self.defaultstyle: buff = '' for h in range(24): buff = buff + chr(int(r * 255 * hh[h] + redf * ( 1 - hh[h]))) + chr(int(g * 255 * hh[h] + greenf * (1 - hh[h]))) + chr(int( b * 255 * hh[h] + bluef * (1 - hh[h]))) self.pixmap.draw_rgb_image(gc, x, 0, 1, 24, gtk.gdk.RGB_DITHER_NONE, buff, 3) if self.cursor: buff2 = '' for h in range(24 * 3): buff2 = buff2 + chr(int(ord(buff[h]) * (darkmulti + (1 - darkmulti) * (1 - hh[int(h / 3)])))) self.pixmap2.draw_rgb_image(gc, x, 0, 1, 24, gtk.gdk.RGB_DITHER_NONE, buff2, 3) else: if self.flat: gc.foreground = self.mod.get_colormap().alloc_color( int(flatcolor1r * 0xFFFF), int(flatcolor1g * 0xFFFF), int(flatcolor1b * 0xFFFF)) else: gc.foreground = self.mod.get_colormap().alloc_color( int(r * 0xFFFF), int(g * 0xFFFF), int(b * 0xFFFF)) self.pixmap.draw_line(gc, x, 13 - waluelength, x, 12 + waluelength) if self.cursor: if self.flat: gc.foreground = self.mod.get_colormap().alloc_color( int(flatcolor2r * 0xFFFF), int(flatcolor2g * 0xFFFF), int(flatcolor2b * 0xFFFF)) else: r, g, b = colorsys.yiq_to_rgb(0.5 * darkmulti, c2, c3) gc.foreground = self.mod.get_colormap().alloc_color( int(r * 0xFFFF), int(g * 0xFFFF), int(b * 0xFFFF)) self.pixmap2.draw_line(gc, x, 13 - waluelength, x, 12 + waluelength) #if not self.defaultstyle: # self.pixmap2.draw_drawable(gc,self.pixmap, 0, 0, 0, 0, self.modwidth, 24) # gc.foreground = self.mod.get_colormap().alloc_color( # int(0xCCCC*darkmulti), int(0xCCCC*darkmulti), int(0xCCCC*darkmulti)) # gc.function=gtk.gdk.AND # self.pixmap2.draw_rectangle(gc, True, 0, 0, self.modwidth, 24) # gc.function=gtk.gdk.COPY return b
def YIQ(y, i, q, a=1.0): r, g, b = colorsys.yiq_to_rgb(y, i, q) return RGB(r, g, b, a)
def from_yiq(cls, y, i, q): """ Construct a :class:`Color` from three `Y'IQ`_ float values. Y' can be between 0.0 and 1.0, while I and Q can be between -1.0 and 1.0. """ return super(Color, cls).__new__(cls, *colorsys.yiq_to_rgb(y, i, q))
def conv_mono(l, x, y): return colorsys.yiq_to_rgb(l*255, 0, 0)
def conv_grey4(l, x, y): return colorsys.yiq_to_rgb(l*17, 0, 0)
#!/usr/bin/env python import Image, sys, colorsys filename = sys.argv[1] im = Image.open(filename) px = list(im.getdata()) px = map(lambda (r,g,b): (r/255.0, g/255.0, b/255.0), px) px = map(lambda p: colorsys.rgb_to_yiq(*p), px) px = sorted(px) px = map(lambda p: colorsys.yiq_to_rgb(*p), px) px = map(lambda (r,g,b): (int(r*255.0), int(g*255.0), int(b*255.0)), px) im.putdata(px) im.save("new" + filename)
def yiq2rgb(y,i,q): "YIQ: Y [0.0, 255] - I [-127, 128] - Q [-127, 128]" y = y/255.0 i = i/255.0 q = q/255.0 return tuple(int(round(i * 255)) for i in cs.yiq_to_rgb(y,i,q) )
def yiq(self, v): self.spaces = {} self.rgb = colorsys.yiq_to_rgb(*v)
def toRGBA(self, color): r, g, b = colorsys.yiq_to_rgb(color[0], color[1], color[2]) return (r, g, b, 1.0)
def from_yiq(cls, yiq): return cls(*colorsys.yiq_to_rgb(*yiq))
def conv_yiq(y, i, q): return colorsys.yiq_to_rgb(y, (i-0.5)*1.2, q-0.5)
print '%s' % (1+3j) print 1==0j, 0.0==0j, 1.0==0j, 0j==0.0 #colorsys import colorsys print '%.2f' % colorsys.ONE_THIRD print '%.2f' % colorsys.ONE_SIXTH print '%.2f' % colorsys.TWO_THIRD def pr(t): print [('%.2f'%x) for x in t] pr(colorsys.hls_to_rgb(1.0, 0.5, 0.7)) pr(colorsys.rgb_to_hls(1.0, 0.5, 0.7)) pr(colorsys.yiq_to_rgb(1.0, 0.5, 0.7)) pr(colorsys.rgb_to_yiq(1.0, 0.5, 0.7)) pr(colorsys.hsv_to_rgb(1.0, 0.5, 0.7)) pr(colorsys.rgb_to_hsv(1.0, 0.5, 0.7)) #equality t1 = ('rc', (0, 0)) t2 =('rc', (0, 0) ) print t1!=t2 print t1==t2 print {(3,2): 0} == {(3,2): 1} #generator and arg unpacking def genpack((i,j),a,b): yield i yield j
def set_yiq(self, y, i, q): r, g, b = colorsys.yiq_to_rgb(y, i * 0.595, q * 0.522) self.set_rgb(r, g, b)
def yiq2rgb(yiq): y,i,q=yiq r,g,b=colorsys.yiq_to_rgb(y/100.0,i/100.0,q/100.0) return map(lambda x: int(round(x*255.0)),[r,g,b])
def yiq2rgb(x,y,z): r = colorsys.yiq_to_rgb(x,y,z) return (int(r[0]*255), int(r[1]*255), int(r[2]*255))
def YIQToRGB(y, i, q): red, green, blue = colorsys.yiq_to_rgb(y, i, q) return int(red * 0xff), int(green * 0xff), int(blue * 0xff)
def test_haar2d(img): im = Image.open(img) #im.show() arr = np.asarray(im, dtype='float') #plt.imshow(arr, cmap = cm.Greys_r) #plt.show() arr = arr/255 #arr = arr[0:5,0:5] arr2 = arr.copy() row, col = arr.shape[0], arr.shape[1] assert (arr - arr2 < 0.0001).all() tranform = np.array([[0.299, 0.587, 0.114], [0.596, -0.275, -0.321], [0.212, -0.523, 0.311]]) #print arr[0,0] #print np.dot(arr[0,0], tranform.T) #print colorsys.rgb_to_yiq(*arr[0,0]) arr = np.dot(arr, tranform.T) arr_r,arr_g,arr_b = (np.zeros([row, col]), np.zeros([row, col]), np.zeros([row, col])) arr3 = arr.copy() for i in range(row): for j in range(col): r,g,b = colorsys.rgb_to_yiq(*arr2[i,j]) arr_r[i,j] = r arr_g[i,j] = g arr_b[i,j] = b arr3[i,j] = [r,g,b] assert (arr - arr3 < 0.01).all() images = np.array([arr[:,:,:1].reshape(row, col), arr[:,:,1:2].reshape(row, col), arr[:,:,2:].reshape(row, col)]) assert (images[0] - arr_r < 0.01).all() colors = images.shape[0] haars = [haar2d(images[i]) for i in range(colors)] #print haars[0].shape #print row, col #print haars[0] - images[0] assert not (images[0] - haars[0] < 0.1).all() haars = [haars[i].reshape(row*col) for i in range(colors)] lefts = 41 inds = [np.argpartition(np.absolute(haars[i]), 0-lefts)[:((row**2)-lefts)] for i in range(colors)] print inds[0].shape #reversed_inds = [list(set(range(row**2)) - set(inds[i])) for i in range(colors)] for i in range(colors): haars[i][inds[i]] = np.zeros(inds[i].shape[0]) haars = [haars[i].reshape([row, col]) for i in range(colors)] ihaars = [ihaar2d(haars[i]) for i in range(colors)] #assert (images[0] - ihaars[0] < 0.1).all() for i in range(row): for j in range(col): r,g,b = colorsys.yiq_to_rgb(ihaars[0][i,j], ihaars[1][i,j], ihaars[2][i,j]) arr3[i,j] = [r,g,b] arr3 = arr3*255 #arr3 = arr3.astype(numpy.int32, copy=False) #plt.imshow(arr3, cmap = cm.Greys_r) #plt.show() img = Image.new('RGB', [row,col]) pixels = img.load() for i in range(row): for j in range(col): pixels[j,i] = (int(arr3[i,j][0]), int(arr3[i,j][1]), int(arr3[i,j][2])) img.show()