Class BinaryCrop
- java.lang.Object
-
- adams.core.logging.LoggingObject
-
- adams.core.logging.CustomLoggingLevelObject
-
- adams.core.option.AbstractOptionHandler
-
- adams.data.image.transformer.crop.AbstractCropAlgorithm
-
- adams.data.image.transformer.crop.BinaryCrop
-
- All Implemented Interfaces:
Destroyable
,GlobalInfoSupporter
,LoggingLevelHandler
,LoggingSupporter
,OptionHandler
,SizeOfHandler
,CropAlgorithm<BufferedImage>
,Serializable
public class BinaryCrop extends AbstractCropAlgorithm
Turns image into binary (ie black and white) image and determines the largest rectangle encompassing a (white) object in the middle to crop to.
When looking for a black object, check the 'invert' option.
-logging-level <OFF|SEVERE|WARNING|INFO|CONFIG|FINE|FINER|FINEST> (property: loggingLevel) The logging level for outputting errors and debugging output. default: WARNING
-image-transformer <adams.data.image.transformer.AbstractBufferedImageTransformer> (property: imageTransformer) The image transformer to apply to the image copy before further binarizing and determining the crop. default: adams.data.image.transformer.PassThrough
-num-check-points <int> (property: numCheckPoints) The number of check points (evenly distributed across width/height) to use for locating the smallest rectangle in the middle. default: 1 minimum: 1
-invert <boolean> (property: invert) If enabled, the algorithm looks for a black rectangle rather than a white one. default: false
- Author:
- fracpete (fracpete at waikato dot ac dot nz)
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected AbstractBufferedImageTransformer
m_ImageTransformer
the image transformer to apply to the image before cropping.protected boolean
m_Invert
whether to invert the check (ie look for black rectangle).protected int
m_NumCheckPoints
the number of checkpoints to use for determining minimum rectangle.-
Fields inherited from class adams.data.image.transformer.crop.AbstractCropAlgorithm
m_BottomRight, m_TopLeft
-
Fields inherited from class adams.core.option.AbstractOptionHandler
m_OptionManager
-
Fields inherited from class adams.core.logging.LoggingObject
m_Logger, m_LoggingIsEnabled, m_LoggingLevel
-
Fields inherited from interface adams.data.image.CropAlgorithm
CROP_BOTTOM, CROP_LEFT, CROP_RIGHT, CROP_TOP
-
-
Constructor Summary
Constructors Constructor Description BinaryCrop()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
defineOptions()
Adds options to the internal list of options.protected BufferedImage
doCrop(BufferedImage img)
Performs the actual cropping.AbstractBufferedImageTransformer
getImageTransformer()
Returns the image transformer to apply to the image copy before further binarizing and determining the crop.boolean
getInvert()
Returns whether to look for black rectangle (true) rather than white (false).int
getNumCheckPoints()
Returns the number of check points to use for determining smallest rectangle in the middle.String
globalInfo()
Returns a string describing the object.String
imageTransformerTipText()
Returns the tip text for this property.String
invertTipText()
Returns the tip text for this property.protected int
max(int[] values, int upperBound)
Finds the largest value that is smaller than the specified upper bound.protected int
min(int[] values, int lowerBound)
Finds the smallest value that is greater than the specified lower bound.String
numCheckPointsTipText()
Returns the tip text for this property.void
setImageTransformer(AbstractBufferedImageTransformer value)
Sets the image transformer to apply to the image copy before further binarizing and determining the crop.void
setInvert(boolean value)
Sets whether to look for black rectangle (true) rather than white (false).void
setNumCheckPoints(int value)
Sets the number of check points to use for determining smallest rectangle in the middle.-
Methods inherited from class adams.data.image.transformer.crop.AbstractCropAlgorithm
check, crop, getBottomRight, getTopLeft, postCrop, preCrop
-
Methods inherited from class adams.core.option.AbstractOptionHandler
cleanUpOptions, destroy, finishInit, getDefaultLoggingLevel, getOptionManager, initialize, loggingLevelTipText, newOptionManager, reset, setLoggingLevel, toCommandLine, toString
-
Methods inherited from class adams.core.logging.LoggingObject
configureLogger, getLogger, getLoggingLevel, initializeLogging, isLoggingEnabled, sizeOf
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface adams.core.logging.LoggingLevelHandler
getLoggingLevel
-
-
-
-
Field Detail
-
m_ImageTransformer
protected AbstractBufferedImageTransformer m_ImageTransformer
the image transformer to apply to the image before cropping.
-
m_NumCheckPoints
protected int m_NumCheckPoints
the number of checkpoints to use for determining minimum rectangle.
-
m_Invert
protected boolean m_Invert
whether to invert the check (ie look for black rectangle).
-
-
Method Detail
-
globalInfo
public String globalInfo()
Returns a string describing the object.- Specified by:
globalInfo
in interfaceGlobalInfoSupporter
- Specified by:
globalInfo
in classAbstractOptionHandler
- Returns:
- a description suitable for displaying in the gui
-
defineOptions
public void defineOptions()
Adds options to the internal list of options.- Specified by:
defineOptions
in interfaceOptionHandler
- Overrides:
defineOptions
in classAbstractOptionHandler
-
setImageTransformer
public void setImageTransformer(AbstractBufferedImageTransformer value)
Sets the image transformer to apply to the image copy before further binarizing and determining the crop.- Parameters:
value
- the transformer
-
getImageTransformer
public AbstractBufferedImageTransformer getImageTransformer()
Returns the image transformer to apply to the image copy before further binarizing and determining the crop.- Returns:
- the transformer
-
imageTransformerTipText
public String imageTransformerTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the gui
-
setNumCheckPoints
public void setNumCheckPoints(int value)
Sets the number of check points to use for determining smallest rectangle in the middle.- Parameters:
value
- the number
-
getNumCheckPoints
public int getNumCheckPoints()
Returns the number of check points to use for determining smallest rectangle in the middle.- Returns:
- the number
-
numCheckPointsTipText
public String numCheckPointsTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the gui
-
setInvert
public void setInvert(boolean value)
Sets whether to look for black rectangle (true) rather than white (false).- Parameters:
value
- true if to look for black rectangle
-
getInvert
public boolean getInvert()
Returns whether to look for black rectangle (true) rather than white (false).- Returns:
- true if to look for black rectangle
-
invertTipText
public String invertTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the gui
-
min
protected int min(int[] values, int lowerBound)
Finds the smallest value that is greater than the specified lower bound.- Parameters:
values
- the values to searchlowerBound
- the lower bound to use- Returns:
- the value, lower bound if failed to locate a value of at greater than lowerBound
-
max
protected int max(int[] values, int upperBound)
Finds the largest value that is smaller than the specified upper bound.- Parameters:
values
- the values to searchupperBound
- the upper bound to use- Returns:
- the value, defValue if failed to locate a value of smaller than upperBound
-
doCrop
protected BufferedImage doCrop(BufferedImage img)
Performs the actual cropping.- Specified by:
doCrop
in classAbstractCropAlgorithm
- Parameters:
img
- the image to crop- Returns:
- the (potentially) cropped image
-
-