def area_crop(img_path, mask_path, ori_name, x_lt, y_lt, x_br, y_br): mask_file = "_".join([ori_name, "label.tif"]) mask_tiff_obj = TIFF.open(os.path.join(mask_path, mask_file)) mask = TIFF.read_image(area_tiff_obj) ori_file = ".".join([ori_name, "tif"]) ori_tiff_obj = TIFF.open(os.path.join(img_path, ori_file)) ori = TIFF.read_image(ori_tiff_obj) area_mask = mask[x_lt:x_br, y_lt:y_br] area = ori[x_lt:x_br, y_lt:y_br] return area, area_mask
def crop_main(img_path, crop_size, stride, img_save_path): img_names = load_id(img_path) for img_name in tqdm(img_names): tif_obj = TIFF.open(os.path.join(img_path, ".".join([img_name, "tif"]))) img = TIFF.read_image(tif_obj) sliding_window_crop(img, img_name, crop_size, stride, img_save_path)
def crop_main(img_path, label_path, img_save_path, label_save_path): img_names = load_id(img_path) label_names = load_id(label_path) # output_path = "/home/arron/Documents/grey/test/" for img_name in tqdm(img_names): tif_obj = TIFF.open(os.path.join(img_path, ".".join([img_name, "tif"]))) img = TIFF.read_image(tif_obj) sliding_window_crop(img, img_name, img_save_path, "img") for label_name in tqdm(label_names): tif_obj = TIFF.open( os.path.join(label_path, ".".join([label_name, "tif"]))) label = TIFF.read_image(tif_obj) label_list_name = label_name.strip().split("_")[:-1] label_id = "_".join(label_list_name) sliding_window_crop(label, label_id, label_save_path, "label")