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.
  • Field Details

    • ADD

      public static final int ADD
      DOCUMENT ME!
      See Also:
    • ADVANCED

      public static final int ADVANCED
      DOCUMENT ME!
      See Also:
    • AND

      public static final int AND
      DOCUMENT ME!
      See Also:
    • AVERAGE

      public static final int AVERAGE
      DOCUMENT ME!
      See Also:
    • DIFFERENCE

      public static final int DIFFERENCE
      DOCUMENT ME!
      See Also:
    • DIVIDE

      public static final int DIVIDE
      DOCUMENT ME!
      See Also:
    • MAXIMUM

      public static final int MAXIMUM
      DOCUMENT ME!
      See Also:
    • MEAN_SQUARED_ERROR

      public static final int MEAN_SQUARED_ERROR
      See Also:
    • MINIMUM

      public static final int MINIMUM
      DOCUMENT ME!
      See Also:
    • MULTIPLY

      public static final int MULTIPLY
      DOCUMENT ME!
      See Also:
    • OR

      public static final int OR
      DOCUMENT ME!
      See Also:
    • SUBTRACT

      public static final int SUBTRACT
      DOCUMENT ME!
      See Also:
    • XOR

      public static final int XOR
      DOCUMENT ME!
      See Also:
    • AVGERAGE_WITH_STDEV

      public static final int AVGERAGE_WITH_STDEV
      See Also:
    • CLIP

      public static final int CLIP
      DOCUMENT ME!
      See Also:
    • PROMOTE

      public static final int PROMOTE
      DOCUMENT ME!
      See Also:
    • aButton

      private JButton aButton
      DOCUMENT ME!
    • bButton

      private JButton bButton
      DOCUMENT ME!
    • backSpaceButton

      private JButton backSpaceButton
      DOCUMENT ME!
    • ceButton

      private JButton ceButton
      DOCUMENT ME!
    • leftParButton

      private JButton leftParButton
      DOCUMENT ME!
    • rightParButton

      private JButton rightParButton
      DOCUMENT ME!
    • adOpDialog

      private JDialog adOpDialog
      DOCUMENT ME!
    • adOpString

      private 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 JButton expButton
      DOCUMENT ME!
    • lnButton

      private JButton lnButton
      DOCUMENT ME!
    • sevenButton

      private JButton sevenButton
      DOCUMENT ME!
    • eightButton

      private JButton eightButton
      DOCUMENT ME!
    • nineButton

      private JButton nineButton
      DOCUMENT ME!
    • divButton

      private JButton divButton
      DOCUMENT ME!
    • logButton

      private JButton logButton
      DOCUMENT ME!
    • absButton

      private 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 JButton OKButton
      DOCUMENT ME!
    • cancelButton

      private JButton cancelButton
      DOCUMENT ME!
    • opType

      private int opType
      Operation to be performed on the images (i.e. Add, ...)
    • powButton

      private JButton powButton
      DOCUMENT ME!
    • commaButton

      private JButton commaButton
      DOCUMENT ME!
    • fourButton

      private JButton fourButton
      DOCUMENT ME!
    • fiveButton

      private JButton fiveButton
      DOCUMENT ME!
    • sixButton

      private JButton sixButton
      DOCUMENT ME!
    • multButton

      private JButton multButton
      DOCUMENT ME!
    • pressedOK

      private boolean pressedOK
      DOCUMENT ME!
    • sinButton

      private JButton sinButton
      DOCUMENT ME!
    • cosButton

      private JButton cosButton
      DOCUMENT ME!
    • oneButton

      private JButton oneButton
      DOCUMENT ME!
    • twoButton

      private JButton twoButton
      DOCUMENT ME!
    • threeButton

      private JButton threeButton
      DOCUMENT ME!
    • subButton

      private JButton subButton
      DOCUMENT ME!
    • srcImageA

      private ModelImage srcImageA
      Source image A.
    • srcImageB

      private ModelImage srcImageB
      Source image B.
    • tanButton

      private JButton tanButton
      DOCUMENT ME!
    • piButton

      private JButton piButton
      DOCUMENT ME!
    • zeroButton

      private JButton zeroButton
      DOCUMENT ME!
    • decimalButton

      private JButton decimalButton
      DOCUMENT ME!
    • modButton

      private JButton modButton
      DOCUMENT ME!
    • addButton

      private JButton addButton
      DOCUMENT ME!
    • textOperator

      private JTextField textOperator
      DOCUMENT ME!
    • srcImages

      private ModelImage[] srcImages
      when performing bulk operations via Image Calculator (Bulk Images) dialog, this array is populated
    • rpn

      private String rpn
  • Constructor Details

    • AlgorithmImageCalculator

      public AlgorithmImageCalculator(ModelImage srcImgA, ModelImage srcImgB, int type, int _clipMode, boolean maskFlag, String adOpString)
      Creates a new AlgorithmImageCalculator object using srcImgA srcImgB.
      Parameters:
      srcImgA - source image A model
      srcImgB - source image B model
      type - operation type
      _clipMode - CLIP or PROMOTE input image data
      maskFlag - Flag that indicates that the operator will be calculated for the whole image if equal to true
      adOpString - 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 stored
      srcImgA - source image A model
      srcImgB - source image B model
      type - operation type
      _clipMode - CLIP or PROMOTE input image data
      maskFlag - Flag that indicates that the operator will be calculated for the whole image if equal to true
      adOpString - 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

      public void actionPerformed(ActionEvent event)
      Calls various methods depending on the action used by the advanced calculator.
      Specified by:
      actionPerformed in interface ActionListener
      Overrides:
      actionPerformed in class AlgorithmBase
      Parameters:
      event - event that triggered function
    • finalize

      public void finalize()
      Prepares this class for destruction.
      Overrides:
      finalize in class AlgorithmBase
    • focusGained

      public void focusGained(FocusEvent event)
      Unchanged.
      Specified by:
      focusGained in interface FocusListener
      Parameters:
      event - DOCUMENT ME!
    • focusLost

      public void focusLost(FocusEvent event)
      Unchanged.
      Specified by:
      focusLost in interface FocusListener
      Parameters:
      event - DOCUMENT ME!
    • getAdvFunction

      public 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 class AlgorithmBase
    • 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(ActionListener al)
      Builds the advanced function dialog - looks like a calculator.
      Parameters:
      al - DOCUMENT ME!
    • evaluateRPNExpression

      public double evaluateRPNExpression(double a, double b, String rpn)
      Method that evaluates the RPN expression and returns the value
    • evaluateToRPN

      public String evaluateToRPN(String expression)
      method that determines the RPN
      Parameters:
      expression -
      Returns:
    • initialValidate

      public boolean initialValidate(String expression)
      method that does some initial validation of the expression
      Parameters:
      expression -
      Returns:
    • tokenize

      public boolean tokenize(String expression, Vector<String> tokens)
      method that tokenizes the expression
      Parameters:
      expression -
      tokens -
      Returns:
    • convertToRPN

      public String convertToRPN(Vector<String> tokens)
      method that converts the tokens to RPN
      Parameters:
      tokens -
      Returns:
    • precedence

      public int precedence(String op)
      method that determines precedence
      Parameters:
      op -
      Returns:
    • isOperator

      public boolean isOperator(String token)
      method determining if token is an operator
      Parameters:
      token -
      Returns:
    • isFunction

      public boolean isFunction(String token)
      method determining if token is function
      Parameters:
      token -
      Returns:
    • readChar

      public char readChar(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(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 type
      minVal - min value of the image
      maxVal - max value of the image
      Returns:
      true if min and max are within the image type specified