Beispiel #1
0
def test_FindRegions():
    image = skimage.data.camera()
    with Pipeline() as pipeline:
        mask = ThresholdConst(image, 255)
        result = FindRegions(mask, image, 0, 100, padding=10)

    pipeline.run()
Beispiel #2
0
def test_ExtractROI():
    with Pipeline() as pipeline:
        image = Unpack([skimage.data.camera()])
        mask = ThresholdConst(image, 255)
        regions = FindRegions(mask, image)
        ExtractROI(image, regions)
        ExtractROI(image, regions, 0.5)

    pipeline.run()
Beispiel #3
0
def test_DrawContoursOnParent():
    image = skimage.data.camera()
    with Pipeline() as pipeline:
        mask = ThresholdConst(image, 255)
        regions = FindRegions(mask, image, 0, 100, padding=10)
        output_ref = image
        result = DrawContoursOnParent(image, mask, output_ref, regions, (0, 255, 0))

    stream = pipeline.transform_stream()
    pipeline.run()
Beispiel #4
0
def test_CalculateZooProcessFeatures(prefix):
    with Pipeline() as p:
        i = Unpack(range(10))
        mask = BinaryBlobs()
        image = NoiseImage(mask.shape)

        regionprops = FindRegions(mask, image)

        CalculateZooProcessFeatures(regionprops, prefix=prefix)

    p.run()
Beispiel #5
0
def test_FindRegions(warn_empty, recwarn):
    images = [skimage.data.camera(), np.zeros((10, 10), np.uint8) + 255]
    with Pipeline() as pipeline:
        image = Unpack(images)
        mask = ThresholdConst(image, 255)
        result = FindRegions(mask,
                             image,
                             0,
                             100,
                             padding=10,
                             warn_empty=warn_empty)

    pipeline.run()

    if warn_empty:
        w = recwarn.pop(UserWarning)
        assert re.search(r"^(Image|foo) did not contain any objects.$",
                         str(w.message))
    img_dilate = Call(cv2.dilate, img_canny, kernel, iterations=2)
    
    #Close
    kernel = Call(cv2.getStructuringElement, cv2.MORPH_ELLIPSE, (5, 5))
    img_close = Call(cv2.morphologyEx, img_dilate, cv2.MORPH_CLOSE, kernel, iterations=1)
     
    #Erode
    kernel = Call(cv2.getStructuringElement, cv2.MORPH_ELLIPSE, (15, 15))
    mask = Call(cv2.erode, img_close, kernel, iterations=2)
    
    frame_fn = Format(os.path.join(ANNOTATED, "{name}.jpg"), name=name)
    ImageWriter(frame_fn, mask)
    
    # Find objects
    regionprops = FindRegions(
        mask, img_gray, min_area=1000, padding=10, warn_empty=name
    )
    # For an object, extract a vignette/ROI from the image
    roi_orig = ExtractROI(img, regionprops, bg_color=255)
    
    # For an object, extract a vignette/ROI from the image
    roi_mask = ExtractROI(mask, regionprops, bg_color=255)


    # Generate an object identifier
    i = Enumerate()
    #Call(print,i)

    object_id = Format("{name}_{i:d}", name=name, i=i)
    #Call(print,object_id)
    
Beispiel #7
0
    # Remove path and extension from the filename
    source_basename = Call(lambda x: os.path.splitext(os.path.basename(x))[0], path)

    with ParallelPipeline():
        # The following operations are distributed among multiple
        # worker processes to speed up the calculations.

        # Read the image
        image = ImageReader(path)

        # Do some thresholding
        mask = image < 128

        # Find regions in the image
        region = FindRegions(mask, image)

        # Extract just the object
        roi_image = region.intensity_image

        # An object is identified by its label
        roi_label = region.label

        # Calculate a filename for the ROI image:
        # "RUNNING_NUMBER-SOURCE_BASENAME-ROI_LABEL"
        roi_name = Format(
            "{:d}-{}-{:d}.jpg", running_number, source_basename, roi_label
        )

        meta = CalculateZooProcessFeatures(region, prefix="object_")
        # End of parallel execution
Beispiel #8
0
            meta,
            drop_duplicates_subset="sample_id",
        )

        img = Call(skimage.io.imread, abs_path)

        StreamBuffer(maxsize=2)

        TQDM(rel_path)

        img = Rescale(img, in_range=(9252, 65278), dtype=np.uint8)

        mask = ThresholdConst(img, 245)  # 245(ubyte) / 62965(uint16)
        mask = Call(skimage.segmentation.clear_border, mask)

        regionprops = FindRegions(mask, img, 100, padding=10)

        # TODO: Draw object info

        # Extract a vignette from the image
        vignette = ExtractROI(img, regionprops)

        # # Extract features from vignette
        # model = resnet18(pretrained=True)
        # model = torch.nn.Sequential(OrderedDict(
        #     list(model.named_children())[:-2]))

        # features = PyTorch(lambda x: model(x).cpu().numpy())(vignette)

        i = Enumerate()
        object_id = Format(