Beispiel #1
0
 def border_distance(self):
     border_ref = MorphologyOps(self.ref, self.neigh).border_map()
     border_seg = MorphologyOps(self.seg, self.neigh).border_map()
     oppose_ref = 1 - self.ref
     oppose_seg = 1 - self.seg
     distance_ref = ndimage.distance_transform_edt(oppose_ref)
     distance_seg = ndimage.distance_transform_edt(oppose_seg)
     distance_border_seg = border_ref * distance_seg
     distance_border_ref = border_seg * distance_ref
     return distance_border_ref, distance_border_seg
def borders(seg, ref, neigh=8):
    """
    This function determines the points that lie on the border of the
    inferred and reference segmentations
    :param seg: numpy array with binary mask from inferred segmentation
    :param ref: numpy array with binary mask from reference segmentation
    :param neigh: connectivity 4 or 8
    :return: numpy arrays of reference and inferred segmentation borders
    """
    border_ref = MorphologyOps(ref[:, :, :, 0, 0], neigh).border_map()
    border_seg = MorphologyOps(seg[:, :, :, 0, 0], neigh).border_map()
    return border_ref, border_seg
 def _connected_components(self):
     """
     This function creates the maps of connected component for the
     reference and the segmentation image using the neighborhood defined
     in self.neigh
     :return: blobs_ref: connected labeling for the reference image,
     blobs_seg: connected labeling for the segmentation image,
     init: intersection between segmentation and reference
     """
     init = np.multiply(self.seg, self.ref)
     blobs_ref = MorphologyOps(self.ref, self.neigh).foreground_component()
     blobs_seg = MorphologyOps(self.seg, self.neigh).foreground_component()
     return blobs_ref, blobs_seg, init
 def border_distance(self):
     """
     This functions determines the map of distance from the borders of the
     segmentation and the reference and the border maps themselves
     :return: distance_border_ref, distance_border_seg, border_ref,
     border_seg
     """
     border_ref = MorphologyOps(self.ref, self.neigh).border_map()
     border_seg = MorphologyOps(self.seg, self.neigh).border_map()
     oppose_ref = 1 - self.ref
     oppose_seg = 1 - self.seg
     # euclidean distance transform
     distance_ref = ndimage.distance_transform_edt(oppose_ref)
     distance_seg = ndimage.distance_transform_edt(oppose_seg)
     distance_border_seg = border_ref * distance_seg
     distance_border_ref = border_seg * distance_ref
     return distance_border_ref, distance_border_seg, border_ref, border_seg
def connected_components(seg, ref, output_prob, neigh=8):
    """
    Numbers connected components in the reference and inferred segmentations
    :param seg: numpy array with binary mask from inferred segmentation
    :param ref: numpy array with binary mask from reference segmentation
    :param output_prob: Is the segmentation probabilistic (if so,
    argmax is used first to compute a label map)
    :param neigh: connectivity 4 or 8
    :return: (cc_map_ref, count) numbered connected components from reference
    :return: (cc_map_seg, count) numbered connected components from inferred
    """
    if output_prob:
        seg = np.argmax(seg, -1)
    blobs_ref = MorphologyOps(ref[:, :, :, 0, 0], neigh).foreground_component()
    blobs_seg = MorphologyOps(seg[:, :, :, 0, 0], neigh).foreground_component()

    return (blobs_ref[0][:, :, :, np.newaxis, np.newaxis], blobs_ref[1]), \
           (blobs_seg[0][:, :, :, np.newaxis, np.newaxis], blobs_seg[1]),
    def surface(self):
        """
        Similarly to the volume function, returns probabilistic sum, binary
        number, probabilistic volume and binarised volume of the segmentation
        border

        :return:
        """
        border_seg = MorphologyOps(self.seg, self.neigh).border_map()
        numb_border_seg_bin = np.sum(border_seg > 0)
        numb_border_seg = np.sum(border_seg)
        return numb_border_seg, numb_border_seg_bin, \
               numb_border_seg * self.vol_vox, numb_border_seg_bin * self.vol_vox
 def test_3d_offset(self):
     test_img = np.zeros([10, 10, 10])
     test_img[5, 5, 5] = 1
     # border is the same as the test image -- just the one positive voxel
     calculated_border = MorphologyOps(test_img, 8).border_map()
     self.assertTrue(np.array_equal(test_img, calculated_border))
Beispiel #8
0
 def surface(self):
     border_seg = MorphologyOps(self.seg, self.neigh).border_map()
     numb_border_seg_bin = np.sum(border_seg > 0)
     numb_border_seg = np.sum(border_seg)
     return numb_border_seg, numb_border_seg_bin, \
            numb_border_seg * self.vol_vox, numb_border_seg_bin * self.vol_vox
Beispiel #9
0
 def _connected_components(self):
     init = np.multiply(self.seg, self.ref)
     blobs_ref = MorphologyOps(self.ref, self.neigh).foreground_component()
     blobs_seg = MorphologyOps(self.seg, self.neigh).foreground_component()
     return blobs_ref, blobs_seg, init