Package noduledistances.imagej
Class RoiOverlay
java.lang.Object
noduledistances.imagej.RoiOverlay
This class object is used to extract the nodule information from
the Nodule Segmentation plugin and incoporate that data
with the rest of this plugin.
It extracts the Roi data from the Tif image which stores the pixel location, area, and name of each nodule. It uses this data to add the nodules as nodes to the RootGraph.
It extracts the Roi data from the Tif image which stores the pixel location, area, and name of each nodule. It uses this data to add the nodules as nodes to the RootGraph.
- Author:
- Brandin Farris
-
Constructor Summary
ConstructorsConstructorDescriptionRoiOverlay(ij.ImagePlus imp) Extracts the Roi information from the loaded Tif image. -
Method Summary
Modifier and TypeMethodDescriptiondouble[]attachmentPoint(ij.gui.ShapeRoi roi, RootGraph graph) Computes what we will use as the node for the given nodule.averagePoint(Point[] points) Computes the average(or centroid) of the given array of points. i.e. it computes the mean of the X values and the mean of the Y values, and returns those as a point.protected ArrayList<ij.gui.ShapeRoi>breakupClump(ij.gui.ShapeRoi roi, int numNods, List<org.apache.commons.math3.ml.clustering.CentroidCluster<ClumpClusterPoint>> clusters) Uses the computed clusters to breakup the given roi into an arrayList of individual Rois.Point[]getBoundaryPoints(ij.gui.ShapeRoi roi, ArrayList<ij.gui.ShapeRoi> intersections) For each line in intersections, it records the points of where that line intersects the given roi, if any.int[]getClumpData(ij.gui.ShapeRoi roi, int numNods, RootGraph graph) Uses k-means clustering to break up the given roi into several pieces.getHaltonSequence(ij.gui.ShapeRoi roi) Computes the halton sequence for a given ROI to create a sample of uniformly distributed points within the Roi polygon by intersecting the halton sequence with the polygon.getHaltonVectors(int numberOfPoints, Rectangle boundingBox) Computes generic halton vectors, and scales them to fill a bounding box.ArrayList<int[]>getRoiCentroids(RootGraph graph) finds the centroid of all ROI's, and returns them in [color,x,y,area] format.static List<org.apache.commons.math3.ml.clustering.CentroidCluster<ClumpClusterPoint>>kMeansClustering(List<ClumpClusterPoint> points, int k) performs k-means clustering on a given set of points to break nodule clumps into k parts.static booleanonBoundary(double p1x, double p1y, double p2x, double p2y, double x, double y) ChatGPT was used in making this method.
Determines whether a given point (x, y) is within 2 pixels from a line segment defined by the points (p1x, p1y) and (p2x, p2y).protected int[]trimArray(int[] array, int length) removes trailing zeros that result from the Power Diagram output.
-
Constructor Details
-
RoiOverlay
public RoiOverlay(ij.ImagePlus imp) Extracts the Roi information from the loaded Tif image. Returns early if passed image file does not have an Overlay- Parameters:
imp- : image file with attached Overlay. Only TIF files can hold Overlays.
-
-
Method Details
-
attachmentPoint
Computes what we will use as the node for the given nodule. Does this in two different ways: First it will try the following procedure to find an ideal attachmnet point:
1. Find all edges intersecting the nodule
2. find the list of points that is those lines intersecting with the boundary of the roi
3. compute the average of those points.
If no such points can be found, the method defaults to computing the contour centroid of the roi.
All versions of the plugin prior to 2/4/25 contain an error causing the first method to always return empty, so only the contour centroid was used.- Parameters:
roi- :nodule to find the node location(attachment point) of.graph- graph object.- Returns:
- : [x,y] location of where the nodule node will go.
-
averagePoint
Computes the average(or centroid) of the given array of points. i.e. it computes the mean of the X values and the mean of the Y values, and returns those as a point.- Parameters:
points- : points to compute the centroid of- Returns:
- : a Point consisting of [meanX, meanY]
-
getBoundaryPoints
For each line in intersections, it records the points of where that line intersects the given roi, if any. Returns all such points in a Point[] object.- Parameters:
roi- : Roi whose boundary is intersected with all lines in intersections.intersections- : ArrayList of lines stored as ShapeRoi's to intersect with the given roi.- Returns:
- : Returns an array of points that are where the boundary of the roi meet with any of the lines in intersections.
-
onBoundary
public static boolean onBoundary(double p1x, double p1y, double p2x, double p2y, double x, double y) ChatGPT was used in making this method.
Determines whether a given point (x, y) is within 2 pixels from a line segment defined by the points (p1x, p1y) and (p2x, p2y). The method calculates the perpendicular distance from the point to the line segment and checks if it is less than 2 units.- Parameters:
p1x- The x-coordinate of the first endpoint of the line segment.p1y- The y-coordinate of the first endpoint of the line segment.p2x- The x-coordinate of the second endpoint of the line segment.p2y- The y-coordinate of the second endpoint of the line segment.x- The x-coordinate of the point to check.y- The y-coordinate of the point to check.- Returns:
trueif the point is within 2 units of the line segment,falseotherwise.
-
getRoiCentroids
finds the centroid of all ROI's, and returns them in [color,x,y,area] format. For nodules that were initially clumps, we return all of their information in one row. color: red==1, green==2, mixed==3- Returns:
- [color,x,y,area] coordinates of the roi centroids.
-
getHaltonSequence
Computes the halton sequence for a given ROI to create a sample of uniformly distributed points within the Roi polygon by intersecting the halton sequence with the polygon. We use the halton sequence to generate the points instead of random sampling becaues the halton sequence produces a very uniform distribution of points.- Parameters:
roi- : Rois that we are creating the points for.- Returns:
- List object of points to cluster.
-
kMeansClustering
public static List<org.apache.commons.math3.ml.clustering.CentroidCluster<ClumpClusterPoint>> kMeansClustering(List<ClumpClusterPoint> points, int k) performs k-means clustering on a given set of points to break nodule clumps into k parts.- Parameters:
points- point cloud representation of an ROI polygonk- number of nodules to break the clump into.- Returns:
- List object of k centroids after performing k-means.
-
getHaltonVectors
Computes generic halton vectors, and scales them to fill a bounding box. This is what intersects a polygon ROI to get the uniform point cloud representation of an ROI polygon.- Parameters:
numberOfPoints- : number of halton vectors to generate.boundingBox- : bounds of the halton vectors.- Returns:
- List object of halton vectors. Uses ClumpClusterPoint to implement Clusterable interface.
-
getClumpData
Uses k-means clustering to break up the given roi into several pieces. The given roi is assumed to be a clump of several nodules.- Parameters:
roi- : roi that we're breaking into parts.numNods- : the number of parts we're breaking the roi into{'.- Returns:
- centroid and area of each ROI in color,x,y,area format.;
-
breakupClump
protected ArrayList<ij.gui.ShapeRoi> breakupClump(ij.gui.ShapeRoi roi, int numNods, List<org.apache.commons.math3.ml.clustering.CentroidCluster<ClumpClusterPoint>> clusters) Uses the computed clusters to breakup the given roi into an arrayList of individual Rois. Returns the separated Roi objects.- Parameters:
roi- : nodule Roi that is found to be a nodule clump and is being separated.numNods- : number of nodules within the given nodule Roi.clusters- : computed clusters within the given nodule Roi.- Returns:
- : numNods shapeRois that togehter make up the original roi.
-
trimArray
protected int[] trimArray(int[] array, int length) removes trailing zeros that result from the Power Diagram output.- Parameters:
array-- Returns:
-