]>
git.sthu.org Git - libstick.git/blob - include/libstick-0.1/image.h
1 #ifndef image_h_uiHiKahYooroomai
2 #define image_h_uiHiKahYooroomai
4 #include "simplicialcomplex.h"
9 /** We consider an image, i.e. a rectangular arrangement of pixels, of given
10 * height and width. Every pixel has a specific value (e.g., grey value) given
11 * by the 'values' array as concatenation of all rows. We add every pixel as
12 * vertex with its value as simplex value. We further triangulate the resulting
13 * rectangular latice as a grid graph together with south-west to north-east
14 * edges for each of the small squares of the grid graph. Finally the resulting
15 * triangles are added. For all non-vertex simplices the maximum of its
16 * vertex-values is used as its value. The first pixel is considered to be at
18 template<class VT
, class IT
>
19 void add_image_to_complex(simplicial_complex
<2, IT
, VT
> &s
, const VT
*values
, size_t width
, size_t height
) {
21 const IT v1st
= s
.size();
22 for (unsigned i
=0; i
< height
; ++i
)
23 for (unsigned j
=0; j
< width
; ++j
)
24 s
.add_simplex(0, NULL
, values
[i
*width
+ j
]);
40 // Adding horizontal edges
41 const IT he1st
= s
.size();
42 for (unsigned i
=0; i
< height
; ++i
)
43 for (unsigned j
=0; j
< width
-1; ++j
) {
44 faces
[0] = v1st
+ i
*width
+ j
;
45 faces
[1] = faces
[0] + 1;
46 s
.add_simplex(1, faces
);
49 // Adding vertical edges
50 const IT ve1st
= s
.size();
51 for (unsigned i
=0; i
< height
-1; ++i
)
52 for (unsigned j
=0; j
< width
; ++j
) {
53 faces
[0] = v1st
+ i
*width
+ j
;
54 faces
[1] = faces
[0] + width
;
55 s
.add_simplex(1, faces
);
58 // Adding diagonal edges
59 const IT de1st
= s
.size();
60 for (unsigned i
=0; i
< height
-1; ++i
)
61 for (unsigned j
=0; j
< width
-1; ++j
) {
62 faces
[0] = v1st
+ i
*width
+ j
;
63 faces
[1] = faces
[0] + width
+ 1;
64 s
.add_simplex(1, faces
);
68 for (unsigned i
=0; i
< height
-1; ++i
)
69 for (unsigned j
=0; j
< width
-1; ++j
) {
70 faces
[0] = he1st
+ i
*(width
-1) + j
;
71 faces
[1] = ve1st
+ i
*width
+ j
+ 1;
72 faces
[2] = de1st
+ i
*(width
-1) + j
;
73 s
.add_simplex(2, faces
);
75 faces
[0] = he1st
+ (i
+1)*(width
-1) + j
;
76 faces
[1] = ve1st
+ i
*width
+ j
;
77 faces
[2] = de1st
+ i
*(width
-1) + j
;
78 s
.add_simplex(2, faces
);