Class AlgorithmColocalizationEM
- java.lang.Object
-
- java.lang.Thread
-
- gov.nih.mipav.model.algorithms.AlgorithmBase
-
- gov.nih.mipav.model.algorithms.AlgorithmColocalizationEM
-
- All Implemented Interfaces:
java.awt.event.ActionListener,java.awt.event.WindowListener,java.lang.Runnable,java.util.EventListener
public class AlgorithmColocalizationEM extends AlgorithmBase
An optional registration may be performed before colocalization. In this registration both images or colors are moved halfway to a common center point. AlgorithmRegOAR2D is used with the cost function being the only registration parameter the user can vary in the dialog box. Correlation ratio is the default, but the user can also select least squares, normalized cross correlation, or normalized mutual information. The colocalization will be performed on the registered image or images rather than on the original image. If the maximum data range is decreased, the bin1 or bin2 will be decreased if necessary to keep them from exceeding the actual number of channels in the data range.A histogram buffer is generated with bin1 counts along the x axis and bin2 counts along the y axis. bin1 and bin2 are user selectable in the dialog. leftPad, rightPad, bottomPad, and topPad spaces are left around the data area in histBuffer to allow room for axis lines and labels.
The user specifies the number of gaussian distributions. For each distribution the initial values of the means, standard deviations, and correlation are assigned using a random number generator. Each distribution is initially assigned an equal probability.
The ellipse corresponds to a contour of constant probabliity density on which the density is smaller by a factor of exp[-0.5] than it is at the mean point. The probability density function is a jointly gaussian or bivariate gaussian density function. In each iteration: 1.) Find the gaussian distribution j with the form: p(x,y/j) = (1/(2*PI*stdxj*stdyj*sqrt(1 - rhoj**2))) * exp{(-1/(2*(1 - rhoj**2)))[((x-meanxj)**2)/(stdxj**2) - (2*rhoj*(x-meanxj)*(y-meanyj))/(stdxj*stdyj) + ((y - meanyj)**2)/(stdyj**2)]} where stdxj and stdyj are the x and y standard deviations and rhoj is the correlation coefficient.
2.) p(x,y) are found from p(x,y) = sum over j of p(x,y/j)*p(j). 3.) Pold(j/(x,y) = (sum over all j of Pold(x,y/j)*Pold(j))/Pold(x,y)
The update equations for the values of the new variables for each gaussian distribution j are: 4.) meanxj = (sum over x,y of Pold(j/(x,y))*x)/(sum over x,y of Pold(j/(x,y))) 5.) meanyj = (sum over x,y of Pold(j/(x,y))*y)/(sum over x,y of Pold(j/(x,y))) 6.) stdxj**2 = (sum over x,y of Pold(j/(x,y)) * (x - meanxj)**2)/ (sum over x,y of Pold(j/(x,y))) 7.) stdyj**2 = (sum over x,y of Pold(j/(x,y)) * (y - meanyj)**2)/ (sum over x,y of Pold(j/(x,y))) 8.) rhoj = (sum over x,y of Pold(j/(x,y)) * (x - meanxj) * (y - meanyj)/(stdjx * stdjy))/ (sum over x,y of Pold(j/(x,y)))
9.) Each new p[j] is found from (sum over x,y of Pold(j/(x,y)))/number of (x,y) points These 9 basic steps are iterated the number of times specified by the user.
The calculated data is passed to ViewJFrameColocalization.
References:
1.) Expectation Maximization Algorithm by Ismet Bayraktaroglu (ismet@bayraktaroglu.org) Code for circles was originally found at http://www-cse.ucsd.edu/users/ibayrakt/java/em but this site is no longer available.
2.) Neural Networks for Pattern Recognition by Christopher M. Bishop, Oxford University Press, 1995, Section 2.6.2 The EM algorithm, pp. 65 - 72.
3.) Probability, Random Variables, and Random Signal Principles, Second Edition by Peyton Z. Peebles, Jr., McGraw-Hill Book Company, 1987, Section 5.3 Jointly Gaussian Random Variables, pp. 124 - 128.
4.) Clustering Algorithms by John A. Hartigan, Wiley, John & Sons, Incorporated, 1975, Chapter 5, Mixtures, pp. 113 - 129.
5.) Principles of Data Mining by David Hand, Heikki Mannila, and Padhraic Smith, A Bradford Book The MIT Press, 2001, pp. 260 - 265, 281 - 284, 315 - 323.
-
-
Field Summary
Fields Modifier and Type Field Description (package private) float[]b1DOCUMENT ME!(package private) float[]b2DOCUMENT ME!private ModelImagebaseImageDOCUMENT ME!private intbin1DOCUMENT ME!private intbin2DOCUMENT ME!private intbottomPadDOCUMENT ME!(package private) float[]bufferDOCUMENT ME!private intcostDOCUMENT ME!private intcountDOCUMENT ME!private double[]dMaxDOCUMENT ME!private double[]dMinDOCUMENT ME!private booleandoOrIf true, or thresholds.private booleanentireImageDOCUMENT ME!private intgaussiansDOCUMENT ME!private double[]halfMajorDOCUMENT ME!private double[]halfMinorDOCUMENT ME!(package private) java.util.BitSetinputMaskDOCUMENT ME!private intiterationsDOCUMENT ME!private intleftPadSpace padding around the histogram data area.private double[][]meanDOCUMENT ME!private double[][]meanOldDOCUMENT ME!private byte[]mostProbableClassDOCUMENT ME!private double[]probDOCUMENT ME!private double[]probOldDOCUMENT ME!private double[]probXDOCUMENT ME!private double[]probXOldDOCUMENT ME!private booleanregisterDOCUMENT ME!private double[]rhoDOCUMENT ME!private double[]rhoOldDOCUMENT ME!private intrightPadDOCUMENT ME!(package private) float[]secondBufferDOCUMENT ME!private byte[]segBufferDOCUMENT ME!private ModelImagesegImageDisplays classes to which pixels belong.private double[][]stdDOCUMENT ME!private double[][]stdOldDOCUMENT ME!private double[]thetaDOCUMENT ME!private floatthreshold1The minimum values that are considered as data values.private floatthreshold2DOCUMENT ME!private inttopPadDOCUMENT ME!private booleanuseBlueDOCUMENT ME!private booleanuseGreenDOCUMENT ME!private booleanuseRedDOCUMENT ME!(package private) intxDimDOCUMENT ME!(package private) intyDimDOCUMENT ME!(package private) intzDimDOCUMENT ME!-
Fields inherited from class gov.nih.mipav.model.algorithms.AlgorithmBase
destFlag, destImage, image25D, mask, maxProgressValue, minProgressValue, multiThreadingEnabled, nthreads, progress, progressModulus, progressStep, runningInSeparateThread, separable, srcImage, threadStopped
-
-
Constructor Summary
Constructors Constructor Description AlgorithmColocalizationEM(ModelImage destImg, ModelImage segImage, ModelImage srcImg, int bin1, int bin2, float threshold1, float threshold2, boolean doOr, int leftPad, int rightPad, int bottomPad, int topPad, boolean useRed, boolean useGreen, boolean useBlue, boolean entireImage, boolean register, int cost, int gaussians, int iterations)Constructor for images in which 2D histogram is placed in a predetermined destination image.AlgorithmColocalizationEM(ModelImage destImg, ModelImage segImage, ModelImage srcImg, ModelImage baseImage, int bin1, int bin2, float threshold1, float threshold2, boolean doOr, int leftPad, int rightPad, int bottomPad, int topPad, boolean entireImage, boolean register, int cost, int gaussians, int iterations)Constructor for images in which 2D histogram is placed in a predetermined destination image.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidcalc2D()This function produces a 2D histogram image with srcImage values represented across the x axis and baseImage values represented across the y axis.private voidcalc3D()This function produces a 2D histogram image with srcImage values represented across the x axis and baseImage values represented across the y axis.private voidcalcColor2D()This function produces a 2D histogram image with first color values represented across the x axis and second color values represented across the y axis.private voidcalcColor3D()This function produces a 2D histogram image with first color values represented across the x axis and second color values represented across the y axis.private voidemfunction()DOCUMENT ME!voidfinalize()Prepares this class for destruction.private voidgetProbX()DOCUMENT ME!private voidgetProbXOld()DOCUMENT ME!private voidnewToOld()DOCUMENT ME!private doubleprobjxOld(int i, int j)DOCUMENT ME!private doubleprobXj(int i, int j)DOCUMENT ME!private doubleprobXjOld(int i, int j)DOCUMENT ME!voidrunAlgorithm()starts the algorithm.voidupdateFileInfo(ModelImage image, ModelImage resultImage)Copy important file information to resultant image structure.-
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, windowOpened
-
Methods 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, join, join, join, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, toString, yield
-
-
-
-
Field Detail
-
b1
float[] b1
DOCUMENT ME!
-
b2
float[] b2
DOCUMENT ME!
-
buffer
float[] buffer
DOCUMENT ME!
-
inputMask
java.util.BitSet inputMask
DOCUMENT ME!
-
secondBuffer
float[] secondBuffer
DOCUMENT ME!
-
xDim
int xDim
DOCUMENT ME!
-
yDim
int yDim
DOCUMENT ME!
-
zDim
int zDim
DOCUMENT ME!
-
baseImage
private ModelImage baseImage
DOCUMENT ME!
-
bin1
private int bin1
DOCUMENT ME!
-
bin2
private int bin2
DOCUMENT ME!
-
bottomPad
private int bottomPad
DOCUMENT ME!
-
cost
private int cost
DOCUMENT ME!
-
count
private int count
DOCUMENT ME!
-
dMax
private double[] dMax
DOCUMENT ME!
-
dMin
private double[] dMin
DOCUMENT ME!
-
doOr
private boolean doOr
If true, or thresholds. If false, and thresholds
-
entireImage
private boolean entireImage
DOCUMENT ME!
-
gaussians
private int gaussians
DOCUMENT ME!
-
halfMajor
private double[] halfMajor
DOCUMENT ME!
-
halfMinor
private double[] halfMinor
DOCUMENT ME!
-
iterations
private int iterations
DOCUMENT ME!
-
leftPad
private int leftPad
Space padding around the histogram data area.
-
mean
private double[][] mean
DOCUMENT ME!
-
meanOld
private double[][] meanOld
DOCUMENT ME!
-
mostProbableClass
private byte[] mostProbableClass
DOCUMENT ME!
-
prob
private double[] prob
DOCUMENT ME!
-
probOld
private double[] probOld
DOCUMENT ME!
-
probX
private double[] probX
DOCUMENT ME!
-
probXOld
private double[] probXOld
DOCUMENT ME!
-
register
private boolean register
DOCUMENT ME!
-
rho
private double[] rho
DOCUMENT ME!
-
rhoOld
private double[] rhoOld
DOCUMENT ME!
-
rightPad
private int rightPad
DOCUMENT ME!
-
segBuffer
private byte[] segBuffer
DOCUMENT ME!
-
segImage
private ModelImage segImage
Displays classes to which pixels belong.
-
std
private double[][] std
DOCUMENT ME!
-
stdOld
private double[][] stdOld
DOCUMENT ME!
-
theta
private double[] theta
DOCUMENT ME!
-
threshold1
private float threshold1
The minimum values that are considered as data values.
-
threshold2
private float threshold2
DOCUMENT ME!
-
topPad
private int topPad
DOCUMENT ME!
-
useBlue
private boolean useBlue
DOCUMENT ME!
-
useGreen
private boolean useGreen
DOCUMENT ME!
-
useRed
private boolean useRed
DOCUMENT ME!
-
-
Constructor Detail
-
AlgorithmColocalizationEM
public AlgorithmColocalizationEM(ModelImage destImg, ModelImage segImage, ModelImage srcImg, ModelImage baseImage, int bin1, int bin2, float threshold1, float threshold2, boolean doOr, int leftPad, int rightPad, int bottomPad, int topPad, boolean entireImage, boolean register, int cost, int gaussians, int iterations)
Constructor for images in which 2D histogram is placed in a predetermined destination image. Used for 2 black and white images- Parameters:
destImg- image model where result image is to storedsegImage- image to display classes to which pixels belongsrcImg- image for x axis of histogrambaseImage- image for y axis of histogrambin1- histogram x axis bin numberbin2- histogram y axis bin numberthreshold1- minimum value for data in sourceImagethreshold2- minimum value for data in baseImagedoOr- If true, or thresholds. If false, and thresholds.leftPad- space to the left of the histogram bin arearightPad- space to the right of the histogram bin areabottomPad- space to the bottom of the histogram bin areatopPad- space to the top of the histogram bin areaentireImage- If false, only use data from VOI regionregister- If true register 2 black and white images before colocalizationcost- Cost function used in registrationgaussians- Number of gaussiansiterations- Number of iterations
-
AlgorithmColocalizationEM
public AlgorithmColocalizationEM(ModelImage destImg, ModelImage segImage, ModelImage srcImg, int bin1, int bin2, float threshold1, float threshold2, boolean doOr, int leftPad, int rightPad, int bottomPad, int topPad, boolean useRed, boolean useGreen, boolean useBlue, boolean entireImage, boolean register, int cost, int gaussians, int iterations)
Constructor for images in which 2D histogram is placed in a predetermined destination image. Used for 1 color image.- Parameters:
destImg- image model where result image is to storedsegImage- image to display classes to which pixels belongsrcImg- source image modelbin1- histogram x axis bin numberbin2- histogram y axis bin numberthreshold1- minimum data value for first colorthreshold2- minimum data value for second colordoOr- If true, or thresholds. If false, and thresholds.leftPad- space to the left of the histogram bin arearightPad- space to the right of the histogram bin areabottomPad- space to the bottom of the histogram bin areatopPad- space to the top of the histogram bin areauseRed- DOCUMENT ME!useGreen- DOCUMENT ME!useBlue- DOCUMENT ME!entireImage- If false, use only data from VOI regionregister- If true, register 2 colors before colocalizationcost- Cost function used in registrationgaussians- Number of gaussiansiterations- Number of iterations
-
-
Method Detail
-
finalize
public void finalize()
Prepares this class for destruction.- Overrides:
finalizein classAlgorithmBase
-
runAlgorithm
public void runAlgorithm()
starts the algorithm.- Specified by:
runAlgorithmin classAlgorithmBase
-
updateFileInfo
public void updateFileInfo(ModelImage image, ModelImage resultImage)
Copy important file information to resultant image structure.- Parameters:
image- Source image.resultImage- Resultant image.
-
calc2D
private void calc2D()
This function produces a 2D histogram image with srcImage values represented across the x axis and baseImage values represented across the y axis.
-
calc3D
private void calc3D()
This function produces a 2D histogram image with srcImage values represented across the x axis and baseImage values represented across the y axis.
-
calcColor2D
private void calcColor2D()
This function produces a 2D histogram image with first color values represented across the x axis and second color values represented across the y axis.
-
calcColor3D
private void calcColor3D()
This function produces a 2D histogram image with first color values represented across the x axis and second color values represented across the y axis.
-
emfunction
private void emfunction()
DOCUMENT ME!
-
getProbX
private void getProbX()
DOCUMENT ME!
-
getProbXOld
private void getProbXOld()
DOCUMENT ME!
-
newToOld
private void newToOld()
DOCUMENT ME!
-
probjxOld
private double probjxOld(int i, int j)DOCUMENT ME!- Parameters:
i- DOCUMENT ME!j- DOCUMENT ME!- Returns:
- DOCUMENT ME!
-
probXj
private double probXj(int i, int j)DOCUMENT ME!- Parameters:
i- DOCUMENT ME!j- DOCUMENT ME!- Returns:
- DOCUMENT ME!
-
probXjOld
private double probXjOld(int i, int j)DOCUMENT ME!- Parameters:
i- DOCUMENT ME!j- DOCUMENT ME!- Returns:
- DOCUMENT ME!
-
-