def server_seg_blood_vessel(image1, preprocess=True): from LIBS.ImgPreprocess.my_patches_based_seg import seg_blood_vessel img_result = seg_blood_vessel( image1, dicts_models, PATCH_H, PATCH_W, rop_resized=preprocess, threshold=127, min_size=10, tmp_dir='/tmp', test_time_image_aug=my_config.blood_vessel_seg_test_time_image_aug) str_uuid = str(uuid.uuid1()) save_filename = os.path.join(dir_tmp, str_uuid + '.jpg') os.makedirs(os.path.dirname(save_filename), exist_ok=True) cv2.imwrite(save_filename, img_result) return save_filename
os.environ["CUDA_VISIBLE_DEVICES"] = "2" import cv2 img_file = '/tmp4/img1.png' img_file = 'rop1.jpg' img_file = '/media/ubuntu/data2/BloodVesselsSegment_2019_10_22/original/DRIVE/training/images/24_training.tif' PATCH_H = 64 PATCH_W = 64 import keras model_file = '/home/ubuntu/dlp/deploy_models/vessel_segmentation/transfer_vessel_seg_patch-012-0.968_0.68_0.81.hdf5' model1 = keras.models.load_model(model_file, compile=False) image1 = cv2.imread(img_file) from LIBS.ImgPreprocess.my_patches_based_seg import seg_blood_vessel img_result = seg_blood_vessel(image1, model1, PATCH_H, PATCH_W, threshold=127, min_size=10, tmp_dir='/tmp', test_time_image_aug=True) cv2.imwrite('a2.png', img_result) pass
continue if not extension.upper() in [ '.BMP', '.PNG', '.JPEG', '.JPG', '.TIFF', '.TIF' ]: continue if IMAGE_TO_SQUARE: img_input = image_to_square(image_file) else: img_input = image_file from LIBS.ImgPreprocess.my_patches_based_seg import seg_blood_vessel img_result = seg_blood_vessel(img_input, dicts_models, PATCH_H, PATCH_W, rop_resized=True, threshold=127, min_size=10, tmp_dir='/tmp', test_time_image_aug=True) image_file_dest = image_file.replace(dir_preprocess, dir_dest) if not os.path.exists(os.path.dirname(image_file_dest)): os.makedirs(os.path.dirname(image_file_dest)) print(image_file_dest) cv2.imwrite(image_file_dest, img_result) print('ok')
# dir_dest = '/media/ubuntu/data2/STAGE/vessel_seg/' dir_source = '/media/ubuntu/data2/ROP_vessel_seg/PLUS血管自动分割_20191014/' dir_dest = '/media/ubuntu/data2/ROP_vessel_seg/PLUS血管自动分割_20191014_my_results/' for dir_path, subpaths, files in os.walk(dir_source, False): for f in files: image_file = os.path.join(dir_path, f) (filepath, tempfilename) = os.path.split(image_file) (filename, extension) = os.path.splitext(tempfilename) if not extension.upper() in [ '.BMP', '.PNG', '.JPEG', '.JPG', '.TIFF', '.TIF' ]: continue from LIBS.ImgPreprocess.my_patches_based_seg import seg_blood_vessel img_result = seg_blood_vessel(image_file, model1, PATCH_H, PATCH_W, rop_resized=False, test_time_image_aug=True) image_file_dest = image_file.replace(dir_source, dir_dest) os.makedirs(os.path.dirname(image_file_dest), exist_ok=True) print(image_file_dest) cv2.imwrite(image_file_dest, img_result) print('ok')