Skip to content

Commit 9faa101

Browse files
committed
Add tutorial
1 parent 87ce7bb commit 9faa101

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

examples/tutorial.cc

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// Include the header-only library.
2+
#include <vpp/vpp.hh>
3+
4+
int main()
5+
{
6+
// import vpp into the current namespace.
7+
using vpp;
8+
9+
10+
typedef vuchar3 V; // value type.
11+
typedef image2d<vuchar3> I; // image type.
12+
13+
// Declare a 2d image.
14+
I img;
15+
16+
// Load an external image using opencv.
17+
img = from_opencv<V>(cv::imread("image.jpg"));
18+
19+
// Allocate a second image with the same definition domain.
20+
I out(img.domain());
21+
22+
// Iterate on img
23+
for (auto pix : img) *pix = *pix * 2;
24+
25+
// 3x3 box filter on img
26+
window<I> row_win(img, {[0, -1], [0, 0], [0, 1]});
27+
28+
pixel_wise(img, out) << [&] (auto in, auto out)
29+
{
30+
V sum = V::Zero();
31+
for (auto n : row_win(in)) sum += *n;
32+
*out = sum / 3;
33+
};
34+
35+
int nr = img.nrows();
36+
row_wise(img, out) << [&] (auto in, auto out)
37+
{
38+
for (int c = 0; c < nr; c++)
39+
{
40+
vuchar3 sum = vuchar3::Zero();
41+
for (auto n : row_win(in)) sum += *n;
42+
*out = sum / 3;
43+
44+
out++;
45+
in++;
46+
}
47+
};
48+
49+
int dims[] = {100, 200};
50+
imageNd<int, 2> img(dims);
51+
52+
}

0 commit comments

Comments
 (0)