Exemple #1
0
def test_ImageWriter(tmp_path):
    d = tmp_path / "sub"
    d.mkdir()
    p = d / "new.jpg"
    image = skimage.data.camera()
    with Pipeline() as pipeline:
        result = ImageWriter(p, image)

    pipeline.run()
Exemple #2
0
"""Process video data using MorphoCut and store frames as individual frames."""

from morphocut import Pipeline
from morphocut.image import ImageWriter
from morphocut.pims import VideoReader
from morphocut.str import Format

with Pipeline() as p:
    # Read individual frames from a video file
    frame = VideoReader("/path/to/video.avi")

    # Format filename
    filename = Format("/output/path/frame_#{}.png", frame.frame_no)

    # Write individual frames as image files
    ImageWriter(filename, frame)

p.run()
    # Show progress bar for frames
    #TQDM(Format("Frame {name}", name=name))
    
    # Apply running median to approximate the background image
    flat_field = RunningMedian(img, 5)

    # Correct image
    img = img / flat_field
    
    # Rescale intensities and convert to uint8 to speed up calculations
    img = RescaleIntensity(img, in_range=(0, 1.1), dtype="uint8")
    
    FilterVariables(name,img)
    #
    frame_fn = Format(os.path.join(CLEAN, "{name}.jpg"), name=name)
    ImageWriter(frame_fn, img)
    
    # Convert image to uint8 gray
    img_gray = RGB2Gray(img)
    
    # ?
    img_gray = Call(img_as_ubyte, img_gray)

    #Canny edge detection
    img_canny = Call(cv2.Canny, img_gray, 50,100)

    #Dilate
    kernel = Call(cv2.getStructuringElement, cv2.MORPH_ELLIPSE, (15, 15))
    img_dilate = Call(cv2.dilate, img_canny, kernel, iterations=2)
    
    #Close
Exemple #4
0
        img = RescaleIntensity(img, in_range=(0, 1.1), dtype="uint8")

        # Show progress bar for frames
        TQDM(Format("Frame {name}", name=name))

        # Convert image to uint8 gray
        img_gray = RGB2Gray(img)
        img_gray = Call(img_as_ubyte, img_gray)

        # Apply threshold find objects
        threshold = 204  # Call(skimage.filters.threshold_otsu, img_gray)
        mask = img_gray < threshold

        # Write corrected frames
        frame_fn = Format(os.path.join(export_path, "{name}.jpg"), name=name)
        ImageWriter(frame_fn, img)

        # Find objects
        regionprops = FindRegions(mask,
                                  img_gray,
                                  min_area=100,
                                  padding=10,
                                  warn_empty=name)

        # For an object, extract a vignette/ROI from the image
        roi_orig = ExtractROI(img, regionprops, bg_color=255)
        roi_gray = ExtractROI(img_gray, regionprops, bg_color=255)

        # Generate an object identifier
        i = Enumerate()
        object_id = Format("{name}_{i:d}", name=name, i=i)
Exemple #5
0
from morphocut.image import ImageWriter, RescaleIntensity
from morphocut.pims import BioformatsReader
from morphocut.str import Format
from morphocut.stream import TQDM, Slice, Pack

if __name__ == "__main__":
    with Pipeline() as p:
        input_fn = "/home/moi/Work/0-Datasets/06_CD20_brightfield_6.cif"

        frame, series = BioformatsReader(input_fn, meta=False)

        # Every second frame is in fact a mask
        # TODO: Batch consecutive objects in the stream

        frame, mask = Pack(2, frame).unpack(2)

        image_fn = Format("/tmp/cif/{}-img.png", series)
        mask_fn = Format("/tmp/cif/{}-mask.png", series)

        frame = RescaleIntensity(frame, dtype=np.uint8)
        mask = RescaleIntensity(mask, dtype=np.uint8)

        ImageWriter(image_fn, frame)
        ImageWriter(mask_fn, mask)

        TQDM()

    print(p)

    p.run()
    Call(rgb, 255, 0, 255)
    # For an object, extract a vignette/ROI from the image
    roi_orig = ExtractROI(img, 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)

    object_fn = Format(os.path.join("/home/pi/PlanktonScope/", "OBJECTS",
                                    "{name}.jpg"),
                       name=object_id)

    ImageWriter(object_fn, roi_orig)

    # Calculate features. The calculated features are added to the global_metadata.
    # Returns a Variable representing a dict for every object in the stream.
    meta = CalculateZooProcessFeatures(regionprops,
                                       prefix="object_",
                                       meta=global_metadata)

    #     json_meta = Call(json.dumps,meta, sort_keys=True, default=str)

    #     Call(client.publish, "receiver/segmentation/metric", json_meta)

    # Add object_id to the metadata dictionary
    meta["object_id"] = object_id

    # Generate object filenames