|
Beatmup
|
Flood fill algorithm implementation. More...
#include <flood_fill.h>
Public Types | |
| enum | BorderMorphology { NONE = 0 , DILATE , ERODE } |
| Morphological postprocessing operation applied to discovered connected components. More... | |
Public Types inherited from Beatmup::AbstractTask | |
| enum class | TaskDeviceRequirement { CPU_ONLY , GPU_OR_CPU , GPU_ONLY } |
| Specifies which device (CPU and/or GPU) is used to run the task. More... | |
Public Member Functions | |
| FloodFill () | |
| ~FloodFill () | |
| const AbstractBitmap * | getInput () const |
| Returns input bitmap (null if not set yet) More... | |
| const AbstractBitmap * | getOutput () const |
| Returns output bitmap (null if not set yet) More... | |
| IntRectangle | getBounds () const |
| Returns bounding box of the computed mask. More... | |
| int | getContourCount () const |
| Returns number of detected contours. More... | |
| const IntegerContour2D & | getContour (int contourIndex) const |
Returns a contour by index if computeContours was true, throws an exception otherwise. More... | |
| void | setInput (AbstractBitmap *) |
| Sets the input bitmap. More... | |
| void | setOutput (AbstractBitmap *) |
| Specifies the bitmap to put the resulting mask to. More... | |
| void | setMaskPos (const IntPoint &) |
| Specifies left-top corner position of the mask to compute inside the input bitmap. More... | |
| void | setSeeds (const IntPoint seeds[], int seedCount) |
| Specifies a set of seeds (starting points) More... | |
| void | setSeeds (const int seedsXY[], int seedCount) |
| void | setTolerance (float) |
| Sets the intensity tolerance threshold used to decide on similarity of neighboring pixels. More... | |
| float | getTolerance () const |
| Returns yjr intensity tolerance threshold. More... | |
| void | setBorderPostprocessing (BorderMorphology operation, float holdRadius, float releaseRadius) |
| Specifies a morphological operation to apply to the mask border. More... | |
| void | setComputeContours (bool) |
| Enables or disables contours computation. More... | |
| ThreadIndex | getMaxThreads () const |
| Gives the upper limint on the number of threads the task may be performed by. More... | |
| virtual bool | process (TaskThread &thread) final |
| Executes the task on CPU within a given thread. More... | |
| virtual void | beforeProcessing (ThreadIndex threadCount, ProcessingTarget target, GraphicPipeline *gpu) final |
| Instruction called before the task is executed. More... | |
| virtual void | afterProcessing (ThreadIndex threadCount, GraphicPipeline *gpu, bool aborted) final |
| Instruction called after the task is executed. More... | |
Public Member Functions inherited from Beatmup::AbstractTask | |
| virtual bool | processOnGPU (GraphicPipeline &gpu, TaskThread &thread) |
| Executes the task on GPU. More... | |
| virtual TaskDeviceRequirement | getUsedDevices () const |
| Communicates devices (CPU and/or GPU) the task is run on. More... | |
Public Member Functions inherited from Beatmup::Object | |
| virtual | ~Object () |
Protected Attributes | |
| AbstractBitmap * | input |
| input bitmap More... | |
| AbstractBitmap * | output |
| resulting mask More... | |
| AbstractBitmap * | ignoredSeeds |
| 1-bit bitmap storing flags marking used pixels More... | |
| IntPoint | maskPos |
| left-top corner of the mask to compute over the input bitmap More... | |
| IntRectangle | bounds |
| mask bounds More... | |
| std::mutex | access |
| access control assuring internal thread safety More... | |
| std::vector< IntPoint > | seeds |
| set of starting points (seed points) More... | |
| std::vector< IntegerContour2D * > | contours |
| contours to store borders for each seed More... | |
| BorderMorphology | borderMorphology |
| border morphological postprocessing More... | |
| float | tolerance |
| intensity tolerance value More... | |
| float | borderHold |
| float | borderRelease |
| bool | computeContours |
if true, border contours will be computed per each seed More... | |
Additional Inherited Members | |
Static Public Member Functions inherited from Beatmup::AbstractTask | |
| static ThreadIndex | validThreadCount (int number) |
| Valid thread count from a given integer value. More... | |
Private Member Functions inherited from Beatmup::BitmapContentLock | |
| BitmapContentLock () | |
| ~BitmapContentLock () | |
| void | readLock (GraphicPipeline *gpu, AbstractBitmap *bitmap, ProcessingTarget target) |
| Locks content of a bitmap for reading using a specific processing target device. More... | |
| void | writeLock (GraphicPipeline *gpu, AbstractBitmap *bitmap, ProcessingTarget target) |
| Locks content of a bitmap for writing using a specific processing target device. More... | |
| void | unlock (AbstractBitmap *bitmap) |
| Drops a lock to the bitmap. More... | |
| void | unlockAll () |
| Unlocks all the locked bitmaps unconditionally. More... | |
| template<const ProcessingTarget target> | |
| void | lock (GraphicPipeline *gpu, AbstractBitmap *input, AbstractBitmap *output) |
| void | lock (GraphicPipeline *gpu, ProcessingTarget target, AbstractBitmap *input, AbstractBitmap *output) |
| template<const ProcessingTarget target> | |
| void | lock (GraphicPipeline *gpu, std::initializer_list< AbstractBitmap * > read, std::initializer_list< AbstractBitmap * > write) |
| template<typename ... Args> | |
| void | unlock (AbstractBitmap *first, Args ... others) |
Flood fill algorithm implementation.
Discovers areas of similar colors up to a tolerance threshold around given positions (seeds) in the input image. These areas are filled with white color in another image (output). If the output bitmap is a binary mask, corresponding pixels are set to 1. The rest of the output image remains unchanged. Optionally, computes contours around the discovered areas and stores the contour positions. Also optionally, applies post-processing by dilating or eroding the discovered regions in the output image.
Definition at line 36 of file flood_fill.h.
Morphological postprocessing operation applied to discovered connected components.
| Enumerator | |
|---|---|
| NONE | no postprocessing |
| DILATE | apply a dilatation |
| ERODE | apply an erosion |
Definition at line 41 of file flood_fill.h.
| FloodFill::FloodFill | ( | ) |
Definition at line 28 of file flood_fill.cpp.
| FloodFill::~FloodFill | ( | ) |
Definition at line 33 of file flood_fill.cpp.
|
inline |
|
inline |
|
inline |
|
inline |
| const IntegerContour2D & FloodFill::getContour | ( | int | contourIndex | ) | const |
Returns a contour by index if computeContours was true, throws an exception otherwise.
Definition at line 173 of file flood_fill.cpp.
| void FloodFill::setInput | ( | AbstractBitmap * | inputBitmap | ) |
Sets the input bitmap.
Definition at line 41 of file flood_fill.cpp.
| void FloodFill::setOutput | ( | AbstractBitmap * | mask | ) |
Specifies the bitmap to put the resulting mask to.
Definition at line 46 of file flood_fill.cpp.
| void FloodFill::setMaskPos | ( | const IntPoint & | pos | ) |
Specifies left-top corner position of the mask to compute inside the input bitmap.
Definition at line 51 of file flood_fill.cpp.
| void FloodFill::setSeeds | ( | const IntPoint | seeds[], |
| int | seedCount | ||
| ) |
Specifies a set of seeds (starting points)
Definition at line 56 of file flood_fill.cpp.
| void FloodFill::setSeeds | ( | const int | seedsXY[], |
| int | seedCount | ||
| ) |
| void FloodFill::setTolerance | ( | float | tolerance | ) |
Sets the intensity tolerance threshold used to decide on similarity of neighboring pixels.
Definition at line 161 of file flood_fill.cpp.
|
inline |
| void FloodFill::setBorderPostprocessing | ( | BorderMorphology | operation, |
| float | holdRadius, | ||
| float | releaseRadius | ||
| ) |
Specifies a morphological operation to apply to the mask border.
| operation | A postprocessing operation |
| holdRadius | Erosion/dilation hold radius (output values set to 1) |
| releaseRadius | Erosion/dilation radius of transition from 1 to 0 |
Definition at line 166 of file flood_fill.cpp.
| void FloodFill::setComputeContours | ( | bool | compute | ) |
Enables or disables contours computation.
Definition at line 70 of file flood_fill.cpp.
|
virtual |
Gives the upper limint on the number of threads the task may be performed by.
The actual number of threads running a specific task may be less or equal to the returned value, depending on the number of workers in ThreadPool running the task.
Reimplemented from Beatmup::AbstractTask.
Definition at line 75 of file flood_fill.cpp.
|
finalvirtual |
Executes the task on CPU within a given thread.
Generally called by multiple threads.
| thread | associated task execution context |
true if the execution is finished correctly, false otherwise Implements Beatmup::AbstractTask.
Definition at line 80 of file flood_fill.cpp.
|
finalvirtual |
Instruction called before the task is executed.
| threadCount | Number of threads used to perform the task |
| target | Device used to perform the task |
| gpu | A graphic pipeline instance; may be null. |
Reimplemented from Beatmup::AbstractTask.
Definition at line 136 of file flood_fill.cpp.
|
finalvirtual |
Instruction called after the task is executed.
| threadCount | Number of threads used to perform the task |
| gpu | GPU to be used to execute the task; may be null. |
| aborted | true if the task was aborted |
Reimplemented from Beatmup::AbstractTask.
Definition at line 152 of file flood_fill.cpp.
|
protected |
input bitmap
Definition at line 49 of file flood_fill.h.
|
protected |
resulting mask
Definition at line 50 of file flood_fill.h.
|
protected |
1-bit bitmap storing flags marking used pixels
Definition at line 51 of file flood_fill.h.
|
protected |
left-top corner of the mask to compute over the input bitmap
Definition at line 53 of file flood_fill.h.
|
protected |
mask bounds
Definition at line 54 of file flood_fill.h.
|
protected |
access control assuring internal thread safety
Definition at line 55 of file flood_fill.h.
|
protected |
set of starting points (seed points)
Definition at line 56 of file flood_fill.h.
|
protected |
contours to store borders for each seed
Definition at line 57 of file flood_fill.h.
|
protected |
border morphological postprocessing
Definition at line 58 of file flood_fill.h.
|
protected |
intensity tolerance value
Definition at line 60 of file flood_fill.h.
|
protected |
Definition at line 62 of file flood_fill.h.
|
protected |
Definition at line 63 of file flood_fill.h.
|
protected |
if true, border contours will be computed per each seed
Definition at line 64 of file flood_fill.h.