slic
test_slic.cpp
Go to the documentation of this file.
1
/*
2
* test_slic.cpp.
3
*
4
* Written by: Pascal Mettes.
5
*
6
* This file creates an over-segmentation of a provided image based on the SLIC
7
* superpixel algorithm, as implemented in slic.h and slic.cpp.
8
*/
9
10
#include <stdio.h>
11
#include <
math.h
>
12
#include <vector>
13
#include <float.h>
14
using namespace
std
;
15
16
#include <opencv2/opencv.hpp>
17
#include "
slic.h
"
18
using namespace
cv
;
19
20
21
int
main
(
int
argc,
char
*argv[]) {
22
/* Load the image and convert to Lab colour space. */
23
Mat image = imread(
"dog.png"
, 1);
24
Mat lab_image;
25
cvtColor
(image, lab_image, COLOR_BGR2Lab);
26
27
/* Yield the number of superpixels and weight-factors from the user. */
28
int
w
= image.cols,
h
= image.rows;
29
int
nr_superpixels = 400;
30
int
nc = 40;
31
32
double
step
=
sqrt
((
w
*
h
) / (
double
) nr_superpixels);
33
34
/* Perform the SLIC superpixel algorithm. */
35
Slic
slic;
36
slic.
generate_superpixels
(lab_image,
int
(
step
), nc);
37
slic.
create_connectivity
(lab_image);
38
slic.
display_contours
(image, Vec3b(0,0,255));
39
40
/* Display the contours and show the result. */
41
imshow(
"result"
, image);
42
waitKey(0);
43
}
random_forest_client_sample.w
w
Definition:
random_forest_client_sample.py:106
Slic::create_connectivity
void create_connectivity(const cv::Mat &image)
Definition:
slic.cpp:195
main
int main(int argc, char *argv[])
Definition:
test_slic.cpp:21
step
unsigned int step
random_forest_client_sample.h
h
Definition:
random_forest_client_sample.py:106
Slic::generate_superpixels
void generate_superpixels(const cv::Mat &image, int step, int nc)
Definition:
slic.cpp:123
slic.h
math.h
Slic::display_contours
void display_contours(cv::Mat &image, cv::Vec3b colour)
Definition:
slic.cpp:270
sqrt
double sqrt()
Slic
Definition:
slic.h:38
std
cv
cvtColor
CvImagePtr cvtColor(const CvImageConstPtr &source, const std::string &encoding)
jsk_perception
Author(s): Manabu Saito, Ryohei Ueda
autogenerated on Fri May 16 2025 03:11:17