Skip to content

Commit a5cc475

Browse files
authored
Merge pull request #3093 from scloke:master
* New superpixel algorithm (F-DBSCAN) Implementation of a new superpixel algorithm, "Accelerated superpixel image segmentation with a parallelized DBSCAN algorithm". * Update scansegment.hpp added newline at end of file * Update scansegment.cpp added newline at end of file * Update scansegment.cpp bug fixes * Update scansegment.cpp bug fixes * Update scansegment.hpp bug fixes * Update scansegment.cpp bug fixes * Update scansegment.hpp trailing whitespace removal * Update scansegment.cpp bug fixes * Update scansegment.cpp bug fixes * Update scansegment.cpp editing changes * Update scansegment.hpp editing changes * Update scansegment.hpp minor edits * Update scansegment.cpp bug fixes * Update scansegment.cpp inserted @addtogroup block * Update scansegment.cpp bug fixes * Update scansegment.hpp bug fixes * Update scansegment.hpp indents removed * Update scansegment.cpp extra indents removed * Update scansegment.cpp license agreement updated * Update scansegment.hpp license agreement updated * Update ximgproc.bib * Update scansegment.hpp reference moved to ximgproc.bib * Update scansegment.cpp reference moved to ximgproc.bib * Update scansegment.hpp c++ def removed * Update scansegment.hpp changed threads param * Update scansegment.cpp changed threads param * Update scansegment.cpp tab indents replaced with 4 spaces * Update scansegment.cpp bug fixes * Update scansegment.hpp removed trailing whitespace * Update scansegment.cpp replace malloc with autobuffer * Update scansegment.hpp updated header guard * Update scansegment.cpp bug fix * Update scansegment.cpp bug fixes * Update scansegment.cpp fixed process threads to the number of slices * Update scansegment.cpp bug fixes * Update scansegment.cpp C++ 11 lambdas used instead of cv::ParallelLoopBody * Update scansegment.cpp changed neighbours location buffer to array * Update scansegment.cpp remove whitespace * Update scansegment.cpp RAW pointers removed * Update scansegment.cpp bug fixes * ximgproc(ScanSegment): coding style, add smoke test * Update scansegment.hpp added citation * Update scansegment.cpp bug fixes
1 parent ebcc69c commit a5cc475

File tree

5 files changed

+898
-0
lines changed

5 files changed

+898
-0
lines changed

modules/ximgproc/doc/ximgproc.bib

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,3 +380,12 @@ @article{akinlar2013edcircles
380380
year={2013},
381381
publisher={Elsevier}
382382
}
383+
384+
@article{loke2021accelerated,
385+
title={Accelerated superpixel image segmentation with a parallelized DBSCAN algorithm},
386+
author={Loke, Seng Cheong and MacDonald, Bruce A and Parsons, Matthew and W{\"u}nsche, Burkhard Claus},
387+
journal={Journal of Real-Time Image Processing},
388+
pages={1--16},
389+
year={2021},
390+
publisher={Springer}
391+
}

modules/ximgproc/include/opencv2/ximgproc.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#include "ximgproc/structured_edge_detection.hpp"
4444
#include "ximgproc/edgeboxes.hpp"
4545
#include "ximgproc/edge_drawing.hpp"
46+
#include "ximgproc/scansegment.hpp"
4647
#include "ximgproc/seeds.hpp"
4748
#include "ximgproc/segmentation.hpp"
4849
#include "ximgproc/fast_hough_transform.hpp"
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
// This file is part of OpenCV project.
2+
// It is subject to the license terms in the LICENSE file found in the top-level directory
3+
// of this distribution and at http://opencv.org/license.html.
4+
//
5+
// Copyright (C) 2021, Dr Seng Cheong Loke ([email protected])
6+
7+
#ifndef __OPENCV_XIMGPROC_SCANSEGMENT_HPP__
8+
#define __OPENCV_XIMGPROC_SCANSEGMENT_HPP__
9+
10+
#include <opencv2/core.hpp>
11+
12+
namespace cv { namespace ximgproc {
13+
14+
/** @brief Class implementing the F-DBSCAN (Accelerated superpixel image segmentation with a parallelized DBSCAN algorithm) superpixels
15+
algorithm by Loke SC, et al. @cite loke2021accelerated for original paper.
16+
17+
The algorithm uses a parallelised DBSCAN cluster search that is resistant to noise, competitive in segmentation quality, and faster than
18+
existing superpixel segmentation methods. When tested on the Berkeley Segmentation Dataset, the average processing speed is 175 frames/s
19+
with a Boundary Recall of 0.797 and an Achievable Segmentation Accuracy of 0.944. The computational complexity is quadratic O(n2) and
20+
more suited to smaller images, but can still process a 2MP colour image faster than the SEEDS algorithm in OpenCV. The output is deterministic
21+
when the number of processing threads is fixed, and requires the source image to be in Lab colour format.
22+
*/
23+
class CV_EXPORTS_W ScanSegment : public Algorithm
24+
{
25+
public:
26+
virtual ~ScanSegment();
27+
28+
/** @brief Returns the actual superpixel segmentation from the last image processed using iterate.
29+
30+
Returns zero if no image has been processed.
31+
*/
32+
CV_WRAP virtual int getNumberOfSuperpixels() = 0;
33+
34+
/** @brief Calculates the superpixel segmentation on a given image with the initialized
35+
parameters in the ScanSegment object.
36+
37+
This function can be called again for other images without the need of initializing the algorithm with createScanSegment().
38+
This save the computational cost of allocating memory for all the structures of the algorithm.
39+
40+
@param img Input image. Supported format: CV_8UC3. Image size must match with the initialized
41+
image size with the function createScanSegment(). It MUST be in Lab color space.
42+
*/
43+
CV_WRAP virtual void iterate(InputArray img) = 0;
44+
45+
/** @brief Returns the segmentation labeling of the image.
46+
47+
Each label represents a superpixel, and each pixel is assigned to one superpixel label.
48+
49+
@param labels_out Return: A CV_32UC1 integer array containing the labels of the superpixel
50+
segmentation. The labels are in the range [0, getNumberOfSuperpixels()].
51+
*/
52+
CV_WRAP virtual void getLabels(OutputArray labels_out) = 0;
53+
54+
/** @brief Returns the mask of the superpixel segmentation stored in the ScanSegment object.
55+
56+
The function return the boundaries of the superpixel segmentation.
57+
58+
@param image Return: CV_8UC1 image mask where -1 indicates that the pixel is a superpixel border, and 0 otherwise.
59+
@param thick_line If false, the border is only one pixel wide, otherwise all pixels at the border are masked.
60+
*/
61+
CV_WRAP virtual void getLabelContourMask(OutputArray image, bool thick_line = false) = 0;
62+
};
63+
64+
/** @brief Initializes a ScanSegment object.
65+
66+
The function initializes a ScanSegment object for the input image. It stores the parameters of
67+
the image: image_width and image_height. It also sets the parameters of the F-DBSCAN superpixel
68+
algorithm, which are: num_superpixels, threads, and merge_small.
69+
70+
@param image_width Image width.
71+
@param image_height Image height.
72+
@param num_superpixels Desired number of superpixels. Note that the actual number may be smaller
73+
due to restrictions (depending on the image size). Use getNumberOfSuperpixels() to
74+
get the actual number.
75+
@param slices Number of processing threads for parallelisation. Setting -1 uses the maximum number
76+
of threads. In practice, four threads is enough for smaller images and eight threads for larger ones.
77+
@param merge_small merge small segments to give the desired number of superpixels. Processing is
78+
much faster without merging, but many small segments will be left in the image.
79+
*/
80+
CV_EXPORTS_W cv::Ptr<ScanSegment> createScanSegment(int image_width, int image_height, int num_superpixels, int slices = 8, bool merge_small = true);
81+
82+
}} // namespace
83+
#endif

0 commit comments

Comments
 (0)