39 typedef std::vector<value_type>
Map;
45 value_type& operator [](
int i){
49 const value_type& operator [](
int i)
const{
53 Map::const_iterator
begin()
const {
60 Map::const_iterator
end()
const {
67 bool save(
const std::string& filename)
const;
70 DVector get_fuzzy(
double x)
const;
87 virtual DVector run(
const NormalizedHistogram& nh)
const = 0;
91 CMeans(
double epsilon, PInitializer class_center_initializer);
95 SparseProbmap run(
const SparseHistogram& histogram, DVector& class_centers)
const;
97 SparseProbmap run(
const SparseHistogram& histogram, DVector& class_centers,
bool de_normalize_results)
const;
101 struct CMeansImpl *impl;
133 template <
typename T,
template <
class >
class Field>
135 const std::vector<double>& class_centers,
136 std::vector<Field<float>>& pv)
138 assert(image.size() == gain.size());
139 assert(class_centers.size() == pv.size());
142 assert(image.size() == i.size());
145 auto ii = image.begin();
146 auto ie = image.end();
147 auto ig = gain.begin();
148 typedef typename Field<float>::iterator prob_iterator;
150 std::vector<prob_iterator> ipv(pv.size());
151 transform(pv.begin(), pv.end(), ipv.begin(), [](Field<float>& p){
return p.begin();});
153 std::vector<double> gain_class_centers(class_centers.size());
160 const double vgain = *ig;
161 transform(class_centers.begin(), class_centers.end(), gain_class_centers.begin(),
162 [vgain](
double x){
return vgain * x;});
164 if ( x < gain_class_centers[0]) {
168 bool value_set =
false;
169 while (!value_set && (j < class_centers.size()) ) {
171 if (x < gain_class_centers[j]) {
173 double p0 = x - gain_class_centers[j-1];
174 double p1 = x - gain_class_centers[j];
175 double p02 = p0 * p0;
176 double p12 = p1 * p1;
177 double normalizer = 1.0/(p02 + p12);
178 *ipv[j] = p02 * normalizer;
179 *ipv[j - 1] = p12 * normalizer;
185 *ipv[class_centers.size() - 1] = 1.0;
188 for (
unsigned i = 0; i < class_centers.size(); ++i)
214 template <
typename T,
template <
class>
class Field>
216 const std::vector<Field<float>>& pv,
217 std::vector<double>& class_centers)
219 double residuum = 0.0;
221 for (
size_t i = 0; i < class_centers.size(); ++i) {
222 double cc = class_centers[i];
223 double sum_prob = 0.0;
224 double sum_weight = 0.0;
226 auto ie = image.end();
227 auto ii = image.begin();
228 auto ig = gain.begin();
229 auto ip = pv[i].begin();
233 auto v = *ip * *ip * *ig;
235 sum_weight += v * *ii;
244 cc = sum_weight / sum_prob;
246 cvwarn() <<
"class[" << i <<
"] has no probable members, keeping old value:" <<
247 sum_prob <<
":" <<sum_weight <<
"\n";
250 double delta = (cc - class_centers[i]) * 0.5;
251 residuum += delta * delta;
252 class_centers[i] += delta;
255 return sqrt(residuum);
266 size_t get_size_param()
const;
274 #pragma GCC diagnostic push 275 #pragma GCC diagnostic ignored "-Wattributes" 280 #pragma GCC diagnostic pop std::shared_ptr< Initializer > PInitializer
the singleton that a plug-in handler really is
THandlerSingleton< TFactoryPluginHandler< CMeansInitializerPlugin > > CMeansInitializerPluginHandler
double cmeans_update_class_centers(const Field< T > &image, const Field< float > &gain, const std::vector< Field< float >> &pv, std::vector< double > &class_centers)
TFactory< CMeans::Initializer > CMeansInitializerPlugin
std::vector< value_type > Map
#define NS_MIA_BEGIN
conveniance define to start the mia namespace
CSparseHistogram::Compressed SparseHistogram
Map::const_iterator begin() const
This is tha base of all plugins that create "things", like filters, cost functions time step operator...
std::pair< unsigned short, DVector > value_type
std::vector< std::pair< int, unsigned long > > Compressed
std::vector< double > DVector
Map::const_iterator end() const
vstream & cvwarn()
send warnings to this stream adapter
#define EXPORT_CORE
Macro to manage Visual C++ style dllimport/dllexport.
The base class for all plug-in created object.
static const char * data_descr
the Base class for all plugn handlers that deal with factory plugins.
static const char * type_descr
std::vector< std::pair< double, double > > NormalizedHistogram
The generic base for all plug-ins.
The basic template of all plugin handlers.
void cmeans_evaluate_probabilities(const Field< T > &image, const Field< float > &gain, const std::vector< double > &class_centers, std::vector< Field< float >> &pv)
evaluate the probabilities for a c-means classification with gain field
#define NS_MIA_END
conveniance define to end the mia namespace