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.JButton
absButton
DOCUMENT ME!private javax.swing.JButton
aButton
DOCUMENT ME!static int
ADD
DOCUMENT ME!private javax.swing.JButton
addButton
DOCUMENT ME!private javax.swing.JDialog
adOpDialog
DOCUMENT ME!private java.lang.String
adOpString
DOCUMENT ME!static int
ADVANCED
DOCUMENT ME!static int
AND
DOCUMENT ME!private double
aVal
DOCUMENT ME!static int
AVERAGE
DOCUMENT ME!static int
AVGERAGE_WITH_STDEV
private javax.swing.JButton
backSpaceButton
DOCUMENT ME!private javax.swing.JButton
bButton
DOCUMENT ME!private double
bestMax
/**.private double
bestMin
/**.private double
bVal
DOCUMENT ME!private boolean
cancel
DOCUMENT ME!private javax.swing.JButton
cancelButton
DOCUMENT ME!private javax.swing.JButton
ceButton
DOCUMENT ME!static int
CLIP
DOCUMENT ME!private double
clipMax
Minimum and maximum clipping modes.private double
clipMin
Minimum and maximum clipping modes.private int
clipMode
Clipping mode.private int
colorFactor
DOCUMENT ME!private javax.swing.JButton
commaButton
DOCUMENT ME!private javax.swing.JButton
cosButton
DOCUMENT ME!private javax.swing.JButton
decimalButton
DOCUMENT ME!static int
DIFFERENCE
DOCUMENT ME!private javax.swing.JButton
divButton
DOCUMENT ME!static int
DIVIDE
DOCUMENT ME!private javax.swing.JButton
eightButton
DOCUMENT ME!private boolean
entireImage
Flag, if true, indicates that the whole image should be processed.private javax.swing.JButton
expButton
DOCUMENT ME!private javax.swing.JButton
fiveButton
DOCUMENT ME!private javax.swing.JButton
fourButton
DOCUMENT ME!private javax.swing.JButton
leftParButton
DOCUMENT ME!private javax.swing.JButton
lnButton
DOCUMENT ME!private javax.swing.JButton
logButton
DOCUMENT ME!private double
maxA
/**.private double
maxAB
DOCUMENT ME!private double
maxAG
DOCUMENT ME!private double
maxAR
DOCUMENT ME!private double
maxB
/**.private double
maxBB
DOCUMENT ME!private double
maxBG
DOCUMENT ME!private double
maxBR
DOCUMENT ME!static int
MAXIMUM
DOCUMENT ME!static int
MEAN_SQUARED_ERROR
private double
minA
/**.private double
minAB
DOCUMENT ME!private double
minAG
DOCUMENT ME!private double
minAR
DOCUMENT ME!private double
minB
/**.private double
minBB
DOCUMENT ME!private double
minBG
DOCUMENT ME!private double
minBR
DOCUMENT ME!static int
MINIMUM
DOCUMENT ME!private javax.swing.JButton
modButton
DOCUMENT ME!private javax.swing.JButton
multButton
DOCUMENT ME!static int
MULTIPLY
DOCUMENT ME!private javax.swing.JButton
nineButton
DOCUMENT ME!private boolean
OK
DOCUMENT ME!private javax.swing.JButton
OKButton
DOCUMENT ME!private javax.swing.JButton
oneButton
DOCUMENT ME!private int
opType
Operation to be performed on the images (i.e.static int
OR
DOCUMENT ME!private javax.swing.JButton
piButton
DOCUMENT ME!private javax.swing.JButton
powButton
DOCUMENT ME!private boolean
pressedOK
DOCUMENT ME!static int
PROMOTE
DOCUMENT ME!private javax.swing.JButton
rightParButton
DOCUMENT ME!private java.lang.String
rpn
private javax.swing.JButton
sevenButton
DOCUMENT ME!private javax.swing.JButton
sinButton
DOCUMENT ME!private javax.swing.JButton
sixButton
DOCUMENT ME!private ModelImage
srcImageA
Source image A.private ModelImage
srcImageB
Source image B.private ModelImage[]
srcImages
when performing bulk operations via Image Calculator (Bulk Images) dialog, this array is populatedprivate javax.swing.JButton
subButton
DOCUMENT ME!static int
SUBTRACT
DOCUMENT ME!private javax.swing.JButton
tanButton
DOCUMENT ME!private javax.swing.JTextField
textOperator
DOCUMENT ME!private javax.swing.JButton
threeButton
DOCUMENT ME!private javax.swing.JButton
twoButton
DOCUMENT ME!static int
XOR
DOCUMENT ME!private javax.swing.JButton
zeroButton
DOCUMENT 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 void
actionPerformed(java.awt.event.ActionEvent event)
Calls various methods depending on the action used by the advanced calculator.private void
calcInPlace()
Runs the calculation and stores the result into the same source buffer.private void
calcMSE()
private void
calcStoreInDest()
Runs the calculation and stores it in a new ModelImage.java.lang.String
convertToRPN(java.util.Vector<java.lang.String> tokens)
method that converts the tokens to RPNprivate void
createAdOpDialog(java.awt.event.ActionListener al)
Builds the advanced function dialog - looks like a calculator.double
evaluateRPNExpression(double a, double b, java.lang.String rpn)
Method that evaluates the RPN expression and returns the valuejava.lang.String
evaluateToRPN(java.lang.String expression)
method that determines the RPNvoid
finalize()
Prepares this class for destruction.private int
findType(int stType)
Find the type able to contain the full range of the data.void
focusGained(java.awt.event.FocusEvent event)
Unchanged.void
focusLost(java.awt.event.FocusEvent event)
Unchanged.java.lang.String
getAdvFunction()
Accessor to return the advanced function string.boolean
initialValidate(java.lang.String expression)
method that does some initial validation of the expressionboolean
isDigit(char c)
determines if char is a digitboolean
isFunction(java.lang.String token)
method determining if token is functionboolean
isOperator(java.lang.String token)
method determining if token is an operatorboolean
isValidNumber(java.lang.String s)
private void
performBulkAdding()
perform bulk adidngprivate void
performBulkAveraging(boolean findSD)
perform bulk averagingprivate void
performBulkMax()
perform bulk adidngprivate void
performBulkMin()
perform bulk adidngint
precedence(java.lang.String op)
method that determines precedenceprivate int
promoteType(int presentType)
DOCUMENT ME!char
readChar(java.lang.String exp, int pos)
reads charvoid
runAlgorithm()
Starts the program.private void
setClipValues()
Sets the minimum and maximum clipping values.private boolean
testType(int type, double minVal, double maxVal)
Determine if the min and max values are in the image types range.boolean
tokenize(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:
actionPerformed
in interfacejava.awt.event.ActionListener
- Overrides:
actionPerformed
in classAlgorithmBase
- Parameters:
event
- event that triggered function
-
finalize
public void finalize()
Prepares this class for destruction.- Overrides:
finalize
in classAlgorithmBase
-
focusGained
public void focusGained(java.awt.event.FocusEvent event)
Unchanged.- Specified by:
focusGained
in interfacejava.awt.event.FocusListener
- Parameters:
event
- DOCUMENT ME!
-
focusLost
public void focusLost(java.awt.event.FocusEvent event)
Unchanged.- Specified by:
focusLost
in 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:
runAlgorithm
in 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
-
-