Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
68ece0e
New superpixel algorithm (F-DBSCAN)
scloke Oct 31, 2021
79f8436
Update scansegment.hpp
scloke Oct 31, 2021
3e6aaae
Update scansegment.cpp
scloke Oct 31, 2021
5d8616e
Update scansegment.cpp
scloke Oct 31, 2021
d74bde5
Update scansegment.cpp
scloke Nov 1, 2021
9dfe150
Update scansegment.hpp
scloke Nov 1, 2021
3e4f25d
Update scansegment.cpp
scloke Nov 1, 2021
5a2e153
Update scansegment.hpp
scloke Nov 1, 2021
7130d25
Update scansegment.cpp
scloke Nov 1, 2021
ee702c6
Update scansegment.cpp
scloke Nov 1, 2021
c4155b0
Update scansegment.cpp
scloke Nov 1, 2021
ec78937
Update scansegment.hpp
scloke Nov 1, 2021
4de0e31
Update scansegment.hpp
scloke Nov 1, 2021
c6a918c
Update scansegment.cpp
scloke Nov 3, 2021
67d9143
Update scansegment.cpp
scloke Nov 3, 2021
0fbdc2f
Update scansegment.cpp
scloke Nov 3, 2021
74c6cf5
Update scansegment.hpp
scloke Nov 3, 2021
650f9c4
Update scansegment.hpp
scloke Nov 10, 2021
e0a4048
Update scansegment.cpp
scloke Nov 10, 2021
a968096
Update scansegment.cpp
scloke Nov 10, 2021
d98fa2c
Update scansegment.hpp
scloke Nov 10, 2021
a2bdd04
Update ximgproc.bib
scloke Nov 10, 2021
0b3bfe4
Update scansegment.hpp
scloke Nov 10, 2021
a2d5fe8
Update scansegment.cpp
scloke Nov 10, 2021
5e950ee
Update scansegment.hpp
scloke Nov 10, 2021
d092203
Update scansegment.hpp
scloke Nov 10, 2021
86521fc
Update scansegment.cpp
scloke Nov 10, 2021
bcbfdc3
Update scansegment.cpp
scloke Nov 10, 2021
c64cbf6
Update scansegment.cpp
scloke Nov 10, 2021
56112ad
Update scansegment.hpp
scloke Nov 10, 2021
a048792
Update scansegment.cpp
scloke Nov 10, 2021
f106c54
Update scansegment.hpp
scloke Nov 10, 2021
6635ef2
Update scansegment.cpp
scloke Nov 10, 2021
e9413ad
Update scansegment.cpp
scloke Nov 10, 2021
8e86fc0
Update scansegment.cpp
scloke Nov 19, 2021
ab87fa1
Update scansegment.cpp
scloke Nov 21, 2021
1b586b3
Update scansegment.cpp
scloke Nov 21, 2021
a766bb4
Update scansegment.cpp
scloke Nov 22, 2021
67fa9e5
Update scansegment.cpp
scloke Nov 22, 2021
2234e6a
Update scansegment.cpp
scloke Nov 24, 2021
3f398a5
Update scansegment.cpp
scloke Nov 24, 2021
8b132b5
ximgproc(ScanSegment): coding style, add smoke test
alalek Nov 28, 2021
30e7b5b
Update scansegment.hpp
scloke Nov 29, 2021
acc879b
Update scansegment.cpp
scloke Nov 29, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions modules/ximgproc/doc/ximgproc.bib
Original file line number Diff line number Diff line change
Expand Up @@ -380,3 +380,12 @@ @article{akinlar2013edcircles
year={2013},
publisher={Elsevier}
}

@article{loke2021accelerated,
title={Accelerated superpixel image segmentation with a parallelized DBSCAN algorithm},
author={Loke, Seng Cheong and MacDonald, Bruce A and Parsons, Matthew and W{\"u}nsche, Burkhard Claus},
journal={Journal of Real-Time Image Processing},
pages={1--16},
year={2021},
publisher={Springer}
}
1 change: 1 addition & 0 deletions modules/ximgproc/include/opencv2/ximgproc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include "ximgproc/structured_edge_detection.hpp"
#include "ximgproc/edgeboxes.hpp"
#include "ximgproc/edge_drawing.hpp"
#include "ximgproc/scansegment.hpp"
#include "ximgproc/seeds.hpp"
#include "ximgproc/segmentation.hpp"
#include "ximgproc/fast_hough_transform.hpp"
Expand Down
83 changes: 83 additions & 0 deletions modules/ximgproc/include/opencv2/ximgproc/scansegment.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.
//
// Copyright (C) 2021, Dr Seng Cheong Loke ([email protected])

#ifndef __OPENCV_XIMGPROC_SCANSEGMENT_HPP__
#define __OPENCV_XIMGPROC_SCANSEGMENT_HPP__

#include <opencv2/core.hpp>

namespace cv { namespace ximgproc {

/** @brief Class implementing the F-DBSCAN (Accelerated superpixel image segmentation with a parallelized DBSCAN algorithm) superpixels
algorithm by Loke SC, et al. @cite loke2021accelerated for original paper.

The algorithm uses a parallelised DBSCAN cluster search that is resistant to noise, competitive in segmentation quality, and faster than
existing superpixel segmentation methods. When tested on the Berkeley Segmentation Dataset, the average processing speed is 175 frames/s
with a Boundary Recall of 0.797 and an Achievable Segmentation Accuracy of 0.944. The computational complexity is quadratic O(n2) and
more suited to smaller images, but can still process a 2MP colour image faster than the SEEDS algorithm in OpenCV. The output is deterministic
when the number of processing threads is fixed, and requires the source image to be in Lab colour format.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add @cite loke2021accelerated in this documentation section.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added.

*/
class CV_EXPORTS_W ScanSegment : public Algorithm
{
public:
virtual ~ScanSegment();

/** @brief Returns the actual superpixel segmentation from the last image processed using iterate.

Returns zero if no image has been processed.
*/
CV_WRAP virtual int getNumberOfSuperpixels() = 0;

/** @brief Calculates the superpixel segmentation on a given image with the initialized
parameters in the ScanSegment object.

This function can be called again for other images without the need of initializing the algorithm with createScanSegment().
This save the computational cost of allocating memory for all the structures of the algorithm.

@param img Input image. Supported format: CV_8UC3. Image size must match with the initialized
image size with the function createScanSegment(). It MUST be in Lab color space.
*/
CV_WRAP virtual void iterate(InputArray img) = 0;

/** @brief Returns the segmentation labeling of the image.

Each label represents a superpixel, and each pixel is assigned to one superpixel label.

@param labels_out Return: A CV_32UC1 integer array containing the labels of the superpixel
segmentation. The labels are in the range [0, getNumberOfSuperpixels()].
*/
CV_WRAP virtual void getLabels(OutputArray labels_out) = 0;

/** @brief Returns the mask of the superpixel segmentation stored in the ScanSegment object.

The function return the boundaries of the superpixel segmentation.

@param image Return: CV_8UC1 image mask where -1 indicates that the pixel is a superpixel border, and 0 otherwise.
@param thick_line If false, the border is only one pixel wide, otherwise all pixels at the border are masked.
*/
CV_WRAP virtual void getLabelContourMask(OutputArray image, bool thick_line = false) = 0;
};

/** @brief Initializes a ScanSegment object.

The function initializes a ScanSegment object for the input image. It stores the parameters of
the image: image_width and image_height. It also sets the parameters of the F-DBSCAN superpixel
algorithm, which are: num_superpixels, threads, and merge_small.

@param image_width Image width.
@param image_height Image height.
Comment on lines +70 to +71
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW, prefer to use Size image_size instead of 2 dedicated values

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking of this also, but in the end I went with following the pattern in createSuperpixelSEEDS which used two dedicated values. If you prefer cv::Size, let me know and I will change.

@param num_superpixels Desired number of superpixels. Note that the actual number may be smaller
due to restrictions (depending on the image size). Use getNumberOfSuperpixels() to
get the actual number.
@param slices Number of processing threads for parallelisation. Setting -1 uses the maximum number
of threads. In practice, four threads is enough for smaller images and eight threads for larger ones.
@param merge_small merge small segments to give the desired number of superpixels. Processing is
much faster without merging, but many small segments will be left in the image.
*/
CV_EXPORTS_W cv::Ptr<ScanSegment> createScanSegment(int image_width, int image_height, int num_superpixels, int slices = 8, bool merge_small = true);

}} // namespace
#endif
Loading