Package gov.nih.mipav.model.algorithms
Class AlgorithmCircleGeneration
java.lang.Object
java.lang.Thread
gov.nih.mipav.model.algorithms.AlgorithmBase
gov.nih.mipav.model.algorithms.AlgorithmCircleGeneration
- All Implemented Interfaces:
ActionListener,WindowListener,Runnable,EventListener
This module draws uniformly randomly positioned circles with a specified radius.
See http://www.indiana.edu/~statmath for skewness, kurtosis, and Jarque-Bera Test that uses skewness
and kurtosis to test for normality. Tests for a Gaussian fit reveal nothing since RANDOM, AGGREGATED,
UNIFORM, and CONSTRAINED patterns all fail Gaussian fit tests.
From Computational Methods in Biophysics, Biomaterials, BioTechnology, and Medical Systems
Algorithm Development, Mathematical Analysis, and Diagnostics Volume 2 Computational Methods edited by Cornelius
T. Leondes, Chapter 2 Computer techniques for spatial analysis of objects in biomedical images by
G. Cevenini, M. R. Massia, and P. Barbini, Kluwer Academic Publishers, 2003, pp. 39-90, information about
randomly distributed circles.
"Analysis of the distribution W**2 of squared NN distances between n randomly distributed circles shows that
2*lambda*PI*(W**2 - n*diameter**2)
has a chi-squared distribution with 2*n degrees of freedom. diameter is the average diameter of the circular objects,
lambda is the mean number per unit area.
X is a point to NN object distance.
W is an inter-object NN distance. Consider W as going from the center of one object to the center of
the nearest object.
The point-object squared NN distance distribution, X**2, is not affected by the reperesentation of objects
as circles, thus 2*lambda*X**2 also has a chi-squared distribution with 2m degrees of freedom, where m is the
number of selected points. It means that, under the assumption of circular objecs of equal size, all tests
based on squared NN distances, like those of Hopkins, Brown, or others, can still be used. If m = n, and these
results are combined, an estimate of the mean radius of the objects as circles can be obtained as
rest = sqrt((W**2 - X**2)/n)
Again, a Monte Carlo approach is sugested. If rest is significantly different from the value measured directly
on the image by automatic procedures of digital image processing or a value nevertheless compatible with the
average physical size of the objects, we can sustain that the statistical pattern is not random. If rest is high,
it indicates regularity; if low, aggregation. Moreover, since the formula for rest is formally a function of NN
distances, we can again inspect classes of distances to obtain scale-related indications about the statistical
pattern.
Best reference for nearest neighbor distribution for equally sized circles is: "Nearest Neighbor Assessments of
Spatial Configurations of Circles rather Than Points" by Daniel Simberloff, Ecology, Vol. 60, No. 4, Aug. 1979,
pp. 679-685.
d = diameter
lambda = mean number per unit area
Dr. Daniel Simberloff writes:
"In any event, you are probably correct that it would be more logical to caclulate rho for the points only in
the interior, not the border region, remembering to leave out the border region when calculating area."
mean nearest neighbor value = d + (exp(lambda * PI * d**2)/sqrt(lambda)*integral from t = d*sqrt(2*lambda*PI) to
t = infinity of (1/sqrt(2*PI))*exp(-t**2/2)dt. The integral is simply the 1 - Gaussian probability integral.
E(nearest neighbor distance squared) = d**2 + 1/(lambda * PI)
variance = E(r**2) - [E(r)]**2 = d**2 + 1/(lambda * PI) - [E(r)]**2
standard error = sqrt(variance)/sqrt(N)
Get percentile from Gaussian probability integral.
If the measured mean is significantly greater than the analytical mean, the distribution is uniform or regular.
If the measured mean is signficantly less than than the analytical mean, the distribution is clumped or
aggregated.
For larger circles these equations become increasingly inaccurate because an assumption of the Poisson
distribution of rare events is violated: the mean number of circles per sampling unit is not small relative
to the maximum possible number of circles per sampling unit. In fact for a given lambda there is a maximum
E[r]= sqrt(2)/((3**0.25)*sqrt(lambda)), which obtains when all the points are perfectly arranged as vertices
of a hexagonal lattice. Put another way, the maximum size circles that can be arranged with density lambda
have diameter d = sqrt(2)/((3**0.25)*sqrt(lambda)), and are located at the centers of hexagons completely
filling space. At d = sqrt(2)/((3**0.25)*sqrt(lambda)), the standard error of average r will be zero, since
there is only one possible arrangement. The Poisson derived expresion for standard error does not vanish until
d is somewhat greater than this maximum d.
According to Simberloff for d = 0 and lambda = 0.005, E[r] = 7.0711. When I ran a random distribution
for 10,000 by 1,000 with 50,000 circles requested and circle diameter = 0, I had observed mean = 7.09
and analytical mean = 7.0717.
The analytic equation for E[r(d,lambda)] is quite accurate for d as large as E[r(0, lambda)]; it exceeds the
simulated value by only 6.6%. The analytic equation for the standard error begins to go badly awry at
approximately d = 0.75E[r(0,lambda)]. For example, for d = E[r(0,lambda)], whereas the equation for E[r]
exceeds its true value by only 6.6%, the calculated standard error exceeds the correct value by 29.1%.
For small circles either the analytic expressions or simulations for the expected mean nearest neighbor
and its standard error can be used, but for larger circles simulations should be used.
Let x2 = chi squared and v = degrees of freedom
The probability density function p(x2,v) = (1/((2**(v/2))* gamma(v/2)))*(x2**((v-2)/2))*exp(-x2/2)
The probability of observing a value of chi square that is larger than a particular value for a random
sample of N observations with v degrees of freedom is the integral of this probability from chi square = x2
to chi square = infinity.
I have used the formula from "Nearest-neighbor distribution functions in many-body systems" by S. Torquato,
B. Lu. and J. Rubinstein, The American Physical Society Physical Review A, Volume 41, Number 4,
February 15, 1990, pp. 2059-2075.
Let the area fraction of the circles = af
a2 = 4*af/((1 - af)**2)
b2 = 4*af*(2 + af)/((1 - af)**2)
mean nearest neighbor distance = diameter * (1 + 0.5*sqrt(PI/a2)*exp(b2*b2/(4*a2))*erfc[b2/(2*sqrt(a2))])
Torquato developed more accurate equations in 1995 superseding the 1990 equations. In "Nearest-neighbor
statistics for packings of hard spheres and disks" by S. Torquato, Physical Review E, Volume 51, Number 4,
April, 1995, pp. 3170 - 3182:
af = area fraction of circles
mean nearest neighbor distance = diameter * (1 + integral)
integral = integral from x = 1 to x = infinity of
exp{-af[4*a0*(x*x - 1) + 8*a1*(x - 1)]}
For af invalid input: '<'= 0.69, the freezing packing fraction:
a0 = (1 + 0.128*af)/((1 - af)**2)
a1 = -0.564*af/((1 - af)**2)
For 0.69 invalid input: '<' af invalid input: '<' 0.82, random close packing
gf(1) = (1 - 0.436*0.69)/((1 - 0.69)**2)
Professor Torquato confirmed that the phi in the disk gf(1) equation numerator is incorrectly missing a f subscript.
a0 = 2*gf(1)*(0.82 - 0.69)/(0.82 - af) - 1/(1 - af)
a1 = -gf(1)*(0.82 - 0.69)/(0.82 - af) + 1/(1 - af)
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) class(package private) class(package private) class(package private) classNested classes/interfaces inherited from class java.lang.Thread
Thread.Builder, Thread.State, Thread.UncaughtExceptionHandler -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intprivate doubleprivate doubleprivate intprivate doubleprivate doubleprivate doubleprivate intprivate intprivate doubleprivate intstatic final intstatic final intprivate doubleprivate doubleprivate doubleFields inherited from class gov.nih.mipav.model.algorithms.AlgorithmBase
destFlag, destImage, image25D, mask, maxProgressValue, minProgressValue, multiThreadingEnabled, nthreads, progress, progressModulus, progressStep, runningInSeparateThread, separable, srcImage, threadStoppedFields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY -
Constructor Summary
ConstructorsConstructorDescriptionAlgorithmCircleGeneration - default constructor.AlgorithmCircleGeneration(ModelImage srcImage, int radius, int numCircles, int pattern, int initialRandomCircles, double minimumNearestNeighborDistance, double maximumNearestNeighborDistance, double lowestForbiddenNNDistance, double highestForbiddenNNDistance, double highestRegenerationNNDistance, double semiMajorAxis, double semiMinorAxis, double phi, double smallestToLargestMajorAxisRatio) AlgorithmRandomCircleGeneration. -
Method Summary
Methods inherited from class gov.nih.mipav.model.algorithms.AlgorithmBase
actionPerformed, addListener, addProgressChangeListener, calculateImageSize, calculatePrincipleAxis, computeElapsedTime, computeElapsedTime, convertIntoFloat, delinkProgressToAlgorithm, delinkProgressToAlgorithmMulti, displayError, errorCleanUp, fireProgressStateChanged, fireProgressStateChanged, fireProgressStateChanged, fireProgressStateChanged, fireProgressStateChanged, generateProgressValues, getDestImage, getElapsedTime, getMask, getMaxProgressValue, getMinProgressValue, getNumberOfThreads, getProgress, getProgressChangeListener, getProgressChangeListeners, getProgressModulus, getProgressStep, getProgressValues, getSrcImage, isCompleted, isImage25D, isMultiThreadingEnabled, isRunningInSeparateThread, isThreadStopped, linkProgressToAlgorithm, linkProgressToAlgorithm, makeProgress, notifyListeners, removeListener, removeProgressChangeListener, run, setCompleted, setImage25D, setMask, setMaxProgressValue, setMinProgressValue, setMultiThreadingEnabled, setNumberOfThreads, setProgress, setProgressModulus, setProgressStep, setProgressValues, setProgressValues, setRunningInSeparateThread, setSrcImage, setStartTime, setThreadStopped, startMethod, windowActivated, windowClosed, windowClosing, windowDeactivated, windowDeiconified, windowIconified, windowOpenedMethods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, isVirtual, join, join, join, join, ofPlatform, ofVirtual, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, sleep, start, startVirtualThread, stop, suspend, threadId, toString, yield
-
Field Details
-
RANDOM
public static final int RANDOM- See Also:
-
AGGREGATED
public static final int AGGREGATED- See Also:
-
AGGREGATED_ELLIPSE
public static final int AGGREGATED_ELLIPSE- See Also:
-
AGGREGATED_ELLIPSE_RANDOM_ORIENTATION
public static final int AGGREGATED_ELLIPSE_RANDOM_ORIENTATION- See Also:
-
AGGREGATED_CIRCLES_DIFFERENT_SIZES
public static final int AGGREGATED_CIRCLES_DIFFERENT_SIZES- See Also:
-
AGGREGATED_ELLIPSE_RANDOM_ORIENTATION_DIFFERENT_SIZES
public static final int AGGREGATED_ELLIPSE_RANDOM_ORIENTATION_DIFFERENT_SIZES- See Also:
-
REGULAR
public static final int REGULAR- See Also:
-
CONSTRAINED
public static final int CONSTRAINED- See Also:
-
radius
private int radius -
numCircles
private int numCircles -
pattern
private int pattern -
initialRandomCircles
private int initialRandomCircles -
minimumNearestNeighborDistance
private double minimumNearestNeighborDistance -
maximumNearestNeighborDistance
private double maximumNearestNeighborDistance -
lowestForbiddenNNDistance
private double lowestForbiddenNNDistance -
highestForbiddenNNDistance
private double highestForbiddenNNDistance -
highestRegenerationNNDistance
private double highestRegenerationNNDistance -
semiMajorAxis
private double semiMajorAxis -
semiMinorAxis
private double semiMinorAxis -
phi
private double phi -
smallestToLargestMajorAxisRatio
private double smallestToLargestMajorAxisRatio
-
-
Constructor Details
-
AlgorithmCircleGeneration
public AlgorithmCircleGeneration()AlgorithmCircleGeneration - default constructor. -
AlgorithmCircleGeneration
public AlgorithmCircleGeneration(ModelImage srcImage, int radius, int numCircles, int pattern, int initialRandomCircles, double minimumNearestNeighborDistance, double maximumNearestNeighborDistance, double lowestForbiddenNNDistance, double highestForbiddenNNDistance, double highestRegenerationNNDistance, double semiMajorAxis, double semiMinorAxis, double phi, double smallestToLargestMajorAxisRatio) AlgorithmRandomCircleGeneration.- Parameters:
radius- Circle radiusnumCircles- Number of circles to be drawnpattern- RANDOM, AGGREGATED, or REGULARinitialRandomCircles- Used in AGGREGATED. initialRandomCircles are drawn randomly. The rest are drawn with nearestNeighborDistance less than or equal ot maximumNearestNeighborDistance.minimumNearestNeighborDistance- Used in REGULARmaximumNearestNeighborDistance- Used in AGGREGATED and REGULARlowestForbiddenNNDistance- Used in CONSTRAINEDhighestForbiddenNNDistance- Used in CONSTRAINEDsemiMajorAxis- used in AGGREGATED_ELIPSEsemiMinorAxis- used in AGGREGATED_ELLIPSEphi- used in AGGREGATED_ELLIPSEsmallestToLargestMajorAxisRatio- used in AGGREGATED_CIRCLES_DIFFERENT_SIZESsrcImg- Blank source image in which circles will be drawnhighestRegeneerationNNDistance- Used in CONSTRAINED
-
-
Method Details
-
finalize
public void finalize()finalize -- Overrides:
finalizein classAlgorithmBase
-
runAlgorithm
public void runAlgorithm()Starts the program.- Specified by:
runAlgorithmin classAlgorithmBase
-