def default_loader(path): from torchvision import get_image_backend if get_image_backend() == 'PIL': return pil_loader(path) else: logging.info("Something went wrong with the default_loader in image_folder_segmentation.py") sys.exit(-1)
def convert_gt(img_path): img = np.array(pil_loader(img_path)) out_img = np.zeros(img.shape, dtype=np.uint8) out_img[:, :, 2] = 1 # set everything to background in blue channel out_img[:, :, 2][img[:, :, 2] != 0] = 2 # set glands to 2 in blue channel out = Image.fromarray(out_img) out.save(img_path)
def _load_test_images_and_vars(self): """ Inits the variables responsible of tracking which crop should be taken next, the current images and the like. This should be run every time a new page gets loaded for the test-set """ # Load image self.current_data_img = pil_loader(self.img_paths[self.next_image_index][0]) self.current_gt_img = pil_loader(self.img_paths[self.next_image_index][1]) # Initialize the sliding window indices self.total_num_horiz_crops = self.num_horiz_crops[self.next_image_index] self.current_horiz_crop = 0 self.total_num_vert_crops = self.num_vert_crops[self.next_image_index] self.current_vert_crop = 0 self.total_crops_current_img = self.total_num_vert_crops * self.total_num_horiz_crops # Update pointer to next image self.next_image_index += 1
def layout_analysis_output(args): ground_truth_folder = args.ground_truth_folder network_output_folder = args.network_output_folder output_folder = os.path.join(args.output_folder, 'layout_analysis_evaluation') gt_img_paths = get_img_paths(ground_truth_folder) segm_img_paths = get_img_paths(network_output_folder) if not output_folder: output_folder = os.path.join(os.path.dirname(segm_img_paths), 'layout_analysis_evaluation') for gt, segm in zip(gt_img_paths, segm_img_paths): gt_image = np.array(pil_loader(gt)) segm_image = np.array(pil_loader(segm)) generate_layout_analysis_output(output_folder, gt_image, segm_image, os.path.basename(gt)) # create a legend and save it make_colour_legend_image( os.path.join(output_folder, "layout_analysis_eval_legend"), CLASS_COLOUR_ENCODINGS)
def _load_image(self, input_folder): """Load the image from the file system""" if not os.path.exists(input_folder): raise FileNotFoundError(f"Could not find file {input_folder}") img = pil_loader(input_folder) return img