def main(image_source, image_dir, output_name, tile_height, num_candidates): """this function receive the image file, the folder for the image, name for the photomasaic, the tile height and the number candidates.""" tiles = mosaic.build_tile_base(image_dir, tile_height) original_image = mosaic.load_image(image_source) mosaic_image = make_mosaic(original_image, tiles, num_candidates) mosaic.save(mosaic_image, output_name)
def main(): """ main function that will load the image, the tiles and use make mosaic to create a mosaic image from out source image. at the end this function will show the mosaic image and save it. """ # loading the image named image name image = mosaic.load_image(image_name) # loading tiles in the image destination folder with the given height tiles = mosaic.build_tile_base(image_src, tile_height) # creating a mosaic_image using make_mosaic function on image and tiles mosaic_image = make_mosaic(image, tiles, num_candidates) # showing the new mosaic image and saving it with the given output_name mosaic.show(mosaic_image) mosaic.save(mosaic_image, output_name)
def main(): ''' Main function ''' if len(sys.argv) == NUM_ARGUMENTS: # Gets the values image_source = sys.argv[ONE] images_dir = sys.argv[TWO] output_name = sys.argv[THREE] tile_height = int(sys.argv[FOUR]) num_candidates = int(sys.argv[FIVE]) image = mosaic.load_image(image_source) tiles = mosaic.build_tile_base(images_dir, tile_height) photosomaic = make_mosaic(image, tiles, num_candidates) mosaic.save(photosomaic, output_name) else: sys.stdout.write(ERROR_MSG)
def main(): """ This function make the program run """ tiles_dir = sys.argv[2] tile_height = int(sys.argv[4]) tiles = mosaic.build_tile_base(tiles_dir, tile_height) image_filename = sys.argv[1] image = mosaic.load_image(image_filename) num_candidates = sys.argv[5] objective = make_mosaic(image, tiles, num_candidates) filename = sys.argv[3] mosaic.save(objective, filename)
def main(): # initializing variables image_name = sys.argv[1] tiles_directory = sys.argv[2] tile_height = int(sys.argv[4]) image = list() tiles = list() mosaic_image = list() num_of_candidates = int(sys.argv[5]) # Make the list of list image image = mosaic.load_image(image_name) # Make the list tiles that are pure list of list made tiles = mosaic.build_tile_base(tiles_directory, tile_height) # Start the mosaic process! mosaic_image = make_mosaic(image, tiles, num_of_candidates) # The name of the mosaic image mosaic_name = sys.argv[3] # Saving the image mosaic.save(mosaic_image, mosaic_name)
def main(image_source, images_dir, tile_height, num_candidates): image_input = mosaic.load_image(image_source) tiles = mosaic.build_tile_base(images_dir, tile_height) image_mosaic = make_mosaic(image_input, tiles, num_candidates) mosaic.save(image_mosaic, output)
"""Receives an image, a list of tiles and a length of a new wanted list, and using previous function, recreates the entire original given image as a mosaic, piece by piece. Once completed, returns said mosaic.""" mosaic_image = copy.deepcopy(image) HEIGHT = len(tiles[0]) WIDTH = len(tiles[0][0]) averages = preprocess_tiles(tiles) for i in range(0,len(image),HEIGHT): for j in range(0,len(image[0]),WIDTH): new_piece = get_piece(mosaic_image,(i,j),(HEIGHT,WIDTH)) best_tiles =get_best_tiles(new_piece,tiles,averages,num_candidates) winner_tile = choose_tile(new_piece,best_tiles) set_piece(mosaic_image,(i,j),winner_tile) return mosaic_image if __name__ == "__main__": #The main calls all the previous functions, using specific arguments, #in order to create the wanted mosaic, so long as the amount and type of #arguments are as needed. if len(sys.argv) != NUMBER_OF_ARGUMENTS+1: print(ERROR_MESSAGE) else: image_source = sys.argv[1] images_dir = sys.argv[2] output_name = sys.argv[3] tile_height = int(sys.argv[4]) num_candidates = int(sys.argv[5]) image = mosaic.load_image(image_source) tiles = mosaic.build_tile_base(images_dir,tile_height) real_mosaic = make_mosaic(image,tiles,num_candidates) mosaic.save(real_mosaic,output_name)
tile_w = len(tiles[0][FRST_ROW]) tiles_across = m.ceil(image_width / tile_w) tiles_down = m.ceil(image_height / tile_h) tile_avg_list = preprocess_tiles(tiles) for row in range(tiles_down): for tile in range(tiles_across): upper_left = (row * tile_h, (tile * tile_w)) piece = get_piece(new_mosaic, upper_left, (tile_h, tile_w)) best_tiles = get_best_tiles(piece, tiles, tile_avg_list, num_candidates) chosen_tile = choose_tile(piece, best_tiles) set_piece(new_mosaic, upper_left, chosen_tile) return new_mosaic if __name__ == '__main__': if len(sys.argv) != COMMAND_LINE_ARGS: # Ensure correct # of args print(USAGE_STRING) sys.exit(2) else: # Parse args image_src, tile_src, out_path, tile_height, num_cand = sys.argv[1:] tile_height = int(tile_height) num_cand = int(num_cand) # Load files, make mosaic, and save. base_image = mosaic.load_image(image_src) tiles_lst = mosaic.build_tile_base(tile_src, tile_height) new_img = make_mosaic(base_image, tiles_lst, num_cand) mosaic.save(new_img, out_path) sys.exit(0)
def main(): image = mosaic.load_image(photo) tiles = mosaic.build_tile_base(lst_of_tiles, tile_height) new_pic = make_mosaic(image, tiles, candidates_number) mosaic.save(new_pic, save_name)