![]() reshape (( width * height, 3 )) palette = set (( tuple ( t ) for t in rarr )) palette_arr = np. uint8, size = 3 ) def crazy_img ( rimg, j ): arr = np. keys ()): palette_dict = new_palette def random_mess_with_palette_dict ( palette_dict ): n = len ( new_palette ) for i, k in enumerate ( palette_dict. ANTIALIAS ) return img colours = colours = def hex_to_tuple ( s ): return int ( s, 16 ), int ( s, 16 ), int ( s, 16 ) new_palette = def mess_with_palette_dict ( palette_dict ): n = len ( new_palette ) for i, k in enumerate ( palette_dict. resize (( new_width, new_height ), Image. size new_height = int ( height * new_width / width ) img = img. open ( img_name ) if GREYSCALE : img = img. fromarray ( carr ) def get_image ( img_name, new_width = 400, GREYSCALE = False ): # Read in the image, convert to greyscale. array ( img, dtype = float ) / 255 arr = get_new_val ( arr, nc ) carr = np. fromarray ( carr ) def palette_reduce ( img, nc ): """Simple palette reduction without dithering.""" arr = np. if ic 0 : arr += err * 3 / 16 arr += err * 5 / 16 if ic < width - 1 : arr += err / 16 carr = np. copy () new_val = get_new_val ( old_val, nc ) arr = new_val err = old_val - new_val # In this simple example, we will just ignore the border pixels. shape for ir in range ( height ): for ic in range ( width ): # NB need to copy here for RGB arrays otherwise err will be (0,0,0)! old_val = arr. array ( img, dtype = float ) / 255 height, width = arr. #p = np.linspace(0, 1, nc) #p = np.array(list(product(p,p,p))) #def get_new_val(old_val): # idx = np.argmin(np.sum((old_val - p)**2, axis=1)) # return p def fs_dither ( img, nc ): """ Floyd-Steinberg dither the image img into a palette with nc colours per channel. round ( old_val * ( nc - 1 )) / ( nc - 1 ) # For RGB images, the following might give better colour-matching. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |