Class RoiLabeling
This enables switching between different methods of representing regions as required.
- Author:
- Pete Bankhead
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
clearBoundary
(ByteProcessor bp, Roi roi, double clearValue) Starting from all white pixels (value = 255) on a ROI's boundary, fill the pixels with blackstatic void
clearOutside
(ImageProcessor ip, Roi roi) Clear (i.e.static void
Fill holes in a binary image.static void
fillOutside
(ImageProcessor ip, Roi roi, double value) Fill in a region outside a specified ROIstatic ByteProcessor
Create a binary image for pixels that have a higher value than their neighbors.static ByteProcessor
Create a binary image for pixels that have a lower value than their neighbors.static List
<PolygonRoi> getFilledPolygonROIs
(ImageProcessor ip, int wandMode) Get filled PolygonRois for connected pixels with the same value in an image.static List
<PolygonRoi> Experimental 8-connected ROI creation; non-zero pixels considered within objectsstatic Map
<Float, PolygonRoi> getFilledPolygonROIsFromLabels
(ImageProcessor ip, int wandMode) Get filled Polygon ROIs using distinct labels, creating a map between labels and ROIs.static ImageProcessor
labelImage
(ImageProcessor ip, float threshold, boolean conn8) Create a labelled image from above-threshold pixels for an image.static ImageProcessor
labelROIs
(ImageProcessor ipLabels, List<? extends Roi> rois) Label ROIs by filling each pixel with an integer value corresponding to the index of the Roi in the list + 1.static Roi[]
labelsToConnectedROIs
(ImageProcessor ipLabels, int n) Create ROIs from labels in an image.static List
<PolygonRoi> labelsToFilledRoiList
(ImageProcessor ipLabels, boolean conn8) Convert a labelled image into a list of PolygonRois by tracing.static PolygonRoi[]
labelsToFilledROIs
(ImageProcessor ipLabels, int n) Convert a labelled image into a list of PolygonRois by tracing.static int
removeByAreas
(ByteProcessor bp, double minPixels, double maxPixels, boolean conn8) Remove objects containing < minPixels or > maxPixels.static void
removeSmallAreas
(ByteProcessor bp, double minPixels, boolean conn8) Remove objects having small areas, defined in terms of pixelsstatic PolygonRoi
Convert a traced outline from the ImageJ Wand into a PolygonRoi.
-
Constructor Details
-
RoiLabeling
public RoiLabeling()
-
-
Method Details
-
findDirectionalMaxima
Create a binary image for pixels that have a higher value than their neighbors. Comparisons are made horizontally, vertically and diagonally. Pixels meeting the criterion have the value 255, all others are 0.- Parameters:
ip
-- Returns:
-
findDirectionalMinima
Create a binary image for pixels that have a lower value than their neighbors. Comparisons are made horizontally, vertically and diagonally. Pixels meeting the criterion have the value 255, all others are 0.- Parameters:
ip
-- Returns:
-
getFilledPolygonROIsExperimental
Experimental 8-connected ROI creation; non-zero pixels considered within objectsTODO: Improve experimental getFillPolygonROIs!!! Consider efficiency (i.e. no min filter) & standard ImageJ compatibility Using standard ImageJ draw/fill, the original binary image is NOT reconstructed.
- Parameters:
ip
-- Returns:
-
labelsToFilledROIs
Convert a labelled image into a list of PolygonRois by tracing.Note that labels are assumed not to contain any holes or nested ROIs; ROIs produced by this command will not contain holes.
Some entries in the resulting array may be null if this is not the case, or if not all labels are found. Otherwise, pixels with the integer label L will belong to the Roi in the output array at entry L-1
- Parameters:
ipLabels
-n
- maximum number of labels- Returns:
-
labelsToFilledRoiList
Convert a labelled image into a list of PolygonRois by tracing.Unlike labelsToFilledROIs, the order in which ROIs are returned is arbitrary.
Also, the multiple Rois may be created for the same label, if unconnected regions are used.
- Parameters:
ipLabels
-conn8
-- Returns:
-
labelsToConnectedROIs
Create ROIs from labels in an image.- Parameters:
ipLabels
- the labeled image; generally this should be a ByteProcessor or ShortProcessorn
- the total number of labels; often this is equal to the maximum value in the image- Returns:
- an array of length n; output[i] is the ROI for label i+1, or null if no Roi is found with that label.
-
getFilledPolygonROIsFromLabels
Get filled Polygon ROIs using distinct labels, creating a map between labels and ROIs.Note that discontinuous ROIs are not supported; if labelled regions are discontinuous, then ROIs detected earlier will be discarded from the map.
- Parameters:
ip
-wandMode
-- Returns:
-
getFilledPolygonROIs
Get filled PolygonRois for connected pixels with the same value in an image. Because this uses ImageJ's Wand tool, holes will be filled.Note that this command applies any thresholds that were set in the ImageProcessor, returning only Rois for values within these limits. Therefore to identify only non-zero pixels in a labelled image you may need to first call
ip.setThreshold(0.5, Double.POSITIVE_INFINITY, ImageProcessor.NO_LUT_UPDATE);
- Parameters:
ip
-wandMode
-- Returns:
-
wandToRoi
Convert a traced outline from the ImageJ Wand into a PolygonRoi.- Parameters:
wand
-- Returns:
-
fillHoles
Fill holes in a binary image.Assumes 255 is foreground, 0 is background.
Based on code in ImageJ's Binary class.
- Parameters:
bp
-
-
labelROIs
Label ROIs by filling each pixel with an integer value corresponding to the index of the Roi in the list + 1.- Parameters:
ipLabels
-rois
-- Returns:
-
labelImage
Create a labelled image from above-threshold pixels for an image.- Parameters:
ip
-threshold
-conn8
-- Returns:
- labelled image, as a ShortProcessor (if possible) or FloatProcessor (if necessary)
-
removeSmallAreas
Remove objects having small areas, defined in terms of pixels- Parameters:
bp
-minPixels
- minimum number of pixels in an object that should be keptconn8
-
-
removeByAreas
public static int removeByAreas(ByteProcessor bp, double minPixels, double maxPixels, boolean conn8) Remove objects containing < minPixels or > maxPixels.- Parameters:
bp
-minPixels
-maxPixels
-conn8
-- Returns:
- the number of connected objects remaining.
-
fillOutside
Fill in a region outside a specified ROI- Parameters:
ip
-roi
-value
-
-
clearOutside
Clear (i.e. set pixels to zero) in a region outside a specified ROI- Parameters:
ip
-roi
-
-
clearBoundary
Starting from all white pixels (value = 255) on a ROI's boundary, fill the pixels with black- Parameters:
bp
-roi
-clearValue
-
-