Class RubberbandLivewire
- All Implemented Interfaces:
ActionListener,MouseListener,MouseMotionListener,WindowListener,ImageObserver,MenuContainer,Serializable,EventListener
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:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclassBinary search tree, modified so it will work with elements that have the same cost.classTree node.Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate RubberbandLivewire.ActiveTreeDOCUMENT ME!private Vector<WildMagic.LibFoundation.Mathematics.Vector3f> DOCUMENT ME!private VOIContourDOCUMENT ME!private byte[]DOCUMENT ME!private intDOCUMENT ME!(package private) floatDOCUMENT ME!private booleanDOCUMENT ME!private floatDOCUMENT ME!static intDOCUMENT ME!static intDOCUMENT ME!static intDOCUMENT ME!static intDOCUMENT ME!static intDOCUMENT ME!private float[]DOCUMENT ME!static intDOCUMENT ME!private floatDOCUMENT ME!(package private) floatDOCUMENT ME!(package private) float[]DOCUMENT ME!(package private) float[]DOCUMENT ME!private BitSetDOCUMENT ME!(package private) ViewJProgressBarDOCUMENT ME!private float[]DOCUMENT ME!private intDOCUMENT ME!private intDOCUMENT ME!private static final longUse serialVersionUID for interoperability.private booleanDOCUMENT ME!private PointDOCUMENT ME!private CursorDOCUMENT ME!private intDOCUMENT ME!private float[]DOCUMENT ME!private float[]DOCUMENT ME!private int[]DOCUMENT ME!private intDOCUMENT ME!private float[]DOCUMENT ME!private float[]DOCUMENT ME!private int[]DOCUMENT ME!Fields inherited from class gov.nih.mipav.view.Rubberband
anchorPt, component, endPt, lastPt, stretchedPt, usableComponent, xMax, xS, yMax, ySFields inherited from class java.awt.Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENTFields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH -
Constructor Summary
ConstructorsConstructorDescriptionRubberbandLivewire(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(Component component, int selection) Sets up local costs graph by calling AlgorithmGradientMagnitude and AlgorithmEdgeLaplacianSep. -
Method Summary
Modifier and TypeMethodDescriptionvoidactionPerformed(ActionEvent event) Stops the thread, and disposes the progress bar.voidCalls seed on this point to set up costGraph array; then anchors point.private intconvertGraphToInt(int next) Takes a byte and gets appropriate addition from current position.voidDraws a line based on the rubberband's last bounds.voidDraws 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) voidmouseClicked(MouseEvent mouseEvent) Unchanged.voidmouseDragged(MouseEvent mouseEvent) Makes a contour out of the curve drawn.voidmouseEntered(MouseEvent mouseEvent) Unchanged.voidmouseExited(MouseEvent mouseEvent) Unchanged.voidmouseMoved(MouseEvent mouseEvent) Stretches if the VOI is active.voidmousePressed(MouseEvent mouseEvent) Unchanged.voidmouseReleased(MouseEvent mouseEvent) Makes a VOI out of the contours upon a mouse release event.private voidSets up directed graph from the seed point.voidsetPresetHue(float presetHue) Sets the presetHue.voidwindowActivated(WindowEvent event) Unchanged.voidwindowClosed(WindowEvent event) Unchanged.voidwindowClosing(WindowEvent event) Sets completed to false, disposes the progress bar and notifies all listeners that the algorithm is stopped.voidwindowDeactivated(WindowEvent event) Unchanged.voidwindowDeiconified(WindowEvent event) Unchanged.voidwindowIconified(WindowEvent event) Unchanged.voidwindowOpened(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, testPointMethods 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 Details
-
serialVersionUID
private static final long serialVersionUIDUse serialVersionUID for interoperability.- See Also:
-
GRADIENT_MAG
public static int GRADIENT_MAGDOCUMENT ME! -
MEDIALNESS
public static int MEDIALNESSDOCUMENT ME! -
INTENSITY
public static int INTENSITYDOCUMENT ME! -
GRADIENT_MAG_MED
public static int GRADIENT_MAG_MEDDOCUMENT ME! -
GRADIENT_MAG_INT
public static int GRADIENT_MAG_INTDOCUMENT ME! -
GRADIENT_ALL
public static int GRADIENT_ALLDOCUMENT ME! -
currContourCost
float currContourCostDOCUMENT ME! -
prevContourCost
float prevContourCostDOCUMENT ME! -
prevXPoints
float[] prevXPointsDOCUMENT ME! -
prevYPoints
float[] prevYPointsDOCUMENT ME! -
progressBar
ViewJProgressBar progressBarDOCUMENT ME! -
activeTree
DOCUMENT ME! -
clickPoints
DOCUMENT ME! -
contour
DOCUMENT ME! -
costGraph
private byte[] costGraphDOCUMENT ME! -
count
private int countDOCUMENT ME! -
firstPoint
private boolean firstPointDOCUMENT ME! -
grad_weight
private float grad_weightDOCUMENT ME! -
localCosts
private float[] localCostsDOCUMENT ME! -
presetHue
private float presetHueDOCUMENT ME! -
processedIndicies
DOCUMENT ME! -
seededCosts
private float[] seededCostsDOCUMENT ME! -
seedPoint
private int seedPointDOCUMENT ME! -
selection
private int selectionDOCUMENT ME! -
smoothVOIFlag
private boolean smoothVOIFlagDOCUMENT ME! -
tmpPt
DOCUMENT ME! -
waitCursor
DOCUMENT ME! -
xDim
private int xDimDOCUMENT ME! -
yDim
private int yDimDOCUMENT ME! -
xDirections
private float[] xDirectionsDOCUMENT ME! -
xPoints
private float[] xPointsDOCUMENT ME! -
xPointsDraw
private int[] xPointsDrawDOCUMENT ME! -
yDirections
private float[] yDirectionsDOCUMENT ME! -
yPoints
private float[] yPointsDOCUMENT ME! -
yPointsDraw
private int[] yPointsDrawDOCUMENT ME!
-
-
Constructor Details
-
RubberbandLivewire
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(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 Details
-
actionPerformed
Stops the thread, and disposes the progress bar.- Specified by:
actionPerformedin interfaceActionListener- Parameters:
event- Event that triggered function.
-
anchor
Calls seed on this point to set up costGraph array; then anchors point.- Overrides:
anchorin classRubberband- Parameters:
pt- Point to anchor.
-
drawLast
Draws a line based on the rubberband's last bounds.- Specified by:
drawLastin classRubberband- Parameters:
graphics- graphics to draw in
-
drawNext
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:
drawNextin 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
Unchanged.- Specified by:
mouseClickedin interfaceMouseListener- Overrides:
mouseClickedin classRubberband- Parameters:
mouseEvent- DOCUMENT ME!
-
mouseDragged
Makes a contour out of the curve drawn.- Specified by:
mouseDraggedin interfaceMouseMotionListener- Overrides:
mouseDraggedin classRubberband- Parameters:
mouseEvent- event that triggered this function
-
mouseEntered
Unchanged.- Specified by:
mouseEnteredin interfaceMouseListener- Overrides:
mouseEnteredin classRubberband- Parameters:
mouseEvent- DOCUMENT ME!
-
mouseExited
Unchanged.- Specified by:
mouseExitedin interfaceMouseListener- Overrides:
mouseExitedin classRubberband- Parameters:
mouseEvent- DOCUMENT ME!
-
mouseMoved
Stretches if the VOI is active.- Specified by:
mouseMovedin interfaceMouseMotionListener- Overrides:
mouseMovedin classRubberband- Parameters:
mouseEvent- event that triggered this function
-
mousePressed
Unchanged.- Specified by:
mousePressedin interfaceMouseListener- Overrides:
mousePressedin classRubberband- Parameters:
mouseEvent- DOCUMENT ME!
-
mouseReleased
Makes a VOI out of the contours upon a mouse release event.- Specified by:
mouseReleasedin interfaceMouseListener- Overrides:
mouseReleasedin classRubberband- Parameters:
mouseEvent- event that triggered function
-
setPresetHue
public void setPresetHue(float presetHue) Sets the presetHue.- Overrides:
setPresetHuein classRubberband- Parameters:
presetHue- DOCUMENT ME!
-
windowActivated
Unchanged.- Specified by:
windowActivatedin interfaceWindowListener- Parameters:
event- DOCUMENT ME!
-
windowClosed
Unchanged.- Specified by:
windowClosedin interfaceWindowListener- Parameters:
event- DOCUMENT ME!
-
windowClosing
Sets completed to false, disposes the progress bar and notifies all listeners that the algorithm is stopped.- Specified by:
windowClosingin interfaceWindowListener- Parameters:
event- event that triggered function
-
windowDeactivated
Unchanged.- Specified by:
windowDeactivatedin interfaceWindowListener- Parameters:
event- DOCUMENT ME!
-
windowDeiconified
Unchanged.- Specified by:
windowDeiconifiedin interfaceWindowListener- Parameters:
event- DOCUMENT ME!
-
windowIconified
Unchanged.- Specified by:
windowIconifiedin interfaceWindowListener- Parameters:
event- DOCUMENT ME!
-
windowOpened
Unchanged.- Specified by:
windowOpenedin interfaceWindowListener- 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
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.
-