Class RubberbandLivewire

All Implemented Interfaces:
ActionListener, MouseListener, MouseMotionListener, WindowListener, ImageObserver, MenuContainer, Serializable, EventListener

public class RubberbandLivewire extends Rubberband implements ActionListener, WindowListener
A Livewire rubberband. It makes segmentation easier by "snapping to" appropriate pixels to outline features. The pixels it snaps to are those with the minimum cost; cost is a function of gradient magnitude, gradient direction, and zero x-crossings. Whenever an anchor is established, a directed graph of costs is created, so that from any pixel in the image, the shortest path from that pixel to the anchor can be drawn. Once the user is satisfied with that path they can put down another anchor, for a new directed cost graph.

This is based on the method described by Eric N Mortensen and William A Barrett from Brigham Young University, in their paper "Interactive Segmentation with Intelligent Scissors", Graphical Models and Image Processing, v 60, n 5, September 1998, p.349-384.

A description of the color gradient direction is given in The Doctoral Dissertation of Eric N. Mortensen: "Simultaneous Multi-Frame Subpixel Boundary Definition using Toboggan-Based Intelligent Scissors for Image and Movie Editing, Department of Computer Science, Brigham Young University, Provo, Utah, December, 2000, Section 4.3.1.1 Domain projection vector: vx. The description of summing gradient magnitudes of the different color bands is described in Section 3.1.1 Discontinuity Measure: Multi-scale Gradient Magnitude. This is in contrast to the earlier 1998 paper which used the maximum of the color band gradient magnitudes.

Version:
1.0, 4/1/2002
Author:
Neva Cherniavsky
See Also:
  • Field Details

    • serialVersionUID

      private static final long serialVersionUID
      Use serialVersionUID for interoperability.
      See Also:
    • GRADIENT_MAG

      public static int GRADIENT_MAG
      DOCUMENT ME!
    • MEDIALNESS

      public static int MEDIALNESS
      DOCUMENT ME!
    • INTENSITY

      public static int INTENSITY
      DOCUMENT ME!
    • GRADIENT_MAG_MED

      public static int GRADIENT_MAG_MED
      DOCUMENT ME!
    • GRADIENT_MAG_INT

      public static int GRADIENT_MAG_INT
      DOCUMENT ME!
    • GRADIENT_ALL

      public static int GRADIENT_ALL
      DOCUMENT ME!
    • currContourCost

      float currContourCost
      DOCUMENT ME!
    • prevContourCost

      float prevContourCost
      DOCUMENT ME!
    • prevXPoints

      float[] prevXPoints
      DOCUMENT ME!
    • prevYPoints

      float[] prevYPoints
      DOCUMENT ME!
    • progressBar

      ViewJProgressBar progressBar
      DOCUMENT ME!
    • activeTree

      private RubberbandLivewire.ActiveTree activeTree
      DOCUMENT ME!
    • clickPoints

      private Vector<WildMagic.LibFoundation.Mathematics.Vector3f> clickPoints
      DOCUMENT ME!
    • contour

      private VOIContour contour
      DOCUMENT ME!
    • costGraph

      private byte[] costGraph
      DOCUMENT ME!
    • count

      private int count
      DOCUMENT ME!
    • firstPoint

      private boolean firstPoint
      DOCUMENT ME!
    • grad_weight

      private float grad_weight
      DOCUMENT ME!
    • localCosts

      private float[] localCosts
      DOCUMENT ME!
    • presetHue

      private float presetHue
      DOCUMENT ME!
    • processedIndicies

      private BitSet processedIndicies
      DOCUMENT ME!
    • seededCosts

      private float[] seededCosts
      DOCUMENT ME!
    • seedPoint

      private int seedPoint
      DOCUMENT ME!
    • selection

      private int selection
      DOCUMENT ME!
    • smoothVOIFlag

      private boolean smoothVOIFlag
      DOCUMENT ME!
    • tmpPt

      private Point tmpPt
      DOCUMENT ME!
    • waitCursor

      private Cursor waitCursor
      DOCUMENT ME!
    • xDim

      private int xDim
      DOCUMENT ME!
    • yDim

      private int yDim
      DOCUMENT ME!
    • xDirections

      private float[] xDirections
      DOCUMENT ME!
    • xPoints

      private float[] xPoints
      DOCUMENT ME!
    • xPointsDraw

      private int[] xPointsDraw
      DOCUMENT ME!
    • yDirections

      private float[] yDirections
      DOCUMENT ME!
    • yPoints

      private float[] yPoints
      DOCUMENT ME!
    • yPointsDraw

      private int[] yPointsDraw
      DOCUMENT ME!
  • Constructor Details

    • RubberbandLivewire

      public RubberbandLivewire(Component component, int selection)
      Sets up local costs graph by calling AlgorithmGradientMagnitude and AlgorithmEdgeLaplacianSep. Initializes necessary global arrays.
      Parameters:
      component - component to add to
      selection - GRADIENT_MAG, MEDIALNESS, INTENSITY, GRADIENT_MAG_MED, GRADIENT_MAG_INT, or GRADIENT_ALL
    • RubberbandLivewire

      public RubberbandLivewire(Component component, float[] grad_sigmas, float[] edgelap_sigmas, float kern_weight, float grad_weight, boolean smoothVOIFlag)
      Sets up local costs graph by calling AlgorithmGradientMagnitudeSep and AlgorithmEdgeLaplacianSep. Initializes necessary global arrays. Only for non-color images and GRADIENT_MAG path calculation (ie- in RFASegTool).
      Parameters:
      component - component to add to
      grad_sigmas - DOCUMENT ME!
      edgelap_sigmas - DOCUMENT ME!
      kern_weight - DOCUMENT ME!
      grad_weight - DOCUMENT ME!
      smoothVOIFlag - whether to smooth the VOI once the livewire selection is done
  • Method Details

    • actionPerformed

      public void actionPerformed(ActionEvent event)
      Stops the thread, and disposes the progress bar.
      Specified by:
      actionPerformed in interface ActionListener
      Parameters:
      event - Event that triggered function.
    • anchor

      public void anchor(Point pt)
      Calls seed on this point to set up costGraph array; then anchors point.
      Overrides:
      anchor in class Rubberband
      Parameters:
      pt - Point to anchor.
    • drawLast

      public void drawLast(Graphics graphics)
      Draws a line based on the rubberband's last bounds.
      Specified by:
      drawLast in class Rubberband
      Parameters:
      graphics - graphics to draw in
    • drawNext

      public void drawNext(Graphics graphics)
      Draws a line by following the graph from the current location back to the anchor point. The anchor point has its parent = -1.
      Specified by:
      drawNext in class Rubberband
      Parameters:
      graphics - Graphics to draw in
    • getLocalCosts

      public static float[] getLocalCosts(ModelImage kImage, int selection, float[] activeSliceBuffer, float[] xDirections, float[] yDirections, ViewJProgressBar progressBar)
    • mouseClicked

      public void mouseClicked(MouseEvent mouseEvent)
      Unchanged.
      Specified by:
      mouseClicked in interface MouseListener
      Overrides:
      mouseClicked in class Rubberband
      Parameters:
      mouseEvent - DOCUMENT ME!
    • mouseDragged

      public void mouseDragged(MouseEvent mouseEvent)
      Makes a contour out of the curve drawn.
      Specified by:
      mouseDragged in interface MouseMotionListener
      Overrides:
      mouseDragged in class Rubberband
      Parameters:
      mouseEvent - event that triggered this function
    • mouseEntered

      public void mouseEntered(MouseEvent mouseEvent)
      Unchanged.
      Specified by:
      mouseEntered in interface MouseListener
      Overrides:
      mouseEntered in class Rubberband
      Parameters:
      mouseEvent - DOCUMENT ME!
    • mouseExited

      public void mouseExited(MouseEvent mouseEvent)
      Unchanged.
      Specified by:
      mouseExited in interface MouseListener
      Overrides:
      mouseExited in class Rubberband
      Parameters:
      mouseEvent - DOCUMENT ME!
    • mouseMoved

      public void mouseMoved(MouseEvent mouseEvent)
      Stretches if the VOI is active.
      Specified by:
      mouseMoved in interface MouseMotionListener
      Overrides:
      mouseMoved in class Rubberband
      Parameters:
      mouseEvent - event that triggered this function
    • mousePressed

      public void mousePressed(MouseEvent mouseEvent)
      Unchanged.
      Specified by:
      mousePressed in interface MouseListener
      Overrides:
      mousePressed in class Rubberband
      Parameters:
      mouseEvent - DOCUMENT ME!
    • mouseReleased

      public void mouseReleased(MouseEvent mouseEvent)
      Makes a VOI out of the contours upon a mouse release event.
      Specified by:
      mouseReleased in interface MouseListener
      Overrides:
      mouseReleased in class Rubberband
      Parameters:
      mouseEvent - event that triggered function
    • setPresetHue

      public void setPresetHue(float presetHue)
      Sets the presetHue.
      Overrides:
      setPresetHue in class Rubberband
      Parameters:
      presetHue - DOCUMENT ME!
    • windowActivated

      public void windowActivated(WindowEvent event)
      Unchanged.
      Specified by:
      windowActivated in interface WindowListener
      Parameters:
      event - DOCUMENT ME!
    • windowClosed

      public void windowClosed(WindowEvent event)
      Unchanged.
      Specified by:
      windowClosed in interface WindowListener
      Parameters:
      event - DOCUMENT ME!
    • windowClosing

      public void windowClosing(WindowEvent event)
      Sets completed to false, disposes the progress bar and notifies all listeners that the algorithm is stopped.
      Specified by:
      windowClosing in interface WindowListener
      Parameters:
      event - event that triggered function
    • windowDeactivated

      public void windowDeactivated(WindowEvent event)
      Unchanged.
      Specified by:
      windowDeactivated in interface WindowListener
      Parameters:
      event - DOCUMENT ME!
    • windowDeiconified

      public void windowDeiconified(WindowEvent event)
      Unchanged.
      Specified by:
      windowDeiconified in interface WindowListener
      Parameters:
      event - DOCUMENT ME!
    • windowIconified

      public void windowIconified(WindowEvent event)
      Unchanged.
      Specified by:
      windowIconified in interface WindowListener
      Parameters:
      event - DOCUMENT ME!
    • windowOpened

      public void windowOpened(WindowEvent event)
      Unchanged.
      Specified by:
      windowOpened in interface WindowListener
      Parameters:
      event - DOCUMENT ME!
    • convertGraphToInt

      private int convertGraphToInt(int next)
      Takes a byte and gets appropriate addition from current position.
      Parameters:
      next - Byte to check (0-8).
      Returns:
      Value to add to current location.
    • seed

      private void seed(Point pt)
      Sets up directed graph from the seed point. A point (x,y) is mapped to its absolute value in the image, y*xDim + x. This along with its cost is stored in Node. The structure costGraph holds the "edges" of the graph. Each location has an integer associated with it which represents where that node is pointing to. Thus costGraph[7] = 8 would mean the node at 7 (really (0,7)) is pointing to position 8 (really (0,8)). The only possibilities for a location in costGraph are the 8 neighbors surrounding that node. For this reason we might use a byte array instead of an integer array. The seed point points nowhere, to indicate that it's the seed; costGraph[seed.location] = -1. We also need to know if a point has been processed, that is, expanded with the cost set. For this we use a BitSet whose size is the same as the number of pixels in the image. Once a point is processed, its location in the BitSet is set to true.

      The array seededCosts holds the costs so far for a location. If a cost has not been assigned yet, the cost is -2. ActiveList is simply a linked list of Integers; the Integer refers to the location in the seededCosts array. ActiveList is sorted by cost, so that the minimum cost in the ActiveList is the first element of the linked list. Thus finding the minimum is O(1). Finding out if an element is in the ActiveList is also O(1), because for an element to be in the list, it must have already been assigned a cost. Therefore, if seededCosts[location] != -2, it is in the ActiveList. And finding the cost of an item in the ActiveList is O(1), because it's just seededCosts[location], where location is the Integer in the ActiveList. Obviously we're winning speed at the expense of memory, but it's not too much memory in the overall scheme of things.

      The gradient direction component of the cost is added in on the fly. This is because to precalculate would mean an array of 8n, where n is the size of the image. The link from p to q is not the same as the link from q to p. Furthermore, it may never be necessary to calculate some of the links, because the graph would never look at that pair. For more information on how the gradient direction cost is calculated, look at the comments directly above the code.

      Parameters:
      pt - Point to seed with.