Class AlgorithmImageCalculator
- java.lang.Object
-
- java.lang.Thread
-
- gov.nih.mipav.model.algorithms.AlgorithmBase
-
- gov.nih.mipav.model.algorithms.utilities.AlgorithmImageCalculator
-
- All Implemented Interfaces:
java.awt.event.ActionListener,java.awt.event.FocusListener,java.awt.event.WindowListener,java.lang.Runnable,java.util.EventListener
public class AlgorithmImageCalculator extends AlgorithmBase implements java.awt.event.ActionListener, java.awt.event.FocusListener
Algorithm that adds, subtracts, multiplies, or divides an image by by another image. In addition, two images can be ANDed, ORed or XORed together. Also, more advanced operator expressions can be entered in a dialog text field.- Version:
- 1.0 Oct 1, 2000
- Author:
- Matthew J. McAuliffe, Ph.D.
-
-
Field Summary
Fields Modifier and Type Field Description private javax.swing.JButtonabsButtonDOCUMENT ME!private javax.swing.JButtonaButtonDOCUMENT ME!static intADDDOCUMENT ME!private javax.swing.JButtonaddButtonDOCUMENT ME!private javax.swing.JDialogadOpDialogDOCUMENT ME!private java.lang.StringadOpStringDOCUMENT ME!static intADVANCEDDOCUMENT ME!static intANDDOCUMENT ME!private doubleaValDOCUMENT ME!static intAVERAGEDOCUMENT ME!static intAVGERAGE_WITH_STDEVprivate javax.swing.JButtonbackSpaceButtonDOCUMENT ME!private javax.swing.JButtonbButtonDOCUMENT ME!private doublebestMax/**.private doublebestMin/**.private doublebValDOCUMENT ME!private booleancancelDOCUMENT ME!private javax.swing.JButtoncancelButtonDOCUMENT ME!private javax.swing.JButtonceButtonDOCUMENT ME!static intCLIPDOCUMENT ME!private doubleclipMaxMinimum and maximum clipping modes.private doubleclipMinMinimum and maximum clipping modes.private intclipModeClipping mode.private intcolorFactorDOCUMENT ME!private javax.swing.JButtoncommaButtonDOCUMENT ME!private javax.swing.JButtoncosButtonDOCUMENT ME!private javax.swing.JButtondecimalButtonDOCUMENT ME!static intDIFFERENCEDOCUMENT ME!private javax.swing.JButtondivButtonDOCUMENT ME!static intDIVIDEDOCUMENT ME!private javax.swing.JButtoneightButtonDOCUMENT ME!private booleanentireImageFlag, if true, indicates that the whole image should be processed.private javax.swing.JButtonexpButtonDOCUMENT ME!private javax.swing.JButtonfiveButtonDOCUMENT ME!private javax.swing.JButtonfourButtonDOCUMENT ME!private javax.swing.JButtonleftParButtonDOCUMENT ME!private javax.swing.JButtonlnButtonDOCUMENT ME!private javax.swing.JButtonlogButtonDOCUMENT ME!private doublemaxA/**.private doublemaxABDOCUMENT ME!private doublemaxAGDOCUMENT ME!private doublemaxARDOCUMENT ME!private doublemaxB/**.private doublemaxBBDOCUMENT ME!private doublemaxBGDOCUMENT ME!private doublemaxBRDOCUMENT ME!static intMAXIMUMDOCUMENT ME!static intMEAN_SQUARED_ERRORprivate doubleminA/**.private doubleminABDOCUMENT ME!private doubleminAGDOCUMENT ME!private doubleminARDOCUMENT ME!private doubleminB/**.private doubleminBBDOCUMENT ME!private doubleminBGDOCUMENT ME!private doubleminBRDOCUMENT ME!static intMINIMUMDOCUMENT ME!private javax.swing.JButtonmodButtonDOCUMENT ME!private javax.swing.JButtonmultButtonDOCUMENT ME!static intMULTIPLYDOCUMENT ME!private javax.swing.JButtonnineButtonDOCUMENT ME!private booleanOKDOCUMENT ME!private javax.swing.JButtonOKButtonDOCUMENT ME!private javax.swing.JButtononeButtonDOCUMENT ME!private intopTypeOperation to be performed on the images (i.e.static intORDOCUMENT ME!private javax.swing.JButtonpiButtonDOCUMENT ME!private javax.swing.JButtonpowButtonDOCUMENT ME!private booleanpressedOKDOCUMENT ME!static intPROMOTEDOCUMENT ME!private javax.swing.JButtonrightParButtonDOCUMENT ME!private java.lang.Stringrpnprivate javax.swing.JButtonsevenButtonDOCUMENT ME!private javax.swing.JButtonsinButtonDOCUMENT ME!private javax.swing.JButtonsixButtonDOCUMENT ME!private ModelImagesrcImageASource image A.private ModelImagesrcImageBSource image B.private ModelImage[]srcImageswhen performing bulk operations via Image Calculator (Bulk Images) dialog, this array is populatedprivate javax.swing.JButtonsubButtonDOCUMENT ME!static intSUBTRACTDOCUMENT ME!private javax.swing.JButtontanButtonDOCUMENT ME!private javax.swing.JTextFieldtextOperatorDOCUMENT ME!private javax.swing.JButtonthreeButtonDOCUMENT ME!private javax.swing.JButtontwoButtonDOCUMENT ME!static intXORDOCUMENT ME!private javax.swing.JButtonzeroButtonDOCUMENT 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 AlgorithmImageCalculator(ModelImage destImage, ModelImage[] srcImages, int opType, int clipMode)constructor used for bulk imagesAlgorithmImageCalculator(ModelImage srcImgA, ModelImage srcImgB, int type, int _clipMode, boolean maskFlag, java.lang.String adOpString)Creates a new AlgorithmImageCalculator object using srcImgAsrcImgB. AlgorithmImageCalculator(ModelImage destImg, ModelImage srcImgA, ModelImage srcImgB, int type, int _clipMode, boolean maskFlag, java.lang.String adOpString)Creates a new AlgorithmImageCalculator object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidactionPerformed(java.awt.event.ActionEvent event)Calls various methods depending on the action used by the advanced calculator.private voidcalcInPlace()Runs the calculation and stores the result into the same source buffer.private voidcalcMSE()private voidcalcStoreInDest()Runs the calculation and stores it in a new ModelImage.java.lang.StringconvertToRPN(java.util.Vector<java.lang.String> tokens)method that converts the tokens to RPNprivate voidcreateAdOpDialog(java.awt.event.ActionListener al)Builds the advanced function dialog - looks like a calculator.doubleevaluateRPNExpression(double a, double b, java.lang.String rpn)Method that evaluates the RPN expression and returns the valuejava.lang.StringevaluateToRPN(java.lang.String expression)method that determines the RPNvoidfinalize()Prepares this class for destruction.private intfindType(int stType)Find the type able to contain the full range of the data.voidfocusGained(java.awt.event.FocusEvent event)Unchanged.voidfocusLost(java.awt.event.FocusEvent event)Unchanged.java.lang.StringgetAdvFunction()Accessor to return the advanced function string.booleaninitialValidate(java.lang.String expression)method that does some initial validation of the expressionbooleanisDigit(char c)determines if char is a digitbooleanisFunction(java.lang.String token)method determining if token is functionbooleanisOperator(java.lang.String token)method determining if token is an operatorbooleanisValidNumber(java.lang.String s)private voidperformBulkAdding()perform bulk adidngprivate voidperformBulkAveraging(boolean findSD)perform bulk averagingprivate voidperformBulkMax()perform bulk adidngprivate voidperformBulkMin()perform bulk adidngintprecedence(java.lang.String op)method that determines precedenceprivate intpromoteType(int presentType)DOCUMENT ME!charreadChar(java.lang.String exp, int pos)reads charvoidrunAlgorithm()Starts the program.private voidsetClipValues()Sets the minimum and maximum clipping values.private booleantestType(int type, double minVal, double maxVal)Determine if the min and max values are in the image types range.booleantokenize(java.lang.String expression, java.util.Vector<java.lang.String> tokens)method that tokenizes the expression-
Methods inherited from class gov.nih.mipav.model.algorithms.AlgorithmBase
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
-
ADD
public static final int ADD
DOCUMENT ME!- See Also:
- Constant Field Values
-
ADVANCED
public static final int ADVANCED
DOCUMENT ME!- See Also:
- Constant Field Values
-
AND
public static final int AND
DOCUMENT ME!- See Also:
- Constant Field Values
-
AVERAGE
public static final int AVERAGE
DOCUMENT ME!- See Also:
- Constant Field Values
-
DIFFERENCE
public static final int DIFFERENCE
DOCUMENT ME!- See Also:
- Constant Field Values
-
DIVIDE
public static final int DIVIDE
DOCUMENT ME!- See Also:
- Constant Field Values
-
MAXIMUM
public static final int MAXIMUM
DOCUMENT ME!- See Also:
- Constant Field Values
-
MEAN_SQUARED_ERROR
public static final int MEAN_SQUARED_ERROR
- See Also:
- Constant Field Values
-
MINIMUM
public static final int MINIMUM
DOCUMENT ME!- See Also:
- Constant Field Values
-
MULTIPLY
public static final int MULTIPLY
DOCUMENT ME!- See Also:
- Constant Field Values
-
OR
public static final int OR
DOCUMENT ME!- See Also:
- Constant Field Values
-
SUBTRACT
public static final int SUBTRACT
DOCUMENT ME!- See Also:
- Constant Field Values
-
XOR
public static final int XOR
DOCUMENT ME!- See Also:
- Constant Field Values
-
AVGERAGE_WITH_STDEV
public static final int AVGERAGE_WITH_STDEV
- See Also:
- Constant Field Values
-
CLIP
public static final int CLIP
DOCUMENT ME!- See Also:
- Constant Field Values
-
PROMOTE
public static final int PROMOTE
DOCUMENT ME!- See Also:
- Constant Field Values
-
aButton
private javax.swing.JButton aButton
DOCUMENT ME!
-
bButton
private javax.swing.JButton bButton
DOCUMENT ME!
-
backSpaceButton
private javax.swing.JButton backSpaceButton
DOCUMENT ME!
-
ceButton
private javax.swing.JButton ceButton
DOCUMENT ME!
-
leftParButton
private javax.swing.JButton leftParButton
DOCUMENT ME!
-
rightParButton
private javax.swing.JButton rightParButton
DOCUMENT ME!
-
adOpDialog
private javax.swing.JDialog adOpDialog
DOCUMENT ME!
-
adOpString
private java.lang.String adOpString
DOCUMENT ME!
-
aVal
private double aVal
DOCUMENT ME!
-
bestMin
private double bestMin
/**.
-
bestMax
private double bestMax
/**.
-
bVal
private double bVal
DOCUMENT ME!
-
cancel
private boolean cancel
DOCUMENT ME!
-
clipMin
private double clipMin
Minimum and maximum clipping modes.
-
clipMax
private double clipMax
Minimum and maximum clipping modes.
-
clipMode
private int clipMode
Clipping mode.CLIP = 0; clamp result data to the bounds of the input image type PROMOTE = 1; promote image type so that the range of the result fits into the new image type. ( ie. byte to short).
-
colorFactor
private int colorFactor
DOCUMENT ME!
-
entireImage
private boolean entireImage
Flag, if true, indicates that the whole image should be processed. If false, process the image over the mask areas.
-
expButton
private javax.swing.JButton expButton
DOCUMENT ME!
-
lnButton
private javax.swing.JButton lnButton
DOCUMENT ME!
-
sevenButton
private javax.swing.JButton sevenButton
DOCUMENT ME!
-
eightButton
private javax.swing.JButton eightButton
DOCUMENT ME!
-
nineButton
private javax.swing.JButton nineButton
DOCUMENT ME!
-
divButton
private javax.swing.JButton divButton
DOCUMENT ME!
-
logButton
private javax.swing.JButton logButton
DOCUMENT ME!
-
absButton
private javax.swing.JButton absButton
DOCUMENT ME!
-
minA
private double minA
/**.
-
maxA
private double maxA
/**.
-
minB
private double minB
/**.
-
maxB
private double maxB
/**.
-
minAB
private double minAB
DOCUMENT ME!
-
maxAB
private double maxAB
DOCUMENT ME!
-
minBB
private double minBB
DOCUMENT ME!
-
maxBB
private double maxBB
DOCUMENT ME!
-
minAG
private double minAG
DOCUMENT ME!
-
maxAG
private double maxAG
DOCUMENT ME!
-
minBG
private double minBG
DOCUMENT ME!
-
maxBG
private double maxBG
DOCUMENT ME!
-
minAR
private double minAR
DOCUMENT ME!
-
maxAR
private double maxAR
DOCUMENT ME!
-
minBR
private double minBR
DOCUMENT ME!
-
maxBR
private double maxBR
DOCUMENT ME!
-
OK
private boolean OK
DOCUMENT ME!
-
OKButton
private javax.swing.JButton OKButton
DOCUMENT ME!
-
cancelButton
private javax.swing.JButton cancelButton
DOCUMENT ME!
-
opType
private int opType
Operation to be performed on the images (i.e. Add, ...)
-
powButton
private javax.swing.JButton powButton
DOCUMENT ME!
-
commaButton
private javax.swing.JButton commaButton
DOCUMENT ME!
-
fourButton
private javax.swing.JButton fourButton
DOCUMENT ME!
-
fiveButton
private javax.swing.JButton fiveButton
DOCUMENT ME!
-
sixButton
private javax.swing.JButton sixButton
DOCUMENT ME!
-
multButton
private javax.swing.JButton multButton
DOCUMENT ME!
-
pressedOK
private boolean pressedOK
DOCUMENT ME!
-
sinButton
private javax.swing.JButton sinButton
DOCUMENT ME!
-
cosButton
private javax.swing.JButton cosButton
DOCUMENT ME!
-
oneButton
private javax.swing.JButton oneButton
DOCUMENT ME!
-
twoButton
private javax.swing.JButton twoButton
DOCUMENT ME!
-
threeButton
private javax.swing.JButton threeButton
DOCUMENT ME!
-
subButton
private javax.swing.JButton subButton
DOCUMENT ME!
-
srcImageA
private ModelImage srcImageA
Source image A.
-
srcImageB
private ModelImage srcImageB
Source image B.
-
tanButton
private javax.swing.JButton tanButton
DOCUMENT ME!
-
piButton
private javax.swing.JButton piButton
DOCUMENT ME!
-
zeroButton
private javax.swing.JButton zeroButton
DOCUMENT ME!
-
decimalButton
private javax.swing.JButton decimalButton
DOCUMENT ME!
-
modButton
private javax.swing.JButton modButton
DOCUMENT ME!
-
addButton
private javax.swing.JButton addButton
DOCUMENT ME!
-
textOperator
private javax.swing.JTextField textOperator
DOCUMENT ME!
-
srcImages
private ModelImage[] srcImages
when performing bulk operations via Image Calculator (Bulk Images) dialog, this array is populated
-
rpn
private java.lang.String rpn
-
-
Constructor Detail
-
AlgorithmImageCalculator
public AlgorithmImageCalculator(ModelImage srcImgA, ModelImage srcImgB, int type, int _clipMode, boolean maskFlag, java.lang.String adOpString)
Creates a new AlgorithmImageCalculator object using srcImgAsrcImgB. - Parameters:
srcImgA- source image A modelsrcImgB- source image B modeltype- operation type_clipMode- CLIP or PROMOTE input image datamaskFlag- Flag that indicates that the operator will be calculated for the whole image if equal to trueadOpString- text for advanced operations
-
AlgorithmImageCalculator
public AlgorithmImageCalculator(ModelImage destImg, ModelImage srcImgA, ModelImage srcImgB, int type, int _clipMode, boolean maskFlag, java.lang.String adOpString)
Creates a new AlgorithmImageCalculator object.- Parameters:
destImg- image model where result image is to storedsrcImgA- source image A modelsrcImgB- source image B modeltype- operation type_clipMode- CLIP or PROMOTE input image datamaskFlag- Flag that indicates that the operator will be calculated for the whole image if equal to trueadOpString- text for advanced operations
-
AlgorithmImageCalculator
public AlgorithmImageCalculator(ModelImage destImage, ModelImage[] srcImages, int opType, int clipMode)
constructor used for bulk images- Parameters:
destImage-srcImages-opType-clipMode-
-
-
Method Detail
-
actionPerformed
public void actionPerformed(java.awt.event.ActionEvent event)
Calls various methods depending on the action used by the advanced calculator.- Specified by:
actionPerformedin interfacejava.awt.event.ActionListener- Overrides:
actionPerformedin classAlgorithmBase- Parameters:
event- event that triggered function
-
finalize
public void finalize()
Prepares this class for destruction.- Overrides:
finalizein classAlgorithmBase
-
focusGained
public void focusGained(java.awt.event.FocusEvent event)
Unchanged.- Specified by:
focusGainedin interfacejava.awt.event.FocusListener- Parameters:
event- DOCUMENT ME!
-
focusLost
public void focusLost(java.awt.event.FocusEvent event)
Unchanged.- Specified by:
focusLostin interfacejava.awt.event.FocusListener- Parameters:
event- DOCUMENT ME!
-
getAdvFunction
public java.lang.String getAdvFunction()
Accessor to return the advanced function string.- Returns:
- adOpString advanced function string
-
runAlgorithm
public void runAlgorithm()
Starts the program.- Specified by:
runAlgorithmin classAlgorithmBase
-
calcMSE
private void calcMSE()
-
calcInPlace
private void calcInPlace()
Runs the calculation and stores the result into the same source buffer.
-
performBulkAdding
private void performBulkAdding()
perform bulk adidng
-
performBulkMin
private void performBulkMin()
perform bulk adidng
-
performBulkMax
private void performBulkMax()
perform bulk adidng
-
performBulkAveraging
private void performBulkAveraging(boolean findSD)
perform bulk averaging
-
calcStoreInDest
private void calcStoreInDest()
Runs the calculation and stores it in a new ModelImage.
-
createAdOpDialog
private void createAdOpDialog(java.awt.event.ActionListener al)
Builds the advanced function dialog - looks like a calculator.- Parameters:
al- DOCUMENT ME!
-
evaluateRPNExpression
public double evaluateRPNExpression(double a, double b, java.lang.String rpn)Method that evaluates the RPN expression and returns the value
-
evaluateToRPN
public java.lang.String evaluateToRPN(java.lang.String expression)
method that determines the RPN- Parameters:
expression-- Returns:
-
initialValidate
public boolean initialValidate(java.lang.String expression)
method that does some initial validation of the expression- Parameters:
expression-- Returns:
-
tokenize
public boolean tokenize(java.lang.String expression, java.util.Vector<java.lang.String> tokens)method that tokenizes the expression- Parameters:
expression-tokens-- Returns:
-
convertToRPN
public java.lang.String convertToRPN(java.util.Vector<java.lang.String> tokens)
method that converts the tokens to RPN- Parameters:
tokens-- Returns:
-
precedence
public int precedence(java.lang.String op)
method that determines precedence- Parameters:
op-- Returns:
-
isOperator
public boolean isOperator(java.lang.String token)
method determining if token is an operator- Parameters:
token-- Returns:
-
isFunction
public boolean isFunction(java.lang.String token)
method determining if token is function- Parameters:
token-- Returns:
-
readChar
public char readChar(java.lang.String exp, int pos)reads char- Parameters:
exp-pos-- Returns:
-
isDigit
public boolean isDigit(char c)
determines if char is a digit- Parameters:
c-- Returns:
-
isValidNumber
public boolean isValidNumber(java.lang.String s)
-
findType
private int findType(int stType)
Find the type able to contain the full range of the data.- Parameters:
stType- starting type of image. Image will be promoted above this type if needed.- Returns:
- type capable of storing full range of data. See ModelStorageBase for image types.
-
promoteType
private int promoteType(int presentType)
DOCUMENT ME!- Parameters:
presentType- DOCUMENT ME!- Returns:
- DOCUMENT ME!
-
setClipValues
private void setClipValues()
Sets the minimum and maximum clipping values.
-
testType
private boolean testType(int type, double minVal, double maxVal)Determine if the min and max values are in the image types range.- Parameters:
type- image typeminVal- min value of the imagemaxVal- max value of the image- Returns:
- true if min and max are within the image type specified
-
-