Ejemplo n.º 1
0
 def label_patches(self, patches, max_patches=None):
     if max_patches is not None:
         patches = itertools.islice(patches, max_patches)
     for patch in patches:
         assert isinstance(patch, Patch)
         os.makedirs(root_dir(FOLDER_TEMP_DATA), exist_ok=True)
         path_patch = root_dir(FOLDER_TEMP_DATA, 'patch.png')
         path_outln = root_dir(FOLDER_TEMP_DATA, 'outln.png')
         images = {
             path_patch: patch.cropped_image(),
             path_outln: outline_regions(image=patch.cropped_image(),
                                         region_labels=patch.cropped_mask())
         }
         [imsave(fname=rel_path, arr=resize(img, output_shape=(600, 600))) for rel_path, img in images.items()]
         labels = LABELS_Ki67 + ['Not well defined']
         while patch.expert_label not in labels:
             # noinspection PyTypeChecker
             gui = buttonbox("Ki67 - Manual labelling", choices=labels,
                             images=list(images.keys()), run=False)
             gui.ui.set_pos("+0+0")
             patch.expert_label = gui.run()
         print(patch.expert_label)
         self.labelled_patches.append(patch)
Ejemplo n.º 2
0
from src.data_loader import sample_names, images, root_dir, FOLDER_EXPERIMENTS, get_expert_Ki67

MAX_PATIENTS = 1000
MAX_IMAGES_PER_PATIENT = 5
MAX_PATCHES_PER_IMAGE = 2

SCALE = None  # None to deactivate
GAUSSIAN_FILTER_SD = 2
CLUSTERING_NUM_CENTROIDS = 4
RADIUS_FILL_HOLES = 5
WIDTH_REMOVE_THIN_STRUCTURES = 12

if __name__ == "__main__":
    execution_id = datetime.datetime.now().strftime('%Y-%m-%d-%H-%M-%S')
    results_dir = root_dir(FOLDER_EXPERIMENTS(version=6), execution_id)
    os.makedirs(results_dir, exist_ok=True)
    logging.basicConfig(level=logging.INFO,
                        handlers=[
                            logging.FileHandler(
                                os.path.join(results_dir, 'log.txt')),
                            logging.StreamHandler()
                        ])

    p_names = sample_names()
    for idx_p, p_name in enumerate(p_names[0:MAX_PATIENTS]):

        for idx_img, (path_image, original_image) in enumerate(
                images(patient_name=p_name,
                       max_images=MAX_IMAGES_PER_PATIENT)):
Ejemplo n.º 3
0
 def load_labelled_patches(self, training_label):
     data_dir = root_dir(FOLDER_LABELLED_DATA, training_label)
     self.labelled_patches = Patch.load_all(folder=data_dir)
Ejemplo n.º 4
0
 def save_labelled_patches(self, training_label):
     data_dir = root_dir(FOLDER_LABELLED_DATA, training_label)
     os.makedirs(data_dir, exist_ok=False)
     for patch in self.labelled_patches:
         patch.save(folder=data_dir)