classPiiThresholdingOperation
#include <PiiThresholdingOperation.h>
A threshold operation with one threshold value.
Inherits PiiDefaultOperation
Description
Input image must be grayscale image and output image has same type as input image, but value of the output image can only be 0 or 1.
Inputs
HysteresisThreshold is used. In this case the input will be used as the upper threshold, absoluteThreshold will be ignored and relativeThreshold will be added to the input to get the lower threshold. Outputs
HysteresisThreshold is in use, the output will always be a PiiMatrix<int>. double) Properties
|
double
|
Absolute threshold. |
|
bool
|
Inversion flag. |
|
double
|
Relative threshold. |
|
How to determine the threshold. |
|
|
The size of a local window for adaptive treshold calculation. |
Public types
|
enum
|
{
StaticThreshold, OtsuThreshold, RelativeToMeanThreshold, RelativeToMinThreshold, RelativeToMaxThreshold, MeanStdThreshold, PercentageThreshold, TwoLevelThreshold, HysteresisThreshold, RelativeToMeanAdaptiveThreshold, MeanStdAdaptiveThreshold, SauvolaAdaptiveThreshold
}
Supported threshold calculation techniques. |
Constructors and destructor
Public member functions
|
double
|
|
|
virtual void
|
(
Checks the operation for execution. |
|
bool
|
(
)
|
|
double
|
|
|
void
|
(
|
|
void
|
(
|
|
void
|
(
|
|
void
|
|
|
void
|
|
|
(
)
|
|
|
(
)
|
Protected member functions
|
virtual void
|
(
)
Executes one round of processing. |
Property details
-
double absoluteThreshold
[read, write]Absolute threshold.
The effect of this value is affected by thresholdType. Default value is 0.
-
bool inverse
[read, write]Inversion flag.
If this value is set to
true, the result will be inverted. In all cases but withHysteresisThresholdthe "inverted" result will be same as the normal thresholding result except that zeros and ones are exchanged. See PiiImage::inverseHysteresisThreshold() for details on hysteresis thresholding. -
double relativeThreshold
[read, write]Relative threshold.
The effect of this value is affected by thresholdType. Default value is 1.0.
-
ThresholdType thresholdType
[read, write]How to determine the threshold.
Default is
StaticThreshold. This value has no effect if the threshold input is connected. -
QSize windowSize
[read, write]The size of a local window for adaptive treshold calculation.
The default is 15-by-15.
Enumeration details
-
enum ThresholdType
Supported threshold calculation techniques.
StaticThreshold- the gray levels are thresholded using absoluteThreshold as such. relativeThreshold will be ignored.OtsuThreshold- initial threshold value is automatically determined from histogram of the input image with the Otsu method. The initial value will be multiplied by relativeThreshold, and absoluteThreshold will be added to the resulting value before applying the operation. This thresholding technique works only if the gray levels are quantized. Floating point input will be rounded to integers, and the result will most likely be totally black.RelativeToMeanThreshold- the threshold is calculated by multiplying the mean gray level of the input image by relativeThreshold and adding absoluteThreshold to the result.RelativeToMaxThreshold- the threshold is calculated by multiplying the maximum gray level of the input image by relativeThreshold and adding absoluteThreshold to the result.RelativeToMinThreshold- the threshold is calculated by multiplying the minimum gray level of the input image by relativeThreshold and adding absoluteThreshold to the result.MeanStdThreshold- the threshold is calculated by adding relativeThreshold times the standard deviation of the input gray levels to the mean gray level. absoluteThreshold will be added to the result.PercentageThreshold- The image will be thresholded so that a fixed fraction of pixels will always be ones. If relativeThreshold is set to 0.7, 30 % of pixels will be ones etc. absoluteThreshold will be added to the result. This thresholding technique works only if the gray levels are quantized. Floating point input will be rounded to integers, and the result will most likely be totally black.TwoLevelThreshold- Everything between absoluteThreshold and absoluteThreshold + relativeThreshold (inclusive) will be set to one. Thethresholdoutput will emit the value of absoluteThreshold.HysteresisThreshold- absoluteThreshold will be used as an upper threshold. All pixels with a gray level higher than this value will work as seeds. The result will contain all pixels with a gray level higher than absoluteThreshold - relativeThreshold that are connected to at least one seed pixel. Thethresholdoutput will emit the value of absoluteThreshold. Thethresholdinput will be ignored.RelativeToMeanAdaptiveThreshold- same asRelativeToMeanThreshold, but the threshold is calculated separately for each pixel in a local window. The size of the local window is determined by windowSize. Thethresholdoutput will emit the value of absoluteThreshold. Thethresholdinput will be ignored.MeanStdAdaptiveThreshold- same asMeanStdThreshold, but the threshold is calculated separately for each pixel in a local window. The size of the local window is determined by windowSize. Thethresholdoutput will emit the value of absoluteThreshold. Thethresholdinput will be ignored.SauvolaAdaptiveThreshold- and adaptive thresholding technique that takes local variance into account. The local threshold t is calculated as
, where r stands for relativeThreshold, a for absoluteThreshold, and
for the maximum possible standard deviation, which is assumed to be 128 for integer-typed images and 0.5 for floating-point types. In document image binarization, a good value for relativeThreshold is 0.34. absoluteThreshold is typically zero. The thresholdoutput will emit the value of absoluteThreshold. Thethresholdinput will be ignored.
Function details
-
PiiThresholdingOperation
() -
double absoluteThreshold
() -
virtual void check
(- bool reset
[virtual]Checks the operation for execution.
This function creates a suitable flow controller by calling createFlowController(). It then sets the flow controller to the active processor and sets the processor as the input controller for all inputs.
If you change socket groupings in your overridden implementation, please call PiiDefaultOperation::check() after that. Otherwise, your new groupings will not be in effect.
Reimplemented from PiiDefaultOperation.
-
bool isInverse
() -
double relativeThreshold
() -
void setAbsoluteThreshold
(- double absoluteThreshold
-
void setInverse
(- bool inverse
-
void setRelativeThreshold
(- double relativeThreshold
-
void setThresholdType
-
void setWindowSize
-
ThresholdType thresholdType
() -
QSize windowSize
() -
virtual void process
()[protected, virtual]Executes one round of processing.
This function is invoked by the processor if the necessary preconditions for a new processing round are met. This function does all the necessary calculations to create output objects and sends them to output sockets.
Calls to process(), syncEvent(), and setProperty() are synchronized and cannot occur simultaneously. PiiDefaultOperation ensures this by locking processLock() for reading before calling process().
Note: With time-consuming operations, one should occasionally check that the operation hasn't been interrupted, i.e. that state() returns
Running.Exceptions
- PiiExecutionException
whenever an unrecoverable error occurs during a processing round, the operation is interrupted, or finishes execution due to end of input data.
Reimplemented from PiiDefaultOperation.
Add a note
Not a single note added yet. Be the first, add yours.