41 typedef std::vector<value_type>
Map;
57 Map::const_iterator
begin()
const
66 Map::const_iterator
end()
const
75 bool save(
const std::string& filename)
const;
111 struct CMeansImpl *impl;
143 template <
typename T,
template <
class >
class Field>
145 const std::vector<double>& class_centers,
146 std::vector<Field<float>>& pv)
148 assert(image.size() == gain.size());
149 assert(class_centers.size() == pv.size());
153 assert(image.size() == i.size());
156 auto ii = image.begin();
157 auto ie = image.end();
158 auto ig = gain.begin();
159 typedef typename Field<float>::iterator prob_iterator;
160 std::vector<prob_iterator> ipv(pv.size());
161 transform(pv.begin(), pv.end(), ipv.begin(), [](Field<float>& p) {
164 std::vector<double> gain_class_centers(class_centers.size());
169 for (
auto iipv : ipv)
172 const double vgain = *ig;
173 transform(class_centers.begin(), class_centers.end(), gain_class_centers.begin(),
178 if ( x < gain_class_centers[0]) {
182 bool value_set =
false;
184 while (!value_set && (j < class_centers.size()) ) {
186 if (x < gain_class_centers[j]) {
187 double p0 = x - gain_class_centers[j - 1];
188 double p1 = x - gain_class_centers[j];
189 double p02 = p0 * p0;
190 double p12 = p1 * p1;
191 double normalizer = 1.0 / (p02 + p12);
192 *ipv[j] = p02 * normalizer;
193 *ipv[j - 1] = p12 * normalizer;
201 *ipv[class_centers.size() - 1] = 1.0;
207 for (
unsigned i = 0; i < class_centers.size(); ++i)
233 template <
typename T,
template <
class>
class Field>
235 const std::vector<Field<float>>& pv,
236 std::vector<double>& class_centers)
238 double residuum = 0.0;
240 for (
size_t i = 0; i < class_centers.size(); ++i) {
241 double cc = class_centers[i];
242 double sum_prob = 0.0;
243 double sum_weight = 0.0;
244 auto ie = image.end();
245 auto ii = image.begin();
246 auto ig = gain.begin();
247 auto ip = pv[i].begin();
251 auto v = *ip * *ip * *ig;
253 sum_weight += v * *ii;
262 cc = sum_weight / sum_prob;
264 cvwarn() <<
"class[" << i <<
"] has no probable members, keeping old value:" <<
265 sum_prob <<
":" << sum_weight <<
"\n";
268 double delta = (cc - class_centers[i]) * 0.5;
269 residuum += delta * delta;
270 class_centers[i] += delta;
273 return sqrt(residuum);
293 #pragma GCC diagnostic push
294 #pragma GCC diagnostic ignored "-Wattributes"
299 #pragma GCC diagnostic pop
size_t get_size_param() const
CMeansInitializerSizedPlugin(const char *name)
virtual DVector run(const NormalizedHistogram &nh) const =0
static const char * type_descr
static const char * data_descr
bool save(const std::string &filename) const
SparseProbmap(const std::string &filename)
std::vector< value_type > Map
DVector get_fuzzy(double x) const
Map::const_iterator end() const
SparseProbmap(size_t size)
Map::const_iterator begin() const
std::pair< unsigned short, DVector > value_type
CMeans(double epsilon, PInitializer class_center_initializer)
CSparseHistogram::Compressed SparseHistogram
std::vector< double > DVector
std::shared_ptr< Initializer > PInitializer
SparseProbmap run(const SparseHistogram &histogram, DVector &class_centers) const
SparseProbmap run(const SparseHistogram &histogram, DVector &class_centers, bool de_normalize_results) const
std::vector< std::pair< double, double > > NormalizedHistogram
The base class for all plug-in created object.
std::vector< std::pair< int, unsigned long > > Compressed
the Base class for all plugn handlers that deal with factory plugins.
This is tha base of all plugins that create "things", like filters, cost functions time step operator...
the singleton that a plug-in handler really is
The basic template of all plugin handlers.
The generic base for all plug-ins.
THandlerSingleton< TFactoryPluginHandler< CMeansInitializerPlugin > > CMeansInitializerPluginHandler
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
TFactory< CMeans::Initializer > CMeansInitializerPlugin
double cmeans_update_class_centers(const Field< T > &image, const Field< float > &gain, const std::vector< Field< float >> &pv, std::vector< double > &class_centers)
#define NS_MIA_BEGIN
conveniance define to start the mia namespace
#define EXPORT_CORE
Macro to manage Visual C++ style dllimport/dllexport.
#define NS_MIA_END
conveniance define to end the mia namespace
vstream & cvwarn()
send warnings to this stream adapter