|
From: Gustavo P. B. <gb...@us...> - 2005-06-23 23:20:42
|
Update of /cvsroot/kimageprocess/kimageprocess/src/libkimageprocess In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32338/src/libkimageprocess Modified Files: Makefile.am ktcalculation.cpp ktcalculation.h ktclassifbackend.cpp ktclassifbackend.h ktmethod.cpp ktmethod.h ktpatternmanager.cpp ktpatternmanager.h ktplugin.h ktpluginmanager.cpp ktpluginmanager.h ktproject.cpp Log Message: All calculation (features extraction, normalization, etc) are now done in KTCalculation which provides us a better way to add new classifiers Index: ktproject.cpp =================================================================== RCS file: /cvsroot/kimageprocess/kimageprocess/src/libkimageprocess/ktproject.cpp,v retrieving revision 1.14 retrieving revision 1.15 diff -u -d -r1.14 -r1.15 --- ktproject.cpp 23 Jun 2005 18:33:51 -0000 1.14 +++ ktproject.cpp 23 Jun 2005 23:19:41 -0000 1.15 @@ -32,6 +32,7 @@ #include <qfile.h> #include "ktpatternmanager.h" +#include "ktcalculation.h" KTProject::KTProject(QObject *parent, const char *name) : QObject(parent, name)/*, @@ -210,14 +211,14 @@ window_size temp; QDomElement option; option = m_doc.createElement("windowType"); - option.setAttribute("value", QString::number(KTImageManager::self()->windowType(), 10)); + option.setAttribute("value", QString::number(KTCalculation::self()->windowType(), 10)); options.appendChild(option); option = m_doc.createElement("numberIterations"); - option.setAttribute("value", QString::number(KTImageManager::self()->numberIterations(), 10)); + option.setAttribute("value", QString::number(KTCalculation::self()->numberIterations(), 10)); options.appendChild(option); - temp = KTImageManager::self()->windowSize(); + temp = KTCalculation::self()->windowSize(); option = m_doc.createElement("windowSize"); option.setAttribute("type", temp.type?"true":"false"); option.setAttribute("x", QString::number(temp.width, 10)); @@ -291,11 +292,11 @@ QDomElement option = options.item(i).toElement(); if (option.nodeName() == "windowType") - KTImageManager::self()->setWindowType(option.attribute("value").toInt(&ok, 10)); + KTCalculation::self()->setWindowType(option.attribute("value").toInt(&ok, 10)); else if (option.nodeName() == "numberIterations") - KTImageManager::self()->setNumberIterations(option.attribute("value").toInt(&ok, 10)); + KTCalculation::self()->setNumberIterations(option.attribute("value").toInt(&ok, 10)); else if (option.nodeName() == "windowSize") - KTImageManager::self()->setWindowSize((option.attribute("type","true")=="true")? true : false, + KTCalculation::self()->setWindowSize((option.attribute("type","true")=="true")? true : false, option.attribute("x").toInt(&ok, 10), option.attribute("y").toInt(&ok, 10)); } Index: ktcalculation.h =================================================================== RCS file: /cvsroot/kimageprocess/kimageprocess/src/libkimageprocess/ktcalculation.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- ktcalculation.h 23 Jun 2005 19:39:00 -0000 1.2 +++ ktcalculation.h 23 Jun 2005 23:19:41 -0000 1.3 @@ -22,6 +22,30 @@ #define KTCALCULATION_H #include <qobject.h> +#include <qvaluevector.h> + +class KTImage; +class KTMethod; + + +// texture window types +#define WIN_SEQ 0 // windows are gathered in sequential iterations +#define WIN_CASC 1 // windows are gathered in sequential cascated iterations +#define WIN_RAND 2 // windows are gathered in random iterations +#define WIN_ALLPIX 3 //windows are generated for all pixels from the image + +typedef struct +{ + bool type; + int height; + int width; +} window_size; + +typedef struct +{ + float *inputs; + int sampleClass; +} dataEntry; /** A class that actually does the calculation for the images at all @@ -37,18 +61,53 @@ static KTCalculation *self(); + /* functions to handle texture options */ + void setWindowType(int type) { m_window_type = type; } + int windowType() { return m_window_type; } + + void setNumberIterations(int number) { m_iterations = number; } + int numberIterations() { return m_iterations; } + + void setWindowSize(bool type, int height, int width); + window_size windowSize(); + + void parseResults(const QValueList<float> &results); + void parseSampleResults(const QValueList<float> &results, int sampleClass); + public slots: void calculateSampleData(); void calculateTestData(); + signals: void updateProgress(); void finished(); private: - static KTCalculation *s_self; + /** + * generate and write results for the current window settings + * @param img the image from which we are going to calculate the patterns + * @param imgClass the class number of the image used to generate the patterns + */ + void generateWindowResults(KTImage *img, int imgClass); + + int m_inputs; + int m_outputs; + bool m_first; + bool m_testing; + QValueList<dataEntry> m_data; + QValueVector<float> m_min; + QValueVector<float> m_max; + /* texture window settings */ + int m_window_type; + int m_iterations; + window_size m_window_size; + + KTMethod *m_method; + + static KTCalculation *s_self; }; Index: ktpatternmanager.h =================================================================== RCS file: /cvsroot/kimageprocess/kimageprocess/src/libkimageprocess/ktpatternmanager.h,v retrieving revision 1.14 retrieving revision 1.15 diff -u -d -r1.14 -r1.15 --- ktpatternmanager.h 23 Jun 2005 18:33:51 -0000 1.14 +++ ktpatternmanager.h 23 Jun 2005 23:19:41 -0000 1.15 @@ -27,11 +27,6 @@ #include <kurl.h> -// texture window types -#define WIN_SEQ 0 // windows are gathered in sequential iterations -#define WIN_CASC 1 // windows are gathered in sequential cascated iterations -#define WIN_RAND 2 // windows are gathered in random iterations -#define WIN_ALLPIX 3 //windows are generated for all pixels from the image class KAction; class KTImage; @@ -39,12 +34,6 @@ typedef QPtrList<KTImage> KTImageList; -typedef struct -{ - bool type; - int height; - int width; -} window_size; /** * This class manages all the opened pattern images. @@ -124,38 +113,21 @@ /** the name of the active features */ QStringList activeFeatureNames(); - - /* functions to handle texture options */ - void setWindowType(int type) { m_window_type = type; } - int windowType() { return m_window_type; } - - void setNumberIterations(int number) { m_iterations = number; } - int numberIterations() { return m_iterations; } - - void setWindowSize(bool type, int height, int width); - window_size windowSize(); - + void clear(); static KTImageManager *self(); + + KTImageList sampleImages() { return m_sampleImages; } + KTImageList testingImages() { return m_testingImages; } + private: - /** - * generate and write results for the current window settings - * @param img the image from which we are going to calculate the patterns - * @param imgClass the class number of the image used to generate the patterns - * @param backend the classification backend to be used - */ - void generateWindowResults(KTImage *img, int imgClass, KTClassifBackend *backend = 0); - + /** The list of loaded samples */ KTImageList m_sampleImages; KTImageList m_testingImages; - /* texture window settings */ - int m_window_type; - int m_iterations; - window_size m_window_size; - + KAction *m_generatePatAction; static KTImageManager *s_self; Index: ktpatternmanager.cpp =================================================================== RCS file: /cvsroot/kimageprocess/kimageprocess/src/libkimageprocess/ktpatternmanager.cpp,v retrieving revision 1.31 retrieving revision 1.32 diff -u -d -r1.31 -r1.32 --- ktpatternmanager.cpp 23 Jun 2005 18:33:51 -0000 1.31 +++ ktpatternmanager.cpp 23 Jun 2005 23:19:41 -0000 1.32 @@ -45,12 +45,6 @@ m_testingData = false; - //Set defaults - m_window_type = WIN_SEQ; - m_window_size.type = true; //window, not the whole image - m_window_size.width = 5; - m_window_size.height = 5; - m_iterations = 0; } KTImageManager::~KTImageManager() @@ -157,191 +151,6 @@ return names; } -void KTImageManager::calculateSampleData(KTImage *img, KTClassifBackend *backend) -{ - if (img) - { - int imgClass=1; - - if (!m_testingData) - { - KTImage *it; - for ( it = m_sampleImages.first(); it; it = m_sampleImages.next()) - if (it == img) - break; - else - imgClass++; - } - generateWindowResults(img, imgClass, backend); - } - else - { - int imgClass=1; - KTImage *it; - for ( it = m_sampleImages.first(); it; it = m_sampleImages.next()) - { - generateWindowResults(it, imgClass, backend); - imgClass++; - } - } -} - -void KTImageManager::generateWindowResults(KTImage *img, int imgClass, KTClassifBackend *backend) -{ - int i, x, y, width, height, acumm; - KTImage *tmpimg; - - KTMethod *m_method = KTMethodManager::self()->activeMethod(); - if (!m_window_size.type) - { - m_method->calculate(img, backend, imgClass); - } - else - { - switch(m_window_type) - { - case WIN_SEQ: - x = y = i = 0; - width = img->width(); - height = img->height(); - - while ( (x + m_window_size.width <= width) && (y + m_window_size.height <= height) && - (i < m_iterations || m_iterations == 0) ) - { - tmpimg = img->returnWindow(x, y, m_window_size.width, m_window_size.height); - m_method->calculate(tmpimg, backend, imgClass); - delete tmpimg; - ++i; - ++x; - if (x + m_window_size.width > width) - { - x = 0; - ++y; - } - } - break; - case WIN_CASC: - x = y = i = acumm = 0; - width = img->width(); - height = img->height(); - - while ( (x + m_window_size.width <= width) && (y + m_window_size.height <= height) && - (i < m_iterations || m_iterations == 0) ) - { - tmpimg = img->returnWindow(x, y, m_window_size.width, m_window_size.height); - m_method->calculate(tmpimg, backend, imgClass); - delete tmpimg; - ++i; - x += m_window_size.width; - if (x + m_window_size.width > width) - { - x = ++acumm; - acumm = acumm % m_window_size.width; - y += m_window_size.height; - } - } - break; - case WIN_RAND: - i = 0; - width = img->width(); - height = img->height(); - - srand((unsigned) time(NULL)); - - while (i < m_iterations) - { - x = rand() % (width - m_window_size.width); - y = rand() % (height - m_window_size.height); - tmpimg = img->returnWindow(x, y, m_window_size.width, m_window_size.height); - m_method->calculate(tmpimg, backend, imgClass); - delete tmpimg; - i++; - } - break; - case WIN_ALLPIX: - int cols_right, cols_left, rows_below, rows_above; - - // Calculate the outer borders of the image, because we're using centered windows - // (The window cross image boundaries) - cols_right = m_window_size.width / 2; - rows_below = m_window_size.height / 2; - if (m_window_size.width % 2 == 0) - cols_left = cols_right; - else - cols_left = cols_right + 1; - if (m_window_size.height % 2 == 0) - rows_above = rows_below; - else - rows_above = rows_below + 1; - - // Generate the pattern for Testing Image - int width = img->width(); - int height = img->height(); - for (y = 0; y < height; y++) - { - kdDebug() << "x = 0 y = " << y << endl; - for (x = 0; x < width; x++) - { - int startx, starty; - - //handling windows that are partly or fully outside the image - - //the x side - if ( x - cols_left < 0 ) - startx = 0; - else if ( x + cols_right >= width ) - startx = width - m_window_size.width - 1; - else - startx = x - cols_left; - - //the y side - if ( y - rows_above < 0 ) - starty = 0; - else if ( y + rows_below >= height ) - starty = height - m_window_size.height - 1; - else - starty = y - rows_above; - - tmpimg = img->returnWindow(startx, starty, m_window_size.width, m_window_size.height); - m_method->calculate(tmpimg, backend, imgClass); - delete tmpimg; - } - } - break; - } - } -} - -void KTImageManager::calculateTestData(KTImage *img, KTClassifBackend *backend) -{ - int wt = m_window_type; - m_window_type = WIN_ALLPIX; - - m_testingData = true; - KTMethodManager::self()->activeMethod()->setTestingData(true); - - if (img == 0) - img = m_testingImages.first(); - - calculateSampleData(img, backend); - - m_testingData = false; - KTMethodManager::self()->activeMethod()->setTestingData(false); - m_window_type = wt; -} - -void KTImageManager::setWindowSize(bool type, int height, int width) -{ - m_window_size.type = type; - m_window_size.height = height; - m_window_size.width = width; -} - -window_size KTImageManager::windowSize() -{ - return m_window_size; -} - KTImage *KTImageManager::testingImage() { return m_testingImages.first(); Index: ktplugin.h =================================================================== RCS file: /cvsroot/kimageprocess/kimageprocess/src/libkimageprocess/ktplugin.h,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- ktplugin.h 23 Jun 2005 18:33:51 -0000 1.5 +++ ktplugin.h 23 Jun 2005 23:19:41 -0000 1.6 @@ -40,6 +40,7 @@ virtual ~KTPlugin(); virtual void setupPlugin(); + }; #endif Index: ktclassifbackend.cpp =================================================================== RCS file: /cvsroot/kimageprocess/kimageprocess/src/libkimageprocess/ktclassifbackend.cpp,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- ktclassifbackend.cpp 23 Jun 2005 18:33:50 -0000 1.5 +++ ktclassifbackend.cpp 23 Jun 2005 23:19:41 -0000 1.6 @@ -19,9 +19,10 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include "ktclassifbackend.h" +#include <ktcalculation.h> KTClassifBackend::KTClassifBackend(QObject *parent, const char *name) - : KTPlugin(parent, name) + : QObject(parent, name) { } @@ -29,15 +30,23 @@ { } -void KTClassifBackend::parseResults(const QValueList<float> &results) +void KTClassifBackend::doTraining(const QValueList<dataEntry>& data, int inputs, int outputs) { - Q_UNUSED(results); + Q_UNUSED(data); + Q_UNUSED(inputs); + Q_UNUSED(outputs); } -void KTClassifBackend::parseSampleResults(const QValueList<float> &results, int sampleClass) +void KTClassifBackend::doClassify(const QValueList<dataEntry>& data, int inputs, int outputs) { - Q_UNUSED(results); - Q_UNUSED(sampleClass); + Q_UNUSED(data); + Q_UNUSED(inputs); + Q_UNUSED(outputs); +} + +QString KTClassifBackend::classifierName() +{ + return "unnamed"; } #include "ktclassifbackend.moc" Index: Makefile.am =================================================================== RCS file: /cvsroot/kimageprocess/kimageprocess/src/libkimageprocess/Makefile.am,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- Makefile.am 23 Jun 2005 18:33:49 -0000 1.6 +++ Makefile.am 23 Jun 2005 23:19:41 -0000 1.7 @@ -3,7 +3,7 @@ libkimageprocess_la_LDFLAGS = $(all_libraries) libkimageprocess_la_SOURCES = ktimage.cpp ktpatternmanager.cpp ktplugin.cpp \ ktpluginmanager.cpp ktproject.cpp ktclassifbackend.cpp ktfeature.cpp ktfeature.h \ - ktfeaturemanager.cpp ktfeaturemanager.h ktmethod.cpp ktmethodmanager.cpp ktcalculation.cpp + ktfeaturemanager.cpp ktfeaturemanager.h ktmethod.cpp ktmethodmanager.cpp ktcalculation.cpp noinst_HEADERS = ktimage.h ktpatternmanager.h ktplugin.h ktpluginmanager.h \ ktproject.h ktclassifbackend.h ktcalculation.h Index: ktpluginmanager.h =================================================================== RCS file: /cvsroot/kimageprocess/kimageprocess/src/libkimageprocess/ktpluginmanager.h,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- ktpluginmanager.h 23 Jun 2005 18:33:51 -0000 1.3 +++ ktpluginmanager.h 23 Jun 2005 23:19:41 -0000 1.4 @@ -22,12 +22,17 @@ #define KTPLUGINMANAGER_H #include <qobject.h> -#include <qptrlist.h> +#include <qdict.h> class KTPlugin; //class KMainWindow; class KTImageManager; + +#include "ktclassifbackend.h" + +typedef QDict<KTClassifBackend> BackendList; + /** A class to manage KImageProcess plugins @@ -47,9 +52,10 @@ static KTPluginManager *self(); + KTClassifBackend *classifier(); private: //KMainWindow *m_window; - QPtrList<KTPlugin> m_pluginList; + BackendList m_backends; static KTPluginManager *s_self; }; Index: ktmethod.h =================================================================== RCS file: /cvsroot/kimageprocess/kimageprocess/src/libkimageprocess/ktmethod.h,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- ktmethod.h 23 Jun 2005 18:33:51 -0000 1.8 +++ ktmethod.h 23 Jun 2005 23:19:41 -0000 1.9 @@ -42,7 +42,7 @@ ~KTMethod(); ///must be reimplemented by child classes - virtual void calculate(KTImage *img, KTClassifBackend *backend, int imgClass = 0); + virtual void calculate(KTImage *img, int imgClass = 0); QString methodName(); QString longName(); Index: ktpluginmanager.cpp =================================================================== RCS file: /cvsroot/kimageprocess/kimageprocess/src/libkimageprocess/ktpluginmanager.cpp,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- ktpluginmanager.cpp 23 Jun 2005 18:33:51 -0000 1.5 +++ ktpluginmanager.cpp 23 Jun 2005 23:19:41 -0000 1.6 @@ -20,7 +20,7 @@ ***************************************************************************/ #include "ktpluginmanager.h" #include "ktpatternmanager.h" -#include "ktplugin.h" +#include "ktclassifbackend.h" #include <kmainwindow.h> #include <kparts/componentfactory.h> @@ -55,7 +55,7 @@ void KTPluginManager::loadPlugins() { - KTPlugin *plugin; + KTClassifBackend *plugin; KTrader::OfferList offers = KTrader::self()->query("KImageProcess/Plugin"); @@ -66,19 +66,23 @@ { KService::Ptr service = *iter; int errCode = 0; - plugin = KParts::ComponentFactory::createInstanceFromService<KTPlugin> + plugin = KParts::ComponentFactory::createInstanceFromService<KTClassifBackend> ( service, this, 0, QStringList(), &errCode); // here we ought to check the error code. if (plugin) { //m_window->guiFactory()->addClient(plugin); - - kdDebug() << "KTPluginManager: Loaded plugin " - << plugin->name() << endl; + kdDebug() << "Loaded classifier: " << plugin->classifierName() << endl; + m_backends.insert(plugin->classifierName(), plugin); } } } +KTClassifBackend *KTPluginManager::classifier() +{ + //FIXME: hardcoded to snns + return m_backends["snns"]; +} #include "ktpluginmanager.moc" Index: ktcalculation.cpp =================================================================== RCS file: /cvsroot/kimageprocess/kimageprocess/src/libkimageprocess/ktcalculation.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- ktcalculation.cpp 23 Jun 2005 19:39:00 -0000 1.2 +++ ktcalculation.cpp 23 Jun 2005 23:19:41 -0000 1.3 @@ -18,13 +18,28 @@ * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ +#include "ktimage.h" #include "ktcalculation.h" +#include "ktfeaturemanager.h" +#include "ktmethodmanager.h" +#include "ktmethod.h" +#include "ktpatternmanager.h" +#include "ktclassifbackend.h" +#include "ktpluginmanager.h" #include <kstaticdeleter.h> +#include <kdebug.h> KTCalculation::KTCalculation(QObject *parent, const char *name) : QObject(parent, name) { + //Set defaults + m_window_type = WIN_SEQ; + m_window_size.type = true; //window, not the whole image + m_window_size.width = 5; + m_window_size.height = 5; + m_iterations = 0; + } @@ -50,6 +65,39 @@ void KTCalculation::calculateSampleData() { + m_testing = false; + + m_method = KTMethodManager::self()->activeMethod(); + + m_inputs = KTFeatureManager::self()->enabledFeaturesCount(m_method->methodName()); + m_outputs = KTImageManager::self()->sampleCount(); + + m_data.clear(); + m_min.resize(m_inputs, 0); + m_max.resize(m_inputs, 0); + + int imgClass = 1; + KTImage *it; + for ( it = KTImageManager::self()->sampleImages().first(); it; it = KTImageManager::self()->sampleImages().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]) * 100 / dif[i]; + } + } + + KTPluginManager::self()->classifier()->doTraining(m_data, m_inputs, m_outputs); + emit updateProgress(); sleep(1); emit finished(); @@ -57,6 +105,47 @@ void KTCalculation::calculateTestData() { + m_testing = true; + + m_method = KTMethodManager::self()->activeMethod(); + + m_inputs = KTFeatureManager::self()->enabledFeaturesCount(m_method->methodName()); + m_outputs = KTImageManager::self()->sampleCount(); + + m_data.clear(); + m_min.resize(m_inputs, 0); + m_max.resize(m_inputs, 0); + + KTImage *img = KTImageManager::self()->testingImage(); + + if (!img) + { + emit finished(); + return; + } + + int winType = m_window_type; + 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]) * 100 / dif[i]; + } + } + + KTPluginManager::self()->classifier()->doClassify(m_data, m_inputs, m_outputs); + emit updateProgress(); sleep(1); emit updateProgress(); @@ -64,4 +153,209 @@ emit finished(); } +void KTCalculation::generateWindowResults(KTImage *img, int imgClass) +{ + int i, x, y, width, height, acumm; + KTImage *tmpimg; + + if (!m_window_size.type) + { + m_method->calculate(img, imgClass); + } + else + { + switch(m_window_type) + { + case WIN_SEQ: + x = y = i = 0; + width = img->width(); + height = img->height(); + + while ( (x + m_window_size.width <= width) && (y + m_window_size.height <= height) && + (i < m_iterations || m_iterations == 0) ) + { + tmpimg = img->returnWindow(x, y, m_window_size.width, m_window_size.height); + m_method->calculate(tmpimg, imgClass); + delete tmpimg; + ++i; + ++x; + if (x + m_window_size.width > width) + { + x = 0; + ++y; + } + } + break; + case WIN_CASC: + x = y = i = acumm = 0; + width = img->width(); + height = img->height(); + + while ( (x + m_window_size.width <= width) && (y + m_window_size.height <= height) && + (i < m_iterations || m_iterations == 0) ) + { + tmpimg = img->returnWindow(x, y, m_window_size.width, m_window_size.height); + m_method->calculate(tmpimg, imgClass); + delete tmpimg; + ++i; + x += m_window_size.width; + if (x + m_window_size.width > width) + { + x = ++acumm; + acumm = acumm % m_window_size.width; + y += m_window_size.height; + } + } + break; + case WIN_RAND: + i = 0; + width = img->width(); + height = img->height(); + + srand((unsigned) time(NULL)); + + while (i < m_iterations) + { + x = rand() % (width - m_window_size.width); + y = rand() % (height - m_window_size.height); + tmpimg = img->returnWindow(x, y, m_window_size.width, m_window_size.height); + m_method->calculate(tmpimg, imgClass); + delete tmpimg; + i++; + } + break; + case WIN_ALLPIX: + int cols_right, cols_left, rows_below, rows_above; + + // Calculate the outer borders of the image, because we're using centered windows + // (The window cross image boundaries) + cols_right = m_window_size.width / 2; + rows_below = m_window_size.height / 2; + if (m_window_size.width % 2 == 0) + cols_left = cols_right; + else + cols_left = cols_right + 1; + if (m_window_size.height % 2 == 0) + rows_above = rows_below; + else + rows_above = rows_below + 1; + + // Generate the pattern for Testing Image + int width = img->width(); + int height = img->height(); + for (y = 0; y < height; y++) + { + for (x = 0; x < width; x++) + { + int startx, starty; + + //handling windows that are partly or fully outside the image + + //the x side + if ( x - cols_left < 0 ) + startx = 0; + else if ( x + cols_right >= width ) + startx = width - m_window_size.width - 1; + else + startx = x - cols_left; + + //the y side + if ( y - rows_above < 0 ) + starty = 0; + else if ( y + rows_below >= height ) + starty = height - m_window_size.height - 1; + else + starty = y - rows_above; + + tmpimg = img->returnWindow(startx, starty, m_window_size.width, m_window_size.height); + m_method->calculate(tmpimg, imgClass); + delete tmpimg; + } + emit updateProgress(); + } + break; + } + } +} + +void KTCalculation::parseResults(const QValueList<float> &results) +{ + float *inputs = new float[m_inputs]; + + QValueList<float>::const_iterator it; + + if (m_first) + { + for (int j = 0; j < m_inputs; ++j) + m_min[j] = m_max[j] = inputs[j]; + m_first = false; + } + + int i = 0; + + //prepare the input + for ( it = results.begin(); it != results.end(); ++it) + { + inputs[i] = (*it); + if (inputs[i] > m_max[i]) + m_max[i] = inputs[i]; + else if (inputs[i] < m_min[i]) + m_min[i] = inputs[i]; + ++i; + } + + dataEntry entry ; + entry.inputs = inputs; + entry.sampleClass = 0; + m_data.append(entry); + +} + +void KTCalculation::parseSampleResults(const QValueList<float> &results, int sampleClass) +{ + float *inputs = new float[m_inputs]; + + QValueList<float>::const_iterator it; + + + if (m_first) + { + for (int j = 0; j < m_inputs; ++j) + m_min[j] = m_max[j] = inputs[j]; + m_first = false; + } + + int i = 0; + + //prepare the input + for ( it = results.begin(); it != results.end(); ++it) + { + inputs[i] = (*it); + if (inputs[i] > m_max[i]) + m_max[i] = inputs[i]; + else if (inputs[i] < m_min[i]) + m_min[i] = inputs[i]; + ++i; + } + + dataEntry entry; + entry.inputs = inputs; + entry.sampleClass = sampleClass; + m_data.append(entry); + +} + +void KTCalculation::setWindowSize(bool type, int height, int width) +{ + m_window_size.type = type; + m_window_size.height = height; + m_window_size.width = width; +} + +window_size KTCalculation::windowSize() +{ + return m_window_size; +} + + #include "ktcalculation.moc" Index: ktclassifbackend.h =================================================================== RCS file: /cvsroot/kimageprocess/kimageprocess/src/libkimageprocess/ktclassifbackend.h,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- ktclassifbackend.h 23 Jun 2005 18:33:50 -0000 1.3 +++ ktclassifbackend.h 23 Jun 2005 23:19:41 -0000 1.4 @@ -21,16 +21,18 @@ #ifndef KTCLASSIFBACKEND_H #define KTCLASSIFBACKEND_H -#include <ktplugin.h> +#include <ktcalculation.h> #include <qvaluelist.h> +#include <qobject.h> +#include <qstring.h> /** Base class for all classification backends @author Gustavo Pichorim Boiko */ -class KTClassifBackend : public KTPlugin +class KTClassifBackend : public QObject { Q_OBJECT public: @@ -38,8 +40,10 @@ ~KTClassifBackend(); - virtual void parseResults(const QValueList<float> &results); - virtual void parseSampleResults(const QValueList<float> &results, int sampleClass); + virtual void doTraining(const QValueList<dataEntry>& data, int inputs, int outputs); + virtual void doClassify(const QValueList<dataEntry>& data, int inputs, int outputs); + + virtual QString classifierName(); }; #endif Index: ktmethod.cpp =================================================================== RCS file: /cvsroot/kimageprocess/kimageprocess/src/libkimageprocess/ktmethod.cpp,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- ktmethod.cpp 23 Jun 2005 18:33:51 -0000 1.7 +++ ktmethod.cpp 23 Jun 2005 23:19:41 -0000 1.8 @@ -33,10 +33,9 @@ //do nothing here too } -void KTMethod::calculate(KTImage *img, KTClassifBackend *backend, int imgClass) +void KTMethod::calculate(KTImage *img, int imgClass) { Q_UNUSED(img); - Q_UNUSED(backend); Q_UNUSED(imgClass); } |