def min_model(I, Delta=0.3, MaxLength=255, Compaction=3, MinArea=100, MinWidth=5, MinDepth=2, MinConcavity=np.inf): """Performs a nuclear segmentation using a gradient contour tracing and geometry splitting algorithm. Implemented from the reference below. Parameters ---------- I : array_like An intensity image used for analyzing local minima/maxima and gradients. Dimensions M x N. Delta : float Fractional difference threshold between minima/maxima pairs to be included in seed point detection. Fractional difference ([0, 1]) in total image range e.g. Delta = 0.3 with a uint8 input would translate to 0.3 * 255. Default value = 0.3. MaxLength : int Maximum allowable contour length. Default value = 255. Compaction : int Factor used in compacting objects to remove thin spurs. Refered to as 'd' in the paper. Default value = 3. MinArea : int Minimum area of objects to analyze. Default value = 100. MinWidth : int Minimum max-width of objects to analyze. Default value = 5. MinDepth : float Minimum depth of concavities to consider during geometric splitting. Default value = 2. MinConcavity : float Minimum concavity score to consider when performing for geometric splitting. Default value = np.inf. Notes ----- Objects are assumed to be dark (as nuclei in hematoxylin channel from color deconvolution). Smoothing improves accuracy and computation time by eliminating spurious seed points. Specifying a value for 'Delta' prevents shallow transitions from being included, also reducing computation time and increasing specificity. Returns ------- X : array_like A 1D array of horizontal coordinates of contour seed pixels for tracing. Y : array_like A 1D array of the vertical coordinates of seed pixels for tracing. Min : array_like A 1D array of the corresponding minimum values for contour tracing of seed point X, Y. Max : array_like A 1D array of the corresponding maximum values for contour tracing of seed point X, Y. See Also -------- histomicstk.segmentation.label.trace_object_boundaries References ---------- .. [#] S. Weinert et al "Detection and Segmentation of Cell Nuclei in Virtual Microscopy Images: A Minimum-Model Approach" in Nature Scientific Reports,vol.2,no.503, doi:10.1038/srep00503, 2012. """ # identify contour seed points X, Y, Min, Max = seed_contours(I, Delta) # trace contours from seeds cXs, cYs = trace_contours(I, X, Y, Min, Max, MaxLength=255) # score successfully traced contours Scores = score_contours(I, cXs, cYs) # construct label image from scored contours Label = label_contour(I.shape, cXs, cYs, Scores) # compact contours to remove spurs - the paper calls this "optimization" Label = label.compact(Label, Compaction) # cleanup label image Label = label.split(Label) Label = label.area_open(Label, MinArea) Label = label.width_open(Label, MinWidth) # split objects with concavities Label = split_concavities(Label, MinDepth, MinConcavity) return Label
def min_model(I, Delta=0.3, MaxLength=255, Compaction=3, MinArea=100, MinWidth=5, MinDepth=2, MinConcavity=np.inf): """Performs a nuclear segmentation using a gradient contour tracing and geometry splitting algorithm. Implemented from the reference below. Parameters ---------- I : array_like An intensity image used for analyzing local minima/maxima and gradients. Dimensions M x N. Delta : float Percent difference threshold between minima/maxima pairs to be included in seed point detection. Percentage difference ([0, 1]) in total image range e.g. Delta = 0.3 with a uint8 input would translate to 0.3 * 255. Default value = 0.3. MaxLength : int Maximum allowable contour length. Default value = 255. Compaction : int Factor used in compacting objects to remove thin spurs. Refered to as 'd' in the paper. Default value = 3. MinArea : int Minimum area of objects to analyze. Default value = 100. MinWidth : int Minimum max-width of objects to analyze. Default value = 5. MinDepth : float Minimum depth of concavities to consider during geometric splitting. Default value = 2. MinConcavity : float Minimum concavity score to consider when performing for geometric splitting. Default value = np.inf. Notes ----- Objects are assumed to be dark (as nuclei in hematoxylin channel from color deconvolution). Smoothing improves accuracy and computation time by eliminating spurious seed points. Specifying a value for 'Delta' prevents shallow transitions from being included, also reducing computation time and increasing specificity. Returns ------- X : array_like A 1D array of horizontal coordinates of contour seed pixels for tracing. Y : array_like A 1D array of the vertical coordinates of seed pixels for tracing. Min : array_like A 1D array of the corresponding minimum values for contour tracing of seed point X, Y. Max : array_like A 1D array of the corresponding maximum values for contour tracing of seed point X, Y. See Also -------- histomicstk.segmentation.label.trace_boundaries References ---------- .. [1] S. Weinert et al "Detection and Segmentation of Cell Nuclei in Virtual Microscopy Images: A Minimum-Model Approach" in Nature Scientific Reports,vol.2,no.503, doi:10.1038/srep00503, 2012. """ # identify contour seed points X, Y, Min, Max = seed_contours(I, Delta) # trace contours from seeds cXs, cYs = trace_contours(I, X, Y, Min, Max, MaxLength=255) # score successfully traced contours Scores = score_contours(I, cXs, cYs) # construct label image from scored contours Label = label_contour(I.shape, cXs, cYs, Scores) # compact contours to remove spurs - the paper calls this "optimization" Label = label.compact(Label, Compaction) # cleanup label image Label = label.split(Label) Label = label.area_open(Label, MinArea) Label = label.width_open(Label, MinWidth) # split objects with concavities Label = split_concavities(Label, MinDepth, MinConcavity) return Label