Exemplo n.º 1
0
def process_annotation(args, slide, rule):
    if args.method == "none":
        annotation = wp.annotation("")
        annotation.dot_to_bbox(args.dot_bbox_width, args.dot_bbox_height)
        if args.minmax:
            min_, max_ = map(int, args.minmax.split("-"))
            annotation.make_masks(slide,
                                  foreground="minmax",
                                  min_=min_,
                                  max_=max_)
        else:
            annotation.make_masks(slide, foreground="otsu")

    else:
        annotation = wp.annotation(args.annotation, slidename=slide.filename)
        annotation.dot_to_bbox(args.dot_bbox_width, args.dot_bbox_height)
        if hasattr(args, "minmax") and args.minmax:
            min_, max_ = map(int, args.minmax.split("-"))
            annotation.make_masks(slide,
                                  rule,
                                  foreground="minmax",
                                  min_=min_,
                                  max_=max_)
        else:
            annotation.make_masks(slide, rule, foreground=True)

    if not args.extract_foreground and "foreground" in annotation.classes:
        annotation.classes.remove("foreground")

    return annotation
Exemplo n.º 2
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()
Exemplo n.º 3
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()
Exemplo n.º 4
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)
import wsiprocess as wp
import numpy as np


def example_function(thumb_gray):
    assert len(thumb_gray.shape) == 2
    assert isinstance(thumb_gray, np.ndarray)
    thresh = 100
    thumb_gray[thumb_gray > thresh] = 1
    thumb_gray[thumb_gray <= thresh] = 0
    assert np.sum((thumb_gray == 0) | (thumb_gray == 1)) == len(thumb_gray)
    return thumb_gray


slide = wp.slide("CMU-1.ndpi")
annotation = wp.annotation("CMU-1_classification.xml")
annotation.make_masks(slide, foreground=example_function)
patcher = wp.patcher(slide, "classification", annotation)
patcher.get_patch_parallel(["benign"])