Go to the documentation of this file.
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
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
Map::const_iterator end() const
CMeansInitializerSizedPlugin(const char *name)
std::shared_ptr< Initializer > PInitializer
THandlerSingleton< TFactoryPluginHandler< CMeansInitializerPlugin > > CMeansInitializerPluginHandler
#define NS_MIA_BEGIN
conveniance define to start the mia namespace
double cmeans_update_class_centers(const Field< T > &image, const Field< float > &gain, const std::vector< Field< float >> &pv, std::vector< double > &class_centers)
SparseProbmap(const std::string &filename)
bool save(const std::string &filename) const
DVector get_fuzzy(double x) const
TFactory< CMeans::Initializer > CMeansInitializerPlugin
#define NS_MIA_END
conveniance define to end the mia namespace
std::pair< unsigned short, DVector > value_type
the singleton that a plug-in handler really is
size_t get_size_param() const
CMeans(double epsilon, PInitializer class_center_initializer)
std::vector< std::pair< int, unsigned long > > Compressed
The basic template of all plugin handlers.
SparseProbmap run(const SparseHistogram &histogram, DVector &class_centers, bool de_normalize_results) const
The generic base for all plug-ins.
vstream & cvwarn()
send warnings to this stream adapter
CSparseHistogram::Compressed SparseHistogram
The base class for all plug-in created object.
SparseProbmap(size_t size)
std::vector< value_type > Map
static const char * type_descr
virtual DVector run(const NormalizedHistogram &nh) const =0
the Base class for all plugn handlers that deal with factory plugins.
#define EXPORT_CORE
Macro to manage Visual C++ style dllimport/dllexport.
std::vector< double > DVector
SparseProbmap run(const SparseHistogram &histogram, DVector &class_centers) const
static const char * data_descr
std::vector< std::pair< double, double > > NormalizedHistogram
Map::const_iterator begin() const
This is tha base of all plugins that create "things", like filters, cost functions time step operator...