Class AlgorithmImageCalculator
java.lang.Object
java.lang.Thread
gov.nih.mipav.model.algorithms.AlgorithmBase
gov.nih.mipav.model.algorithms.utilities.AlgorithmImageCalculator
- All Implemented Interfaces:
ActionListener,FocusListener,WindowListener,Runnable,EventListener
public class AlgorithmImageCalculator
extends AlgorithmBase
implements ActionListener, 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.
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Thread
Thread.Builder, Thread.State, Thread.UncaughtExceptionHandler -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate JButtonDOCUMENT ME!private JButtonDOCUMENT ME!static final intDOCUMENT ME!private JButtonDOCUMENT ME!private JDialogDOCUMENT ME!private StringDOCUMENT ME!static final intDOCUMENT ME!static final intDOCUMENT ME!private doubleDOCUMENT ME!static final intDOCUMENT ME!static final intprivate JButtonDOCUMENT ME!private JButtonDOCUMENT ME!private double/**.private double/**.private doubleDOCUMENT ME!private booleanDOCUMENT ME!private JButtonDOCUMENT ME!private JButtonDOCUMENT ME!static final intDOCUMENT ME!private doubleMinimum and maximum clipping modes.private doubleMinimum and maximum clipping modes.private intClipping mode.private intDOCUMENT ME!private JButtonDOCUMENT ME!private JButtonDOCUMENT ME!private JButtonDOCUMENT ME!static final intDOCUMENT ME!private JButtonDOCUMENT ME!static final intDOCUMENT ME!private JButtonDOCUMENT ME!private booleanFlag, if true, indicates that the whole image should be processed.private JButtonDOCUMENT ME!private JButtonDOCUMENT ME!private JButtonDOCUMENT ME!private JButtonDOCUMENT ME!private JButtonDOCUMENT ME!private JButtonDOCUMENT ME!private double/**.private doubleDOCUMENT ME!private doubleDOCUMENT ME!private doubleDOCUMENT ME!private double/**.private doubleDOCUMENT ME!private doubleDOCUMENT ME!private doubleDOCUMENT ME!static final intDOCUMENT ME!static final intprivate double/**.private doubleDOCUMENT ME!private doubleDOCUMENT ME!private doubleDOCUMENT ME!private double/**.private doubleDOCUMENT ME!private doubleDOCUMENT ME!private doubleDOCUMENT ME!static final intDOCUMENT ME!private JButtonDOCUMENT ME!private JButtonDOCUMENT ME!static final intDOCUMENT ME!private JButtonDOCUMENT ME!private booleanDOCUMENT ME!private JButtonDOCUMENT ME!private JButtonDOCUMENT ME!private intOperation to be performed on the images (i.e.static final intDOCUMENT ME!private JButtonDOCUMENT ME!private JButtonDOCUMENT ME!private booleanDOCUMENT ME!static final intDOCUMENT ME!private JButtonDOCUMENT ME!private Stringprivate JButtonDOCUMENT ME!private JButtonDOCUMENT ME!private JButtonDOCUMENT ME!private ModelImageSource image A.private ModelImageSource image B.private ModelImage[]when performing bulk operations via Image Calculator (Bulk Images) dialog, this array is populatedprivate JButtonDOCUMENT ME!static final intDOCUMENT ME!private JButtonDOCUMENT ME!private JTextFieldDOCUMENT ME!private JButtonDOCUMENT ME!private JButtonDOCUMENT ME!static final intDOCUMENT ME!private JButtonDOCUMENT 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, threadStoppedFields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY -
Constructor Summary
ConstructorsConstructorDescriptionAlgorithmImageCalculator(ModelImage destImage, ModelImage[] srcImages, int opType, int clipMode) constructor used for bulk imagesAlgorithmImageCalculator(ModelImage srcImgA, ModelImage srcImgB, int type, int _clipMode, boolean maskFlag, String adOpString) Creates a new AlgorithmImageCalculator object using srcImgAsrcImgB. AlgorithmImageCalculator(ModelImage destImg, ModelImage srcImgA, ModelImage srcImgB, int type, int _clipMode, boolean maskFlag, String adOpString) Creates a new AlgorithmImageCalculator object. -
Method Summary
Modifier and TypeMethodDescriptionvoidactionPerformed(ActionEvent event) Calls various methods depending on the action used by the advanced calculator.private voidRuns the calculation and stores the result into the same source buffer.private voidcalcMSE()private voidRuns the calculation and stores it in a new ModelImage.convertToRPN(Vector<String> tokens) method that converts the tokens to RPNprivate voidBuilds the advanced function dialog - looks like a calculator.doubleevaluateRPNExpression(double a, double b, String rpn) Method that evaluates the RPN expression and returns the valueevaluateToRPN(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(FocusEvent event) Unchanged.voidfocusLost(FocusEvent event) Unchanged.Accessor to return the advanced function string.booleaninitialValidate(String expression) method that does some initial validation of the expressionbooleanisDigit(char c) determines if char is a digitbooleanisFunction(String token) method determining if token is functionbooleanisOperator(String token) method determining if token is an operatorbooleanprivate voidperform bulk adidngprivate voidperformBulkAveraging(boolean findSD) perform bulk averagingprivate voidperform bulk adidngprivate voidperform bulk adidngintprecedence(String op) method that determines precedenceprivate intpromoteType(int presentType) DOCUMENT ME!charreads charvoidStarts the program.private voidSets 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.booleanmethod that tokenizes the expressionMethods 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, 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
-
ADD
public static final int ADDDOCUMENT ME!- See Also:
-
ADVANCED
public static final int ADVANCEDDOCUMENT ME!- See Also:
-
AND
public static final int ANDDOCUMENT ME!- See Also:
-
AVERAGE
public static final int AVERAGEDOCUMENT ME!- See Also:
-
DIFFERENCE
public static final int DIFFERENCEDOCUMENT ME!- See Also:
-
DIVIDE
public static final int DIVIDEDOCUMENT ME!- See Also:
-
MAXIMUM
public static final int MAXIMUMDOCUMENT ME!- See Also:
-
MEAN_SQUARED_ERROR
public static final int MEAN_SQUARED_ERROR- See Also:
-
MINIMUM
public static final int MINIMUMDOCUMENT ME!- See Also:
-
MULTIPLY
public static final int MULTIPLYDOCUMENT ME!- See Also:
-
OR
public static final int ORDOCUMENT ME!- See Also:
-
SUBTRACT
public static final int SUBTRACTDOCUMENT ME!- See Also:
-
XOR
public static final int XORDOCUMENT ME!- See Also:
-
AVGERAGE_WITH_STDEV
public static final int AVGERAGE_WITH_STDEV- See Also:
-
CLIP
public static final int CLIPDOCUMENT ME!- See Also:
-
PROMOTE
public static final int PROMOTEDOCUMENT ME!- See Also:
-
aButton
DOCUMENT ME! -
bButton
DOCUMENT ME! -
backSpaceButton
DOCUMENT ME! -
ceButton
DOCUMENT ME! -
leftParButton
DOCUMENT ME! -
rightParButton
DOCUMENT ME! -
adOpDialog
DOCUMENT ME! -
adOpString
DOCUMENT ME! -
aVal
private double aValDOCUMENT ME! -
bestMin
private double bestMin/**. -
bestMax
private double bestMax/**. -
bVal
private double bValDOCUMENT ME! -
cancel
private boolean cancelDOCUMENT ME! -
clipMin
private double clipMinMinimum and maximum clipping modes. -
clipMax
private double clipMaxMinimum and maximum clipping modes. -
clipMode
private int clipModeClipping 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 colorFactorDOCUMENT ME! -
entireImage
private boolean entireImageFlag, if true, indicates that the whole image should be processed. If false, process the image over the mask areas. -
expButton
DOCUMENT ME! -
lnButton
DOCUMENT ME! -
sevenButton
DOCUMENT ME! -
eightButton
DOCUMENT ME! -
nineButton
DOCUMENT ME! -
divButton
DOCUMENT ME! -
logButton
DOCUMENT ME! -
absButton
DOCUMENT ME! -
minA
private double minA/**. -
maxA
private double maxA/**. -
minB
private double minB/**. -
maxB
private double maxB/**. -
minAB
private double minABDOCUMENT ME! -
maxAB
private double maxABDOCUMENT ME! -
minBB
private double minBBDOCUMENT ME! -
maxBB
private double maxBBDOCUMENT ME! -
minAG
private double minAGDOCUMENT ME! -
maxAG
private double maxAGDOCUMENT ME! -
minBG
private double minBGDOCUMENT ME! -
maxBG
private double maxBGDOCUMENT ME! -
minAR
private double minARDOCUMENT ME! -
maxAR
private double maxARDOCUMENT ME! -
minBR
private double minBRDOCUMENT ME! -
maxBR
private double maxBRDOCUMENT ME! -
OK
private boolean OKDOCUMENT ME! -
OKButton
DOCUMENT ME! -
cancelButton
DOCUMENT ME! -
opType
private int opTypeOperation to be performed on the images (i.e. Add, ...) -
powButton
DOCUMENT ME! -
commaButton
DOCUMENT ME! -
fourButton
DOCUMENT ME! -
fiveButton
DOCUMENT ME! -
sixButton
DOCUMENT ME! -
multButton
DOCUMENT ME! -
pressedOK
private boolean pressedOKDOCUMENT ME! -
sinButton
DOCUMENT ME! -
cosButton
DOCUMENT ME! -
oneButton
DOCUMENT ME! -
twoButton
DOCUMENT ME! -
threeButton
DOCUMENT ME! -
subButton
DOCUMENT ME! -
srcImageA
Source image A. -
srcImageB
Source image B. -
tanButton
DOCUMENT ME! -
piButton
DOCUMENT ME! -
zeroButton
DOCUMENT ME! -
decimalButton
DOCUMENT ME! -
modButton
DOCUMENT ME! -
addButton
DOCUMENT ME! -
textOperator
DOCUMENT ME! -
srcImages
when performing bulk operations via Image Calculator (Bulk Images) dialog, this array is populated -
rpn
-
-
Constructor Details
-
AlgorithmImageCalculator
public AlgorithmImageCalculator(ModelImage srcImgA, ModelImage srcImgB, int type, int _clipMode, boolean maskFlag, 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, 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 Details
-
actionPerformed
Calls various methods depending on the action used by the advanced calculator.- Specified by:
actionPerformedin interfaceActionListener- Overrides:
actionPerformedin classAlgorithmBase- Parameters:
event- event that triggered function
-
finalize
public void finalize()Prepares this class for destruction.- Overrides:
finalizein classAlgorithmBase
-
focusGained
Unchanged.- Specified by:
focusGainedin interfaceFocusListener- Parameters:
event- DOCUMENT ME!
-
focusLost
Unchanged.- Specified by:
focusLostin interfaceFocusListener- Parameters:
event- DOCUMENT ME!
-
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
Builds the advanced function dialog - looks like a calculator.- Parameters:
al- DOCUMENT ME!
-
evaluateRPNExpression
Method that evaluates the RPN expression and returns the value -
evaluateToRPN
method that determines the RPN- Parameters:
expression-- Returns:
-
initialValidate
method that does some initial validation of the expression- Parameters:
expression-- Returns:
-
tokenize
method that tokenizes the expression- Parameters:
expression-tokens-- Returns:
-
convertToRPN
method that converts the tokens to RPN- Parameters:
tokens-- Returns:
-
precedence
method that determines precedence- Parameters:
op-- Returns:
-
isOperator
method determining if token is an operator- Parameters:
token-- Returns:
-
isFunction
method determining if token is function- Parameters:
token-- Returns:
-
readChar
reads char- Parameters:
exp-pos-- Returns:
-
isDigit
public boolean isDigit(char c) determines if char is a digit- Parameters:
c-- Returns:
-
isValidNumber
-
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
-