Beispiel #1
0
 def show_thumb_when_selected(self, event):
     idx = self.selected_files.curselection()[0]
     filepath = self.selected_files_list[idx]
     slide = wp.slide(filepath)
     slide.export_thumbnail(save_to=".", size=256)
     self.thumb = ImageTk.PhotoImage(file="thumb.png")
     x = (256 - self.thumb.width()) / 2
     y = (256 - self.thumb.height()) / 2
     self.thumb_canvas.create_image(x, y, image=self.thumb, anchor=tk.NW)
Beispiel #2
0
def main(command=None):
    args = Args(command)
    slide = wp.slide(args.wsi)
    rule = wp.rule(args.rule) if hasattr(args, "rule") and args.rule else False
    annotation = process_annotation(args, slide, rule)

    if hasattr(args, "export_thumbs") and args.export_thumbs:
        thumbs_dir = args.save_to/slide.filestem/"thumbs"
        if not thumbs_dir.exists():
            thumbs_dir.mkdir(parents=True)
        annotation.export_thumb_masks(thumbs_dir)

    if args.method == "evaluation":
        on_annotation = False
    else:
        on_annotation = args.on_annotation
    crop_bbox = args.crop_bbox if hasattr(args, "crop_bbox") else False

    patcher = wp.patcher(
        slide, args.method,
        annotation=annotation,
        save_to=args.save_to,
        patch_width=args.patch_width,
        patch_height=args.patch_height,
        overlap_width=args.overlap_width,
        overlap_height=args.overlap_height,
        on_foreground=args.on_foreground,
        on_annotation=on_annotation,
        offset_x=args.offset_x,
        offset_y=args.offset_y,
        start_sample=args.start_sample,
        finished_sample=args.finished_sample,
        no_patches=args.no_patches,
        crop_bbox=crop_bbox,
        verbose=args.verbose)
    patcher.get_patch_parallel(annotation.classes)

    if args.method == "detection":
        converter = wp.converter(
            args.save_to/slide.filestem,
            args.save_to/slide.filestem,
            args.ratio)
        if args.voc_style:
            converter.to_voc()
        if args.coco_style:
            converter.to_coco()
        if args.yolo_style:
            converter.to_yolo()

        if args.crop_bbox:
            patcher.get_mini_patch_parallel(annotation.classes)
Beispiel #3
0
 def run_process(self):
     wsiidx = self.selected_files.curselection()[0]
     self.params["wsi"] = self.selected_files_list[wsiidx]
     slide = wp.slide(self.params["wsi"])
     if self.params["rule file"].get():
         rule = wp.rule(self.params["rule file"].get())
     else:
         rule = False
     if self.params["annotation file"].get():
         annotation = wp.annotation(self.params["annotation file"].get())
         annotation.make_masks(slide, rule, foreground=True)
         annotation.classes.remove("foreground")
         classes = annotation.classes
     else:
         annotation = wp.annotation("")
         annotation.make_masks(slide, foreground=True)
         classes = annotation.classes
     patcher = wp.patcher(
         slide,
         self.params["method"].get(),
         annotation=annotation,
         save_to=self.params["where to save"].get(),
         patch_width=self.params["patch width"].get(),
         patch_height=self.params["patch height"].get(),
         overlap_width=self.params["overlap width"].get(),
         overlap_height=self.params["overlap height"].get(),
         on_foreground=self.params["ratio of foreground"].get(),
         on_annotation=self.params["ratio of annotation"].get(),
         start_sample=False,
         finished_sample=False,
         extract_patches=True)
     patcher.get_patch_parallel(classes)
     if self.params["convert to voc"].get(
     ) or self.params["convert to coco"].get():
         converter = wp.converter(
             self.params["where to save"].get() + "/" + slide.filestem,
             self.params["where to save"].get(), "8:1:1")
         if self.params["convert to voc"].get():
             converter.to_voc()
         if self.params["convert to coco"].get():
             converter.to_coco()
Beispiel #4
0
def cli(params):
    slide = wp.slide(params.wsi)
    if params.rule:
        rule = wp.rule(params.rule)
    else:
        rule = False
    if params.annotation:
        annotation = wp.annotation(params.annotation)
        annotation.make_masks(slide, rule, foreground=True)
        annotation.classes.remove("foreground")
    else:
        annotation = wp.annotation("")
        if params.on_annotation:
            annotation.make_masks(slide, foreground=True)
    patcher = wp.patcher(slide,
                         params.method,
                         annotation=annotation,
                         save_to=params.save_to,
                         patch_width=params.patch_width,
                         patch_height=params.patch_height,
                         overlap_width=params.overlap_width,
                         overlap_height=params.overlap_height,
                         offset_x=params.offset_x,
                         offset_y=params.offset_y,
                         on_foreground=params.on_foreground,
                         on_annotation=params.on_annotation,
                         no_patches=params.no_patches)
    patcher.get_patch_parallel(annotation.classes)
    if params.voc_style or params.coco_style or params.yolo_style:
        converter = wp.converter(params.save_to / slide.filestem,
                                 params.save_to, params.ratio)
        if params.voc_style:
            converter.to_voc()
        if params.coco_style:
            converter.to_coco()
        if params.yolo_style:
            converter.to_yolo()
Beispiel #5
0
import wsiprocess as wp
import cv2

slide = wp.slide("CMU-1.ndpi")
annotation = wp.annotation("", is_image=True)
target_classes = ["benign", "malignant"]
annotation.add_class(target_classes)

benign_mask = cv2.imread("benign_mask.png", 0) * 255
malignant_mask = cv2.imread("malignant_mask.png", 0) * 255

# Make sure your mask data includes only 0 as background or 255 as foreground
annotation.from_image(benign_mask, "benign")
annotation.from_image(malignant_mask, "malignant")

patcher = wp.patcher(slide, "classification", annotation=annotation)
patcher.get_patch_parallel(target_classes)