示例#1
0
def select_targets(image1, image2):
    """Creates an image containing the overlapping regions from the passed
    images.

    Args:
        image1 (array-like): A binary image serving as reference in comparing
            image regions with another image.

        image2 (array-like): A binary image serving as samples in comparing
            image regions with the reference image.

    Returns:
        targets (array-like): An image containing the common regions in both of
            the passed images.

    """

    _image1, _image2 = _check_image(image1), _check_image(image2)

    masked = join_segmentations(_image1, _image2)
    masks = np.unique(masked)

    targets = np.zeros_like(_image1)
    targets[masked == masks[-1]] = 255

    return targets
示例#2
0
def region_selection(image, constraints):
    """Retain only the regions from a binary image with an area inside the
    specified range.

    Args:
        image (array-like): Input image. Is converted to grayscale if RGB.

        constraints (dict): Allows filtering of blobs based on geometrical
            properties.

    Returns:
        filtered (array-like): The region filtered version of the input image.

    """

    _image = utils._check_image(image)
    _constraints = utils._check_blob_constraints(constraints)

    labeled = measure.label(_image, neighbors=8, background=0)

    num_regions = labeled.max()
    wanted_blobs = [True] * num_regions

    regions = measure.regionprops(labeled)

    for num, blob in enumerate(regions):
        wanted_blobs[num] = _is_wanted_blob(blob, _constraints)

    filtered = _select_regions(labeled, wanted_blobs)

    return filtered
示例#3
0
def threshold(image, algorithm='otsu', nbins=256):
    """Computes thresholding value according to specified algorithm.

    Args:
        image (array-like): Input image. Is converted to grayscale if RGB.

        algorithm (str, {'otsu', 'li', 'yen'}): Thresholding algorithm to
            determine threshold value. Defaults to 'otsu'.

        nbins (int): The number of bins used to calculate histogram as input to
            thresholding algorithms. Defaults to 256 bins.

    Returns:
        thresh (float): Thresholding value.

    """

    _image = _check_image(image)

    if algorithm == 'otsu':
        thresh = filters.threshold_otsu(_image, nbins=nbins)

    elif algorithm == 'li':
        thresh = filters.threshold_li(_image)

    elif algorithm == 'yen':
        thresh = filters.threshold_yen(_image, nbins=nbins)

    else:
        raise ValueError('Algorithm {} not available'.format(algorithm))

    return thresh
示例#4
0
def region_labeling(image, neighbors=8, background=0):
    """Labels blobs of a binary image.

    Args:
        image (array-like): Input image. Is converted to grayscale if RGB.

        neighbors (int, {4, 8}): Specifies connectivity.

        background (int, float): The image background intensity value.

    Returns:
        labeled (array-like): The labeled version of the input image.

    """

    _image = utils._check_image(image)

    labeled = measure.label(_image, neighbors=neighbors, background=background)

    return labeled
示例#5
0
def clear_borders(image):
    """Creates an image containing only the inner cluter regions by removing
    the foreground borders of the original image around a center region of the
    image.

    Args:

    Returns:

    """

    _image = _check_image(image)

    center_region = binary_fill_holes(_image)

    center = np.zeros_like(_image)
    center[center_region == True] = 255

    cleared = _image - center

    return -cleared
示例#6
0
def binarize(image, thresh, foreground=255):
    """Creates a binary image from an original image and a thresholding value.

    Args:
        image (array-like): Input image. Is converted to grayscale if RGB.

        thresh (int): Optional threshold value to use instead of a thresholding
            algorithm. Defaults to None.

        foreground (int, float): The image foreground intensity value.

    Returns:
        binary (array-like): A binarized version of the input image.

    """

    _image = _check_image(image)

    binary = np.zeros_like(_image, dtype=np.uint8)

    binary[_image > thresh] = foreground

    return binary