[ VIGRA Homepage | Function Index | Class Index | Namespaces | File List | Main Page ]

features.hxx
1#ifndef RN_FEATURES_HXX
2#define RN_FEATURES_HXX
3
4
5
6
7
8class FeatureBase
9{
10public:
11 MultiArrayShape<2>::type shape() = 0;
12 int shape(int index)
13 {
14 return shape()[index];
15 }
16 double & operator() (int i, int j) = 0;
17};
18
19
20class CompositFeatures : public FeatureBase
21{
22public:
23 typedef typename MultiArrayShape<2>::type
24 Shp;
25 ArrayVector<Shp>
26 ext2int;
27 ArrayVector<FeatureBase > sub_feats;
28 void add(FeatureBase & feat)
29 {
30 if(feat.shape(0) != this->shape(0))
31 throw std::runtime_error("Wrong Number Of samples");
32
33 sub_feats.push_back(feat);
34 for(int ii = 0; ii < feat.shape(1); ++ii)
35 ext2int.push_back(Shp(sub_feats.size()-1,
36 ii));
37
38 }
39
40 MultiArrayShape<2>::type shape()
41 {
42 return MultiArrayShape<2>::type(sub_feats[0].shape(0),
43 ext2int.size());
44 }
45
46 double & operator() (int i, int j)
47 {
48 return sub_feats[ext2int[j][0]](i, ext2int[j][1]);
49 }
50};
51
52template<int N, class T, class C>
53class NeighborFeatures : public FeatureBase
54{
55public:
56 typedef typename MultiArrayShape<N>::type Shp;
57 MultiArrayView<N, T, C> raw_data;
58 ArrayVector<Shp >
59 feat_coos;
60 MultiArrayShape<2>::type shape()
61 {
62 return MultiArrayShape<2>::type(raw_data.size(),
63 feat_coos.size());
64 }
65
66 double & operator() (int i, int j)
67 {
68 return raw_data(raw_data.scanOrderIndexToCoordinate(i) + feat_coos(j));
69 }
70 NeighborFeatures(MultiArrayView<N, T, C> & in, MultiArrayView<2, int> const & coos)
71 : raw_data(in)
72 {
73 for(int ii = 0; ii < coos.shape(0); ++ii)
74 feat_coos.push_back(Shp());
75 for(int jj = 0; jj < coos.shape(1); ++jj)
76 feat_coos.back()[jj] = coos(ii, jj);
77 }
78
79};
80
81
82class BindFeatureColumn : public FeatureBase
83{
84 typedef typename MultiArrayShape<N>::type Shp;
85 int index;
86 FeatureBase & underlying;
87
88 MultiArrayShape<2>::type shape()
89 {
90 return MultiArrayShape<2>::type(underlying.shape(0), 1);
91 }
92
93 double & operator() (int i, int j)
94 {
95 return underlying(i, index);
96 }
97 double & operator[](int i)
98 {
99 return underlying(i, index);
100 }
101
102 BindFeatureColumn(FeaetureBase & in, int index_)
103 : index(index_), underlying(in)
104 {
105 ;
106 }
107};
108
109FeatureBase columnVector(FeatureBase & in, int ii)
110{
111 return BindFeatureColumn(in, ii);
112}
113
114#endif

© Ullrich Köthe (ullrich.koethe@iwr.uni-heidelberg.de)
Heidelberg Collaboratory for Image Processing, University of Heidelberg, Germany

html generated using doxygen and Python
vigra 1.12.2 (Mon Apr 14 2025)