Repository navigation
Expand file tree
/
Copy pathdemo.cpp
More file actions
50 lines (47 loc) · 1.94 KB
/
Copy pathdemo.cpp
File metadata and controls
50 lines (47 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <string>
#include "SLIC.h"
int main()
{
int width(0), height(0);
// unsigned int (32 bits) to hold a pixel in ARGB format as follows:
// from left to right,
// the first 8 bits are for the alpha channel (and are ignored)
// the next 8 bits are for the red channel
// the next 8 bits are for the green channel
// the last 8 bits are for the blue channel
unsigned int* pbuff = new UINT[sz];
ReadImage(pbuff, width, height);//YOUR own function to read an image into the ARGB format
//----------------------------------
// Initialize parameters
//----------------------------------
int k = 200;//Desired number of superpixels.
double m = 20;//Compactness factor. use a value ranging from 10 to 40 depending on your needs. Default is 10
int* klabels = NULL;
int numlabels(0);
string filename = "yourfilename.jpg";
string savepath = "yourpathname";
//----------------------------------
// Perform SLIC on the image buffer
//----------------------------------
SLIC segment;
segment.DoSuperpixelSegmentation_ForGivenNumberOfSuperpixels(pbuff, width, height, klabels, numlabels, k, m);
// Alternately one can also use the function DoSuperpixelSegmentation_ForGivenStepSize() for a desired superpixel size
//----------------------------------
// Save the labels to a text file
//----------------------------------
segment.SaveSuperpixelLabels(klabels, width, height, filename, savepath);
//----------------------------------
// Draw boundaries around segments
//----------------------------------
segment.DrawContoursAroundSegments(pbuff, klabels, width, height, 0xff0000);
//----------------------------------
// Save the image with segment boundaries.
//----------------------------------
SaveSegmentedImageFile(pbuff, width, height);//YOUR own function to save an ARGB buffer as an image
//----------------------------------
// Clean up
//----------------------------------
if(pbuff) delete [] pbuff;
if(klabels) delete [] klabels;
return 0;
}