|
From: Gustavo P. B. <gb...@us...> - 2005-07-02 23:43:01
|
Update of /cvsroot/kimageprocess/kimageprocess/src/libkimageprocess In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23941/src/libkimageprocess Modified Files: ktcalculation.cpp ktcalculation.h Log Message: Moved the normalization code to a function (reduce code duplication) Index: ktcalculation.h =================================================================== RCS file: /cvsroot/kimageprocess/kimageprocess/src/libkimageprocess/ktcalculation.h,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- ktcalculation.h 2 Jul 2005 19:11:08 -0000 1.6 +++ ktcalculation.h 2 Jul 2005 23:42:52 -0000 1.7 @@ -72,6 +72,8 @@ void parseResults(const QValueList<float> &results, int sampleClass); + void normalize(); + public slots: void calculateSampleData(); Index: ktcalculation.cpp =================================================================== RCS file: /cvsroot/kimageprocess/kimageprocess/src/libkimageprocess/ktcalculation.cpp,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -r1.10 -r1.11 --- ktcalculation.cpp 2 Jul 2005 19:11:08 -0000 1.10 +++ ktcalculation.cpp 2 Jul 2005 23:42:52 -0000 1.11 @@ -85,25 +85,10 @@ for ( it = list.first(); it; it = list.next()) generateWindowResults(it, imgClass++); - //normalize - QValueList<dataEntry>::iterator end = m_data.end(); - - float dif[m_inputs]; - for (int i=0; i < m_inputs; ++i) - dif[i] = m_max[i] - m_min[i]; - - for (QValueList<dataEntry>::iterator it = m_data.begin(); it != end; ++it) - { - for ( int i=0; i < m_inputs; ++i ) - { - (*it).inputs[i] = ((*it).inputs[i] - m_min[i]) * 1000 / dif[i]; - } - } + //normalize the values + normalize(); KTPluginManager::self()->classifier()->doTraining(m_data, m_inputs, m_outputs); - - emit updateProgress(); - sleep(1); emit finished(); } @@ -133,21 +118,9 @@ m_window_type = WIN_ALLPIX; generateWindowResults(img, 0); m_window_type = winType; - - //normalize - QValueList<dataEntry>::iterator end = m_data.end(); - - float dif[m_inputs]; - for (int i=0; i < m_inputs; ++i) - dif[i] = m_max[i] - m_min[i]; - - for (QValueList<dataEntry>::iterator it = m_data.begin(); it != end; ++it) - { - for ( int i=0; i < m_inputs; ++i ) - { - (*it).inputs[i] = ((*it).inputs[i] - m_min[i]) * 1000 / dif[i]; - } - } + + //normalize the values + normalize(); KTPluginManager::self()->classifier()->doClassify(m_data, m_inputs, m_outputs); @@ -175,6 +148,7 @@ while ( (x + m_window_size.width <= width) && (y + m_window_size.height <= height) && (i < m_iterations || m_iterations == 0) ) { + kdDebug() << "SEQ: using x=" << x << " y=" << y << " w=" << m_window_size.width << " h=" << m_window_size.height << endl; tmpimg = img->returnWindow(x, y, m_window_size.width, m_window_size.height); m_method->calculate(tmpimg, imgClass); delete tmpimg; @@ -195,6 +169,7 @@ while ( (x + m_window_size.width <= width) && (y + m_window_size.height <= height) && (i < m_iterations || m_iterations == 0) ) { + kdDebug() << "CASC: using x=" << x << " y=" << y << " w=" << m_window_size.width << " h=" << m_window_size.height << endl; tmpimg = img->returnWindow(x, y, m_window_size.width, m_window_size.height); m_method->calculate(tmpimg, imgClass); delete tmpimg; @@ -254,12 +229,15 @@ if (m_first) { for (int j = 0; j < m_inputs; ++j) - m_min[j] = m_max[j] = results[j]; + { + m_min[j] = results[j]; + m_max[j] = results[j]; + } m_first = false; } //prepare the input - for (int i=0; i < results.count(); ++i) + for (int i=0; i < m_inputs; ++i) { if (results[i] > m_max[i]) m_max[i] = results[i]; @@ -285,6 +263,24 @@ return m_window_size; } +void KTCalculation::normalize() +{ + //the upper limit + float uplimit = 1000.; + + QValueList<dataEntry>::iterator end = m_data.end(); + float dif[m_inputs]; + for (int i=0; i < m_inputs; ++i) + dif[i] = m_max[i] - m_min[i]; + + for (QValueList<dataEntry>::iterator it = m_data.begin(); it != end; ++it) + { + for ( int i=0; i < m_inputs; ++i ) + (*it).inputs[i] = ((*it).inputs[i] - m_min[i]) * uplimit / dif[i]; + + } +} + QString& operator<<(QString& s, const QValueList<dataEntry> &l ) { QValueList<dataEntry>::const_iterator it; @@ -299,4 +295,5 @@ } return s; } + #include "ktcalculation.moc" |