org.shapelogic.imageprocessing
Class BaseVectorizer

java.lang.Object
  extended by org.shapelogic.imageutil.BaseImageOperation
      extended by org.shapelogic.imageprocessing.BaseVectorizer
All Implemented Interfaces:
java.lang.Runnable, java.util.Iterator<Polygon>, IPixelTypeFinder, LazyPlugInFilter<Polygon>, PixelJumperByte, ImageOperation
Direct Known Subclasses:
BaseMaxDistanceVectorizer, ShortLineBasedVectorizer

public abstract class BaseVectorizer
extends BaseImageOperation
implements IPixelTypeFinder, LazyPlugInFilter<Polygon>, java.util.Iterator<Polygon>

Input image needs to be binary, that is gray scale with inverted LUT. That the background is white, 0, and the foreground is black, 255. When it handles a point it will mark a point as used and what type it has. I put the result in a polygon. How do I know where to start? I will start taking the pixels until I meet the first black pixel, and I will work out from there. Cycle starting at (1,0) to (1,1) to (0,1) so in what would normally be counter clockwise, but since the coordinate system is turned upside down it is clockwise Terminology: Current: the short line that is currently handled Short line: there are 2 pieces, a short line at the end and everything before that

Author:
Sami Badawi

Field Summary
protected  Polygon _cleanedupPolygon
           
protected  byte _currentDirection
           
protected  int _currentPixelIndex
          this is the index into the _pixels where the current point is
protected  CPointInt _currentPoint
          last point where you are
protected  int[] _cyclePoints
          What you need to add to the the index in the pixels array to get to the indexed point
protected  boolean _displayInternalInfo
           
protected  java.util.List<java.util.Set<IPoint2D>> _endPointsClusters
           
protected  java.lang.String _errorMessage
           
protected  int _firstPointInLineIndex
           
protected  CPointInt _firstPointInMultiLine
           
protected  java.lang.Object _matchingOH
           
protected  int _maxX
           
protected  int _maxY
           
protected  int _minX
           
protected  int _minY
           
protected  int _nextCount
           
protected  int _numberOfPointsInAllLines
           
protected  byte[] _pixels
           
protected  PixelTypeCalculator _pixelTypeCalculator
           
protected  IPixelTypeFinder _pixelTypeFinder
           
protected  NumericRule[] _rulesArrayForLetterMatching
           
protected  ListStream<Polygon> _stream
           
protected  java.lang.String _streamName
          Really stream name but could be changed to _name.
protected  java.util.ArrayList<CPointInt> _unfinishedPoints
           
protected  int _yForUnporcessedPixel
           
static int MAX_DISTANCE_BETWEEN_CLUSTER_POINTS
           
static byte STRAIGHT_LINE_COLOR
           
 
Fields inherited from class org.shapelogic.imageutil.BaseImageOperation
_arg, _guiWrapper, _image, _keyValueParser, _setupReturnValue
 
Constructor Summary
BaseVectorizer()
           
 
Method Summary
protected  void addToUnfinishedPoints(CPointInt newPoint)
           
protected  void cleanPolygon()
           
 int countRegionCrossingsAroundPoint(int pixelIndex)
          A normal line has a crossing index of 4.
protected  void drawLine(CLine line)
           
protected  void drawLines()
          Draws the vectorized lines on the original image for visual inspection.
This is probably not needed in the final version of this class.
protected  void findAllLines()
           
protected  boolean findFirstLinePoint(boolean process)
          Find first point that is not a unused foreground point.
protected abstract  void findMultiLine()
           
protected  void findMultiLinePostProcess()
          To be overridden.
protected  boolean findMultiLinePreProcess()
           
 PixelTypeCalculator findPointType(int pixelIndex, PixelTypeCalculator reusedPixelTypeCalculator)
           
 Polygon getCleanedupPolygon()
           
 int[] getCyclePoints()
          What you need to add to the the index in the pixels array to get to the indexed point.
 java.lang.String getErrorMessage()
           
 ij.process.ImageProcessor getImageProcessor()
          Get an ImageJ ImageProcessor
This introduces dependency of ImageJ in a image processing algorithm, and should ideally be abstracted out.
 java.lang.Object getMatchingOH()
           
 int getMaxX()
           
 int getMaxY()
           
 int getMinX()
           
 int getMinY()
           
 byte[] getPixels()
           
 java.util.Collection<IPoint2D> getPoints()
           
 Polygon getPolygon()
           
 ListStream<Polygon> getStream()
          Used when calling in lazy mode.
 java.lang.String getStreamName()
          Really stream name but could be changed to _name.
protected abstract  byte handleProblematicPoints()
           
 boolean hasNext()
           
 void init()
          Cannot handle the last pixel at the edge, so for now just ignore it.
protected abstract  void internalFactory()
          All the objects that needs special version should be created here.
 boolean isPixelUsed(int pixelIndex)
          Not background and the used bit set to 0
protected abstract  boolean lastPixelOk(byte newDirection)
           
protected  void matchLines()
          This does really not belong in a vectorizer.
protected  void moveCurrentPointForwards(byte newDirection)
           
 Polygon next()
          Currently returns the cleaned up polygons.
static byte oppesiteDirection(byte direction)
           
 CPointInt pixelIndexToPoint(int pixelIndex)
           
 int pointToPixelIndex(int x, int y)
           
 int pointToPixelIndex(IPoint2D point)
           
protected  Polygon polygonFactory()
           
 void remove()
           
 void run()
           
 void setStreamName(java.lang.String name)
          Really stream name but could be changed to _name.
 
Methods inherited from class org.shapelogic.imageutil.BaseImageOperation
getGuiWrapper, getImage, getKeyValueParser, getSetupReturnValue, isImageValid, setArg, setGuiWrapper, setKeyValueParser, setSetupReturnValue, setup, showAbout, showMessage
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAX_DISTANCE_BETWEEN_CLUSTER_POINTS

public static final int MAX_DISTANCE_BETWEEN_CLUSTER_POINTS
See Also:
Constant Field Values

STRAIGHT_LINE_COLOR

public static final byte STRAIGHT_LINE_COLOR
See Also:
Constant Field Values

_pixels

protected byte[] _pixels

_minX

protected int _minX

_maxX

protected int _maxX

_minY

protected int _minY

_maxY

protected int _maxY

_cyclePoints

protected int[] _cyclePoints
What you need to add to the the index in the pixels array to get to the indexed point


_currentPoint

protected CPointInt _currentPoint
last point where you are


_firstPointInMultiLine

protected CPointInt _firstPointInMultiLine

_pixelTypeCalculator

protected PixelTypeCalculator _pixelTypeCalculator

_unfinishedPoints

protected java.util.ArrayList<CPointInt> _unfinishedPoints

_cleanedupPolygon

protected Polygon _cleanedupPolygon

_currentPixelIndex

protected int _currentPixelIndex
this is the index into the _pixels where the current point is


_currentDirection

protected byte _currentDirection

_numberOfPointsInAllLines

protected int _numberOfPointsInAllLines

_matchingOH

protected java.lang.Object _matchingOH

_errorMessage

protected java.lang.String _errorMessage

_endPointsClusters

protected java.util.List<java.util.Set<IPoint2D>> _endPointsClusters

_firstPointInLineIndex

protected int _firstPointInLineIndex

_pixelTypeFinder

protected IPixelTypeFinder _pixelTypeFinder

_rulesArrayForLetterMatching

protected NumericRule[] _rulesArrayForLetterMatching

_stream

protected ListStream<Polygon> _stream

_streamName

protected java.lang.String _streamName
Really stream name but could be changed to _name.


_yForUnporcessedPixel

protected int _yForUnporcessedPixel

_nextCount

protected int _nextCount

_displayInternalInfo

protected boolean _displayInternalInfo
Constructor Detail

BaseVectorizer

public BaseVectorizer()
Method Detail

run

public void run()
Specified by:
run in interface java.lang.Runnable

cleanPolygon

protected void cleanPolygon()

matchLines

protected void matchLines()
This does really not belong in a vectorizer.


findAllLines

protected void findAllLines()

findMultiLine

protected abstract void findMultiLine()

handleProblematicPoints

protected abstract byte handleProblematicPoints()

isPixelUsed

public boolean isPixelUsed(int pixelIndex)
Not background and the used bit set to 0


findPointType

public PixelTypeCalculator findPointType(int pixelIndex,
                                         PixelTypeCalculator reusedPixelTypeCalculator)
Specified by:
findPointType in interface IPixelTypeFinder

oppesiteDirection

public static byte oppesiteDirection(byte direction)

moveCurrentPointForwards

protected void moveCurrentPointForwards(byte newDirection)

lastPixelOk

protected abstract boolean lastPixelOk(byte newDirection)

init

public void init()
Cannot handle the last pixel at the edge, so for now just ignore it.


internalFactory

protected abstract void internalFactory()
All the objects that needs special version should be created here.


pointToPixelIndex

public int pointToPixelIndex(int x,
                             int y)

pointToPixelIndex

public int pointToPixelIndex(IPoint2D point)

pixelIndexToPoint

public CPointInt pixelIndexToPoint(int pixelIndex)

findFirstLinePoint

protected boolean findFirstLinePoint(boolean process)
Find first point that is not a unused foreground point.
XXX Currently start from the beginning if called multiple time, change that.


countRegionCrossingsAroundPoint

public int countRegionCrossingsAroundPoint(int pixelIndex)
A normal line has a crossing index of 4.


findMultiLinePostProcess

protected void findMultiLinePostProcess()
To be overridden. If I want to do more matching at the end.


findMultiLinePreProcess

protected boolean findMultiLinePreProcess()

addToUnfinishedPoints

protected void addToUnfinishedPoints(CPointInt newPoint)

drawLines

protected void drawLines()
Draws the vectorized lines on the original image for visual inspection.
This is probably not needed in the final version of this class.


getImageProcessor

public ij.process.ImageProcessor getImageProcessor()
Get an ImageJ ImageProcessor
This introduces dependency of ImageJ in a image processing algorithm, and should ideally be abstracted out.


getPoints

public java.util.Collection<IPoint2D> getPoints()

drawLine

protected void drawLine(CLine line)

polygonFactory

protected Polygon polygonFactory()

getPolygon

public Polygon getPolygon()

getStream

public ListStream<Polygon> getStream()
Description copied from interface: LazyPlugInFilter
Used when calling in lazy mode.

Specified by:
getStream in interface LazyPlugInFilter<Polygon>

hasNext

public boolean hasNext()
Specified by:
hasNext in interface java.util.Iterator<Polygon>

next

public Polygon next()
Currently returns the cleaned up polygons.

Specified by:
next in interface java.util.Iterator<Polygon>

remove

public void remove()
Specified by:
remove in interface java.util.Iterator<Polygon>

getMatchingOH

public java.lang.Object getMatchingOH()

getErrorMessage

public java.lang.String getErrorMessage()

getCleanedupPolygon

public Polygon getCleanedupPolygon()

getCyclePoints

public int[] getCyclePoints()
Description copied from interface: PixelJumperByte
What you need to add to the the index in the pixels array to get to the indexed point.

Specified by:
getCyclePoints in interface PixelJumperByte

getMaxX

public int getMaxX()
Specified by:
getMaxX in interface PixelJumperByte

getMaxY

public int getMaxY()
Specified by:
getMaxY in interface PixelJumperByte

getMinX

public int getMinX()
Specified by:
getMinX in interface PixelJumperByte

getMinY

public int getMinY()
Specified by:
getMinY in interface PixelJumperByte

getPixels

public byte[] getPixels()
Specified by:
getPixels in interface PixelJumperByte

getStreamName

public java.lang.String getStreamName()
Really stream name but could be changed to _name.

Specified by:
getStreamName in interface LazyPlugInFilter<Polygon>

setStreamName

public void setStreamName(java.lang.String name)
Really stream name but could be changed to _name.

Specified by:
setStreamName in interface LazyPlugInFilter<Polygon>


Copyright © 2009. All Rights Reserved.