36 #ifndef VIGRA_MULTI_HISTOGRAMM_HXX
37 #define VIGRA_MULTI_HISTOGRAMM_HXX
39 #include "multi_array.hxx"
40 #include "tinyvector.hxx"
41 #include "multi_gridgraph.hxx"
42 #include "multi_convolution.hxx"
48 template<
unsigned int DIM ,
class T_DATA ,
unsigned int CHANNELS,
class T_HIST >
49 void multi_gaussian_histogram(
50 const MultiArrayView<DIM, TinyVector<T_DATA,CHANNELS> > & image,
51 const TinyVector<T_DATA,CHANNELS> minVals,
52 const TinyVector<T_DATA,CHANNELS> maxVals,
56 MultiArrayView<DIM+2 , T_HIST> histogram
59 typedef typename Graph::NodeIt graph_scanner;
60 typedef typename Graph::Node Node;
61 typedef T_HIST ValueType;
62 typedef TinyVector<ValueType,CHANNELS> ChannelsVals;
63 typedef typename MultiArrayView<DIM+2 , T_HIST>::difference_type HistCoord;
64 const Graph g(image.shape());
65 const ChannelsVals nBins(bins);
68 for (graph_scanner n(g); n != lemon::INVALID; ++n){
70 ChannelsVals binIndex = image[node];
75 for(
size_t d=0;d<DIM;++d){
78 for(
size_t c=0;c<CHANNELS;++c){
79 const float fi = binIndex[c];
81 histCoord[DIM]=std::min(bi,static_cast<size_t>(bins-1));
83 histogram[histCoord]+=1.0;
87 MultiArray<DIM+2 , T_HIST> histogramBuffer(histogram);
88 Kernel1D<float> gauss,gaussBin;
89 gauss.initGaussian(sigma);
90 gaussBin.initGaussian(sigmaBin);
91 for(
size_t c=0;c<CHANNELS;++c){
94 MultiArrayView<DIM+1,T_HIST> histc = histogram.bindOuter(c);
95 MultiArrayView<DIM+1,T_HIST> histcBuffer = histogram.bindOuter(c);
121 throw std::runtime_error(
"not yet implemented for arbitrary dimension");
128 template<
unsigned int DIM ,
class T_DATA,
class T_HIST >
129 void multi_gaussian_co_histogram(
130 const MultiArrayView<DIM, T_DATA > & imageA,
131 const MultiArrayView<DIM, T_DATA > & imageB,
132 const TinyVector<T_DATA,2> & minVals,
133 const TinyVector<T_DATA,2> & maxVals,
134 const TinyVector<int,2> & nBins,
135 const TinyVector<float,3> & sigma,
136 MultiArrayView<DIM+2, T_HIST> histogram
139 typedef typename Graph::NodeIt graph_scanner;
140 typedef typename Graph::Node Node;
141 typedef typename MultiArrayView<DIM+2 , T_HIST>::difference_type HistCoord;
142 const Graph g(imageA.shape());
145 for (graph_scanner n(g); n != lemon::INVALID; ++n){
148 T_DATA binIndexA = imageA[node];
149 T_DATA binIndexB = imageA[node];
151 binIndexA -=minVals[0];
152 binIndexA /=maxVals[0];
153 binIndexA *=nBins[0];
155 binIndexB -=minVals[1];
156 binIndexB /=maxVals[1];
157 binIndexB *=nBins[1];
160 for(
size_t d=0;d<DIM;++d)
161 histCoord[d]=node[d];
163 histCoord[DIM]=binIndexA;
164 histCoord[DIM+1]=binIndexB;
166 const float fiA = binIndexA;
168 const float fiB = binIndexB;
170 histCoord[DIM]=std::min(biA,static_cast<unsigned int>(nBins[0]-1));
171 histCoord[DIM+1]=std::min(biB,static_cast<unsigned int>(nBins[1]-1));
172 histogram[histCoord]+=1.0;
176 MultiArray<DIM+2 , T_HIST> histogramBuffer(histogram);
177 Kernel1D<float> gaussS,gaussA,gaussB;
178 gaussS.initGaussian(sigma[0]);
179 gaussA.initGaussian(sigma[1]);
180 gaussB.initGaussian(sigma[2]);
194 histogram=histogramBuffer;
205 throw std::runtime_error(
"not yet implemented for arbitrary dimension");
215 #endif //VIGRA_MULTI_HISTOGRAMM_HXX