def predict_add(img_path): height, width, channels = 36, 60, 4 sum = 0 img_processed = preprocess_img(img_path) if not img_processed: return None for i, img_array in enumerate(img_processed): print(img_array.shape) img_array = img_array.reshape(1, img_array.shape[0], width, channels) value = predict_img(img_array, model=mode[i], mapp=cls_map[i]) sum += value return sum
def save_img(): file = request.files['image'] file.save(os.path.join(app.config['UPLOAD_FOLDER'], file.filename)) result = predict_img(file.filename) print(result) return result
in_file = args.test + file_name + "/images/" + file_name + ".png" out_file = args.save + file_name + ".png" print("\nPredicting image {} ...".format(in_file)) original_img = Image.open(in_file) # 元画像の大きさを保存しておく original_width = original_img.size[0] original_height = original_img.size[1] original_img = np.asarray(original_img) # 所定の大きさにresize resized_img = to_square(original_img, args.size) # U-Netを用いてsegentation(確率値を出力) probs = predict_img(net, resized_img, args.gpu) # もとの大きさに戻す probs_resized = from_square(probs, (original_height, original_width)) # ノイズ除去 & 二値化 dst_img = remove_noise(probs_resized, (original_height, original_width), original_img) dst_img = (dst_img * 255).astype(np.uint8) # 真ん中を穴埋め if "b83d1d77935b6cfd44105b54600ffc4b6bd82de57dec65571bcb117fa8398ba3" in in_file: print("zzzzzzzzzzzzzzzzzz") else: dst_img = fill(dst_img)
out_file = args.save + file_name + ".png" print("\nPredicting image {} ...".format(in_file)) original_img = Image.open(in_file) original_width = original_img.size[0] original_height = original_img.size[1] original_img_array = np.asarray(original_img) # 染色方法を識別 image_type = imagetype_classification(in_file) resized_img = original_img.resize(SIZE) #resized_img = original_img resized_img_array = np.array(resized_img) print(image_type, "\n") dst_img_array = predict_img(net, resized_img_array, args.gpu) dst_img_array = morphology(dst_img_array, iterations=1) dst_img = Image.fromarray(dst_img_array * 255) dst_img_resized = dst_img.resize((original_width, original_height)) print(original_width, original_height) #dst_img_resized_array = np.asarray(dst_img_resized) #devide = Devide(original_img_array, dst_img_resized_array) #out = devide.make_mask() #result = Image.fromarray((out).astype(numpy.uint8)) result = dst_img_resized result.save(out_file)
for file_name in os.listdir(args.test): in_file = args.test + file_name + "/images/" + file_name + ".png" out_file = args.save + file_name + ".png" print("\nPredicting image {} ...".format(in_file)) img = Image.open(in_file) original_width = img.size[0] original_height = img.size[1] img_array = np.asarray(img) # 染色方法ごとに処理を分ける image_type = imagetype_classification(in_file) print(image_type, "\n") if image_type == 1: out = predict_img(net, img, in_file, args.gpu, SIZE) out = morphology(out, iterations=0) result = Image.fromarray((out * 255).astype(numpy.uint8)) result = result.resize((original_width, original_height)) elif image_type == 2: out = predict_img(net, img, in_file, args.gpu, SIZE) out = morphology(out, iterations=0) result = Image.fromarray((out * 255).astype(numpy.uint8)) result = result.resize((original_width, original_height)) else: out = predict_img(net, img, in_file, args.gpu, SIZE) out = morphology(out, iterations=0) result = Image.fromarray((out * 255).astype(numpy.uint8)) result = result.resize((original_width, original_height)) result.save(out_file)