Class RubberbandLivewire
- java.lang.Object
-
- java.awt.Component
-
- gov.nih.mipav.view.Rubberband
-
- gov.nih.mipav.view.RubberbandLivewire
-
- All Implemented Interfaces:
java.awt.event.ActionListener
,java.awt.event.MouseListener
,java.awt.event.MouseMotionListener
,java.awt.event.WindowListener
,java.awt.image.ImageObserver
,java.awt.MenuContainer
,java.io.Serializable
,java.util.EventListener
public class RubberbandLivewire extends Rubberband implements java.awt.event.ActionListener, java.awt.event.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:
Rubberband
, Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
RubberbandLivewire.ActiveTree
Binary search tree, modified so it will work with elements that have the same cost.class
RubberbandLivewire.TreeNode
Tree node.
-
Field Summary
Fields Modifier and Type Field Description private RubberbandLivewire.ActiveTree
activeTree
DOCUMENT ME!private java.util.Vector<WildMagic.LibFoundation.Mathematics.Vector3f>
clickPoints
DOCUMENT ME!private VOIContour
contour
DOCUMENT ME!private byte[]
costGraph
DOCUMENT ME!private int
count
DOCUMENT ME!(package private) float
currContourCost
DOCUMENT ME!private boolean
firstPoint
DOCUMENT ME!private float
grad_weight
DOCUMENT ME!static int
GRADIENT_ALL
DOCUMENT ME!static int
GRADIENT_MAG
DOCUMENT ME!static int
GRADIENT_MAG_INT
DOCUMENT ME!static int
GRADIENT_MAG_MED
DOCUMENT ME!static int
INTENSITY
DOCUMENT ME!private float[]
localCosts
DOCUMENT ME!static int
MEDIALNESS
DOCUMENT ME!private float
presetHue
DOCUMENT ME!(package private) float
prevContourCost
DOCUMENT ME!(package private) float[]
prevXPoints
DOCUMENT ME!(package private) float[]
prevYPoints
DOCUMENT ME!private java.util.BitSet
processedIndicies
DOCUMENT ME!(package private) ViewJProgressBar
progressBar
DOCUMENT ME!private float[]
seededCosts
DOCUMENT ME!private int
seedPoint
DOCUMENT ME!private int
selection
DOCUMENT ME!private static long
serialVersionUID
Use serialVersionUID for interoperability.private boolean
smoothVOIFlag
DOCUMENT ME!private java.awt.Point
tmpPt
DOCUMENT ME!private java.awt.Cursor
waitCursor
DOCUMENT ME!private int
xDim
DOCUMENT ME!private float[]
xDirections
DOCUMENT ME!private float[]
xPoints
DOCUMENT ME!private int[]
xPointsDraw
DOCUMENT ME!private int
yDim
DOCUMENT ME!private float[]
yDirections
DOCUMENT ME!private float[]
yPoints
DOCUMENT ME!private int[]
yPointsDraw
DOCUMENT ME!-
Fields inherited from class gov.nih.mipav.view.Rubberband
anchorPt, component, endPt, lastPt, stretchedPt, usableComponent, xMax, xS, yMax, yS
-
-
Constructor Summary
Constructors Constructor Description RubberbandLivewire(java.awt.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.RubberbandLivewire(java.awt.Component component, int selection)
Sets up local costs graph by calling AlgorithmGradientMagnitude and AlgorithmEdgeLaplacianSep.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
actionPerformed(java.awt.event.ActionEvent event)
Stops the thread, and disposes the progress bar.void
anchor(java.awt.Point pt)
Calls seed on this point to set up costGraph array; then anchors point.private int
convertGraphToInt(int next)
Takes a byte and gets appropriate addition from current position.void
drawLast(java.awt.Graphics graphics)
Draws a line based on the rubberband's last bounds.void
drawNext(java.awt.Graphics graphics)
Draws a line by following the graph from the current location back to the anchor point.static float[]
getLocalCosts(ModelImage kImage, int selection, float[] activeSliceBuffer, float[] xDirections, float[] yDirections, ViewJProgressBar progressBar)
void
mouseClicked(java.awt.event.MouseEvent mouseEvent)
Unchanged.void
mouseDragged(java.awt.event.MouseEvent mouseEvent)
Makes a contour out of the curve drawn.void
mouseEntered(java.awt.event.MouseEvent mouseEvent)
Unchanged.void
mouseExited(java.awt.event.MouseEvent mouseEvent)
Unchanged.void
mouseMoved(java.awt.event.MouseEvent mouseEvent)
Stretches if the VOI is active.void
mousePressed(java.awt.event.MouseEvent mouseEvent)
Unchanged.void
mouseReleased(java.awt.event.MouseEvent mouseEvent)
Makes a VOI out of the contours upon a mouse release event.private void
seed(java.awt.Point pt)
Sets up directed graph from the seed point.void
setPresetHue(float presetHue)
Sets the presetHue.void
windowActivated(java.awt.event.WindowEvent event)
Unchanged.void
windowClosed(java.awt.event.WindowEvent event)
Unchanged.void
windowClosing(java.awt.event.WindowEvent event)
Sets completed to false, disposes the progress bar and notifies all listeners that the algorithm is stopped.void
windowDeactivated(java.awt.event.WindowEvent event)
Unchanged.void
windowDeiconified(java.awt.event.WindowEvent event)
Unchanged.void
windowIconified(java.awt.event.WindowEvent event)
Unchanged.void
windowOpened(java.awt.event.WindowEvent event)
Unchanged.-
Methods inherited from class gov.nih.mipav.view.Rubberband
dispose, distance, end, getAnchor, getBounds, getEnd, getLast, getStretched, isActive, lastBounds, setActive, setComponent, stretch, testPoint
-
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAccessibleContext, getAlignmentX, getAlignmentY, getBackground, getBaseline, getBaselineResizeBehavior, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeys, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMinimumSize, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusCycleRoot, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, minimumSize, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paint, paintAll, paramString, postEvent, preferredSize, prepareImage, prepareImage, print, printAll, processComponentEvent, processEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, revalidate, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setFont, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setMixingCutoutShape, setName, setPreferredSize, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle, update, validate
-
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
Use serialVersionUID for interoperability.- See Also:
- Constant Field Values
-
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 java.util.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 java.util.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 java.awt.Point tmpPt
DOCUMENT ME!
-
waitCursor
private java.awt.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 Detail
-
RubberbandLivewire
public RubberbandLivewire(java.awt.Component component, int selection)
Sets up local costs graph by calling AlgorithmGradientMagnitude and AlgorithmEdgeLaplacianSep. Initializes necessary global arrays.- Parameters:
component
- component to add toselection
- GRADIENT_MAG, MEDIALNESS, INTENSITY, GRADIENT_MAG_MED, GRADIENT_MAG_INT, or GRADIENT_ALL
-
RubberbandLivewire
public RubberbandLivewire(java.awt.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 tograd_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 Detail
-
actionPerformed
public void actionPerformed(java.awt.event.ActionEvent event)
Stops the thread, and disposes the progress bar.- Specified by:
actionPerformed
in interfacejava.awt.event.ActionListener
- Parameters:
event
- Event that triggered function.
-
anchor
public void anchor(java.awt.Point pt)
Calls seed on this point to set up costGraph array; then anchors point.- Overrides:
anchor
in classRubberband
- Parameters:
pt
- Point to anchor.
-
drawLast
public void drawLast(java.awt.Graphics graphics)
Draws a line based on the rubberband's last bounds.- Specified by:
drawLast
in classRubberband
- Parameters:
graphics
- graphics to draw in
-
drawNext
public void drawNext(java.awt.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 classRubberband
- 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(java.awt.event.MouseEvent mouseEvent)
Unchanged.- Specified by:
mouseClicked
in interfacejava.awt.event.MouseListener
- Overrides:
mouseClicked
in classRubberband
- Parameters:
mouseEvent
- DOCUMENT ME!
-
mouseDragged
public void mouseDragged(java.awt.event.MouseEvent mouseEvent)
Makes a contour out of the curve drawn.- Specified by:
mouseDragged
in interfacejava.awt.event.MouseMotionListener
- Overrides:
mouseDragged
in classRubberband
- Parameters:
mouseEvent
- event that triggered this function
-
mouseEntered
public void mouseEntered(java.awt.event.MouseEvent mouseEvent)
Unchanged.- Specified by:
mouseEntered
in interfacejava.awt.event.MouseListener
- Overrides:
mouseEntered
in classRubberband
- Parameters:
mouseEvent
- DOCUMENT ME!
-
mouseExited
public void mouseExited(java.awt.event.MouseEvent mouseEvent)
Unchanged.- Specified by:
mouseExited
in interfacejava.awt.event.MouseListener
- Overrides:
mouseExited
in classRubberband
- Parameters:
mouseEvent
- DOCUMENT ME!
-
mouseMoved
public void mouseMoved(java.awt.event.MouseEvent mouseEvent)
Stretches if the VOI is active.- Specified by:
mouseMoved
in interfacejava.awt.event.MouseMotionListener
- Overrides:
mouseMoved
in classRubberband
- Parameters:
mouseEvent
- event that triggered this function
-
mousePressed
public void mousePressed(java.awt.event.MouseEvent mouseEvent)
Unchanged.- Specified by:
mousePressed
in interfacejava.awt.event.MouseListener
- Overrides:
mousePressed
in classRubberband
- Parameters:
mouseEvent
- DOCUMENT ME!
-
mouseReleased
public void mouseReleased(java.awt.event.MouseEvent mouseEvent)
Makes a VOI out of the contours upon a mouse release event.- Specified by:
mouseReleased
in interfacejava.awt.event.MouseListener
- Overrides:
mouseReleased
in classRubberband
- Parameters:
mouseEvent
- event that triggered function
-
setPresetHue
public void setPresetHue(float presetHue)
Sets the presetHue.- Overrides:
setPresetHue
in classRubberband
- Parameters:
presetHue
- DOCUMENT ME!
-
windowActivated
public void windowActivated(java.awt.event.WindowEvent event)
Unchanged.- Specified by:
windowActivated
in interfacejava.awt.event.WindowListener
- Parameters:
event
- DOCUMENT ME!
-
windowClosed
public void windowClosed(java.awt.event.WindowEvent event)
Unchanged.- Specified by:
windowClosed
in interfacejava.awt.event.WindowListener
- Parameters:
event
- DOCUMENT ME!
-
windowClosing
public void windowClosing(java.awt.event.WindowEvent event)
Sets completed to false, disposes the progress bar and notifies all listeners that the algorithm is stopped.- Specified by:
windowClosing
in interfacejava.awt.event.WindowListener
- Parameters:
event
- event that triggered function
-
windowDeactivated
public void windowDeactivated(java.awt.event.WindowEvent event)
Unchanged.- Specified by:
windowDeactivated
in interfacejava.awt.event.WindowListener
- Parameters:
event
- DOCUMENT ME!
-
windowDeiconified
public void windowDeiconified(java.awt.event.WindowEvent event)
Unchanged.- Specified by:
windowDeiconified
in interfacejava.awt.event.WindowListener
- Parameters:
event
- DOCUMENT ME!
-
windowIconified
public void windowIconified(java.awt.event.WindowEvent event)
Unchanged.- Specified by:
windowIconified
in interfacejava.awt.event.WindowListener
- Parameters:
event
- DOCUMENT ME!
-
windowOpened
public void windowOpened(java.awt.event.WindowEvent event)
Unchanged.- Specified by:
windowOpened
in interfacejava.awt.event.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(java.awt.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 totrue
.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.
-
-