def main(): config = configparser.ConfigParser() # Don't mix it up with settings config.read(str( settings['config_file'])) # Config file stores confidential data data_obj = get_images(config=config) objsplit = merge_pictures.items_split(items_list=data_obj, number=settings['images_in_row']) rowimgs = merge_pictures.imgs_to_rows(img_list=objsplit, settings=settings) final_image = merge_pictures.rows_to_final(settings=settings, rows=rowimgs) now_names = [str(x.name) for x in data_obj] stored_names = image.get_stored_backup(settings=settings) image_updated = image.image_changed(now_data=now_names, stored_data=stored_names) if image_updated: print("Shop image updated.") image.save_image(settings=settings, image=final_image, names=now_names) # Save final image to backups telegram.send_image(config=config, image=final_image) # Send final image via Telegram elif not image_updated: print("Same image.") for shopobj in data_obj: if shopobj.video: print(f"A video for \"{shopobj.name}\" was found.") telegram.send_video(config=config, vid_path=shopobj.video)
def save_mask(mask): """Save a masking image. Parameters ---------- mask : numpy.ndarray The mask to save. See Also -------- image.save_image : Save an image. """ img = AllSkyImage("Mask.png", None, None, mask * 255) image.save_image(img, "Images/")
def save_medians(medians, date, color=False): """Save a dict of medians produced by median_all_date. Parameters ---------- medians: dict Dictionary mapping exposure times to their median images. date : str The date of the median images. color : bool, optional If True, saves the median images in color, otherwise works in grayscale. Defaults to False. See Also -------- image.save_image : Save an image. median_all_date : Generate median images for a given date. Notes ----- Saves median images to Images/median/`date`/ if the medians are grayscale, and Images/median-color/`date`/ if the medians are in color. """ if not color: loc = os.path.join(os.path.dirname(__file__), *["Images", "median", date]) cmap = "gray" else: loc = os.path.join(os.path.dirname(__file__), *["Images", "median-color", date]) cmap = None for key, median in medians.items(): name = str(key).replace(".", "") # If blocks to only save the ones with actual data if not color and not np.array_equal(median, np.zeros((1, 1))): img = AllSkyImage(name, None, None, median) image.save_image(img, loc, cmap) elif color and not np.array_equal(median, np.zeros((512, 512, 3))): img = AllSkyImage(name, None, None, np.uint8(median)) image.save_image(img, loc, cmap)
def paralel_augment(image_proto, in_path, out_path): """ Augment data method called in parallel by multiple threads :param image: rois metadata :param in_path: input images folder :param out_path: out images folder :return: generated metadata """ output_metadata = [] image_path = in_path + "/" + image_proto.metadata.image_path image_data = image_operations.load_image(image_path) image_size = image_data.shape shutil.copy(image_path, out_path + "/") crop_file = crop(image_proto, output_metadata) shutil.copy(image_path, out_path + "/" + crop_file) slide_file = slide_window(image_proto, image_size, output_metadata) shutil.copy(image_path, out_path + "/" + slide_file) ccw_rotated_image, ccw_rotation_matrix = image_operations.rotate_image( image_data, 5) ccw_rotated_file = rotate_ccw( image_proto, image_size, ccw_rotation_matrix, output_metadata) image_operations.save_image( ccw_rotated_image, out_path + "/" + ccw_rotated_file) cw_rotated_image, cw_rotation_matrix = image_operations.rotate_image( image_data, -5) cw_rotated_file = rotate_cw( image_proto, image_size, cw_rotation_matrix, output_metadata) image_operations.save_image(cw_rotated_image, out_path + "/" + cw_rotated_file) darken_image_data = image_operations.adjust_gamma(image_data, 0.9) darken_image_file = darken_image(image_proto, output_metadata) image_operations.save_image( darken_image_data, out_path + "/" + darken_image_file) brighten_image_data = image_operations.adjust_gamma(image_data, 1.1) brighten_image_file = brighten_image(image_proto, output_metadata) image_operations.save_image( brighten_image_data, out_path + "/" + brighten_image_file) return output_metadata
def main(): # Nombres de los archivos a procesar input_name = 'shingeki.jpeg' output_name = 'shingeki_gray.jpeg' # Carga de la imagen de entrada input_image = load_image(input_name) # Conversion de la imagen de entrada a vector image = np.array( input_image.getdata()).reshape(input_image.size[1], input_image.size[0], 3 ) image_vector = array2vector(image) # Tamano de la imagen original height, width = input_image.size[1], input_image.size[0] # Conversion a escala de grises output_image_array = rgb2gray(image_vector, height, width) # Conversion del array resultante a formato imagen output_image = array2image(output_image_array) # Guardado de la imagen procesada save_image(output_image, output_name)
def upload(): if request.files['image']: # 画像として読み込み img = read_image(request.files['image']) # 変換 img, kanna_value, original_image = pred_kanna(img) # オリジナル画像を保存 save_filename, save_path = save_image(kanna_value, original_image) return render_template('result.html', filename=save_filename, kanna_value=kanna_value)
def save(self): # When the plot is closed we save the newly created label mask. save_im = image.AllSkyImage(self.name, None, None, self.mask) if self.camera.lower() == "kpno": # Gets the exposure for the saving location. exp_im = image.AllSkyImage(self.name, None, None, self.img) exp = image.get_exposure(exp_im) loc = os.path.join(os.path.dirname(__file__), *["Images", "data", "labels", str(exp)]) # Maks the antenna m = mask.generate_mask() save_im = mask.apply_mask(m, save_im) else: loc = os.path.join(os.path.dirname(__file__), *["Images", "data", "labels-sw"]) # Saves the image. image.save_image(save_im, loc) if not self.update: # Moves the downloaded image into the training folder. loc = os.path.join(os.path.dirname(__file__), *["Images", "data", "to_label", self.name]) if self.camera.lower() == "kpno": dest = os.path.join( os.path.dirname(__file__), *["Images", "data", "train", str(exp), self.name]) else: dest = os.path.join( os.path.dirname(__file__), *["Images", "data", "train", "sw", self.name]) os.rename(loc, dest) print("Moved: " + loc)
def main(): search_input = input(search_string) engine_params = {"q": search_input} save_image(bing, engine_params, search_input)
session = tf.Session(config=config) K.set_session(session) if args.display: pylab.ion() if args.output_image: print('The final result will be saved as {}'.format(args.output_image)) if not args.display and not args.output_image: print('WARNING: You have not turned on display or provided an output image path, so you will NOT see the styled results.') content_image = load_image(args.content_image, max_size=args.size) style_image = load_image(args.style_image, max_size=args.size) style_net = StyleNet() styled_image = style_net.apply_style(content_image, style_image, display=args.display, iterations=args.iterations, content_weight=args.content_weight, style_weight=args.style_weight, variation_weight=args.variation_weight) if args.output_image: save_image(styled_image, args.output_image) if args.display: display_image(styled_image) pylab.ioff() pylab.show()
__author__ = 'anton' import image import encoder import decoder import encoder_gpu if __name__ == '__main__': img = image.load_image('nature.bmp') print img.width, img.height transformations = encoder_gpu.encode(img) print len(transformations), len(transformations[0]) img_data = decoder.decode(10, img.width, img.height, transformations) print len(transformations) img = image.ImageData(img.width, img.height, img_data, img.mode) image.save_image('anture_test.bmp', img)
def main(image_file, model_file, layer_name, label, method_name, output_path, guided, no_plot): print(image_file, model_file, layer_name, label) # 1. Load model model = load_model(model_file) # 1.1 Save model summary into file model_summary_file = model_file + '_summary.txt' save_model_summary(model, model_summary_file) # 2. Load image image = load_image(image_file) height, width, _ = image.shape # Get model's input shape _, input_width, input_height, _ = model.layers[0].input_shape # 2.1 Preprocess Image preprocessed_image = preprocess_image(image, (input_width, input_height)) # 3. Layers to visualize all_layers = get_model_viewable_layers(model) if layer_name == 'all': layers = all_layers elif layer_name in all_layers: layers = [layer_name] else: print('Error: Invalid layer name') return # 4. Image prediction probabilities and predicted_class predictions = model.predict(preprocessed_image) predicted_class = np.argmax(predictions) # 5 Label to visualize nb_classes = get_model_nb_classes(model) # 5.1 Model's number of classes if label == -1: class_to_visualize = predicted_class elif label < nb_classes and label > -1: class_to_visualize = label else: print('Error: Invalid label value') return # 6. Choose Visualization method all_methods = [ 'CAM_IMAGE_JET', 'CAM_IMAGE_BONE', 'CAM_AS_WEIGHTS', 'JUST_CAM_JET', 'JUST_CAM_BONE' ] if method_name in all_methods: method = Method[method_name] elif guided: method_name = 'GUIDED' else: print('Error: Invalid visualization method') return # 7. Create output folder create_folder_if_not_exists(output_path) # TODO: Handler with dataset folder cams = [] # 8. Iterate over layers to visualize for layer_to_visualize in layers: # 8.1 Get cam cam = grad_cam(model, preprocessed_image, class_to_visualize, layer_to_visualize, nb_classes) # 8.2 Generate visualization if guided: cam = guided_grad_cam(model, cam, layer_to_visualize, preprocessed_image) cam_heatmap = create_guided_cam_image(cam, image, cam_rate=1) else: cam_heatmap = create_cam_image(cam, image, method) cams.append( Cam(image=cam_heatmap, target=class_to_visualize, layer=layer_to_visualize, method=method_name, file_name=image_file)) cams.insert( 0, Cam(image=convert_to_bgr(image), target=class_to_visualize, layer='Original', method=method_name, file_name=image_file)) if no_plot: file_name = extract_file_name(image_file) create_folder_if_not_exists(os.path.join(output_path, file_name)) for _cam in cams: save_image( _cam.image, os.path.join(output_path, file_name) + '/' + _cam.layer + '.png') else: plot(cams, image_file) plt.savefig(output_path + '/' + extract_file_name(image_file) + '.png') plt.clf()
] process = 1 if process == 0: # Visualize specific layer with specific visualization method # Select Layer to visualize # layer_to_visualize = 'conv2d_41' | 'max_pooling2d_33' layer_to_visualize = 'max_pooling2d_33' # Get cam cam = grad_cam(model, preprocessed_image, class_to_visualize, layer_to_visualize, nb_classes) # Apply visualization method method = Method.CAM_IMAGE_JET cam_heatmap = create_cam_image(cam, image, method) save_image(cam_heatmap, './experiments/' + image_name) elif process == 1: # Merge change target experiment #cams = [] for layer_to_visualize in layers: # Get cam cam = grad_cam(model, preprocessed_image, class_to_visualize, layer_to_visualize, nb_classes) # Apply visualization method method = Method.CAM_IMAGE_JET cam_heatmap = create_cam_image(cam, image, method) #cams.append(Cam(cam_heatmap, class_name[class_to_visualize], layer_to_visualize, method_name[method], image_name)) save_image(cam_heatmap, './output/' + layer_to_visualize + '.png')
def main(infile, outfile, width, height): stocks = stock_info_from(infile) im = image.create_image(width, height) draw(stocks, im) image.save_image(im, outfile)