def find_grains(input_file, output_dir=None):
    """Return tuple of segmentaitons (grains, difficult_regions)."""
    name = fpath2name(input_file)
    name = "grains-" + name + ".png"
    if output_dir:
        name = os.path.join(output_dir, name)

    image = Image.from_file(input_file)
    intensity = mean_intensity_projection(image)

# Median filter seems more robust than Otsu.
#   image = threshold_otsu(intensity)
    image = threshold_median(intensity, scale=0.8)

    image = invert(image)
    image = erode_binary(image, selem=disk(2))
    image = dilate_binary(image, selem=disk(2))
    image = remove_small_objects(image, min_size=200)
    image = fill_holes(image, min_size=50)

    dist = distance(image)
    seeds = local_maxima(dist)
    seeds = dilate_binary(seeds)  # Merge spurious double peaks.
    seeds = connected_components(seeds, background=0)

    segmentation = watershed_with_seeds(dist, seeds=seeds, mask=image)

    # Remove spurious blobs.
    segmentation = remove_large_segments(segmentation, max_size=3000)
    segmentation = remove_small_segments(segmentation, min_size=100)

    return segmentation
def find_grains(input_file, output_dir=None):
    """Return tuple of segmentaitons (grains, difficult_regions)."""
    name = fpath2name(input_file)
    name = "grains-" + name + ".png"
    if output_dir:
        name = os.path.join(output_dir, name)

    image = Image.from_file(input_file)
    intensity = mean_intensity_projection(image)
    image = remove_scalebar(intensity, np.mean(intensity))
    image = threshold_abs(image, 75)
    image = invert(image)
    image = fill_holes(image, min_size=500)
    image = erode_binary(image, selem=disk(4))
    image = remove_small_objects(image, min_size=500)
    image = dilate_binary(image, selem=disk(4))

    dist = distance(image)
    seeds = local_maxima(dist)
    seeds = dilate_binary(seeds)  # Merge spurious double peaks.
    seeds = connected_components(seeds, background=0)

    segmentation = watershed_with_seeds(dist, seeds=seeds, mask=image)
    # Need a copy to avoid over-writing original.
    initial_segmentation = np.copy(segmentation)

    # Remove spurious blobs.
    segmentation = remove_large_segments(segmentation, max_size=3000)
    segmentation = remove_small_segments(segmentation, min_size=500)
    props = skimage.measure.regionprops(segmentation)
    segmentation = remove_non_round(segmentation, props, 0.6)

    difficult = initial_segmentation - segmentation

    return segmentation, difficult
def segment(line_image, dilation):
    lines = convert_to_signal(line_image)
    lines = skeletonize(lines)
    lines = remove_small_objects(lines, min_size=10, connectivity=2)
    lines = dilate_binary(lines, selem=np.ones((1, dilation)))
    segmentation = connected_components(lines, background=0)
    return segmentation
    def test_dilate_binary(self):
        from jicbioimage.transform import dilate_binary
        from jicbioimage.core.image import Image
        array = np.array([[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 1, 0, 0],
                          [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]],
                         dtype=np.bool)
        expected = np.array([[0, 0, 0, 0, 0], [0, 0, 1, 0, 0], [0, 1, 1, 1, 0],
                             [0, 0, 1, 0, 0], [0, 0, 0, 0, 0]],
                            dtype=np.bool)
        dilated = dilate_binary(array)
        self.assertTrue(np.array_equal(expected, dilated))
        self.assertTrue(isinstance(dilated, Image))

        # The dilate_binary function only makes sense on dtype bool.
        with self.assertRaises(TypeError):
            dilate_binary(array.astype(np.uint8))
def analyse_image(image):
    image = normalise(image) * 255

    canvas = AnnotatedImage.from_grayscale(image)

    image = smooth_gaussian(image.astype(float), 5)
    image = threshold_abs(image, 30)

    image = erode_binary(image)
    image = remove_small_objects(image, 5)

    salem = skimage.morphology.disk(2)
    image = dilate_binary(image, salem)

    segmentation = connected_components(image, background=0)
    for i in segmentation.identifiers:
        color = pretty_color_from_identifier(i)

        region = segmentation.region_by_identifier(i)
        convex_hull = region.convex_hull
        outline = convex_hull.inner.border.dilate()

        canvas.mask_region(outline, color=color)

    return canvas
def cell_segmentation(wall_intensity2D, wall_mask2D, max_cell_size):
    """Return image segmented into cells."""
    seeds = dilate_binary(wall_mask2D)
    seeds = invert(seeds)
    seeds = remove_small_objects(seeds, min_size=10)
    seeds = connected_components(seeds, background=0)
    segmentation = watershed_with_seeds(-wall_intensity2D, seeds=seeds)
    segmentation = remove_large_segments(segmentation, max_cell_size)
    return segmentation
Exemple #7
0
def generate_cross_section_mask(image):
    image = find_edges_sobel(image)
    image = threshold_otsu(image)
    image = dilate_binary(image, selem=skimage.morphology.disk(5))
    image = remove_small_objects(image, 5000)
    image = fill_holes(image, 50000)
    image = erode_binary(image, selem=skimage.morphology.disk(10))
    image = remove_small_objects(image, 50000)
    return image
def generate_mask(image):
    mask = threshold_abs(image, 6500)
    mask = remove_small_objects(mask, 50)
    mask = fill_holes(mask, 5)

    selem = disk(3)
    mask = erode_binary(mask, selem)
    mask = dilate_binary(mask, selem)

    return mask
def generate_seeds(image):
    seeds = white_tophat(image, 10)

    seeds = threshold_abs(seeds, 1500)
    seeds = remove_small_objects(seeds, 50)

    selem = disk(5)
    seeds = dilate_binary(seeds, selem)

    return connected_components(seeds, background=0)
 def test_dilate_binary_with_selem(self):
     from jicbioimage.transform import dilate_binary
     selem = np.ones((3, 3))
     array = np.array([[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 1, 0, 0],
                       [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]],
                      dtype=np.bool)
     expected = np.array([[0, 0, 0, 0, 0], [0, 1, 1, 1, 0], [0, 1, 1, 1, 0],
                          [0, 1, 1, 1, 0], [0, 0, 0, 0, 0]],
                         dtype=np.bool)
     dilated = dilate_binary(array, selem=selem)
     self.assertTrue(np.array_equal(expected, dilated))
def segment_cells(image, max_cell_size):
    """Return segmented cells."""
    image = identity(image)

    wall = threshold_adaptive_median(image, block_size=101)
    seeds = remove_small_objects(wall, min_size=100)
    seeds = dilate_binary(seeds)
    seeds = invert(seeds)
    seeds = remove_small_objects(seeds, min_size=5)
    seeds = connected_components(seeds, background=0)

    segmentation = watershed_with_seeds(-image, seeds=seeds)
    segmentation = remove_large_segments(segmentation, max_cell_size)
    return segmentation, wall
def find_tubes(input_file, output_dir=None):
    """Return pollen tube segmentation."""
    name = fpath2name(input_file)
    name = "tubes-" + name + ".png"
    if output_dir:
        name = os.path.join(output_dir, name)

    image = Image.from_file(input_file)
    intensity = mean_intensity_projection(image)
    image = find_edges_sobel(intensity)
    image = remove_scalebar(image, 0)
    image = threshold_otsu(image)
    image = dilate_binary(image, selem=disk(3))
    image = erode_binary(image, selem=disk(3))
    image = remove_small_objects(image, min_size=500)
    image = fill_holes(image, min_size=500)
    image = erode_binary(image, selem=disk(3))
    image = remove_small_objects(image, min_size=200)

    segmentation = connected_components(image, background=0)

    return segmentation