From f19e5e8aaa58c18b3fc20fb3f444dfd38893b584 Mon Sep 17 00:00:00 2001 From: even <philippe.even@loria.fr> Date: Mon, 7 Jan 2019 09:07:51 +0100 Subject: [PATCH] Hough removed --- Code/Seg/BSTools/bsaccumulatoritem.cpp | 170 ----- Code/Seg/BSTools/bsaccumulatoritem.h | 143 ---- Code/Seg/BSTools/bsaccumulatorview.cpp | 87 --- Code/Seg/BSTools/bsaccumulatorview.h | 42 -- Code/Seg/BSTools/bsdetectionwidget.cpp | 86 ++- Code/Seg/BSTools/bsdetectionwidget.h | 8 +- Code/Seg/BSTools/bsstructureview.cpp | 40 +- Code/Seg/BSTools/bsstructureview.h | 16 +- Code/Seg/BSTools/bswindow.cpp | 8 +- Code/Seg/BSTools/bswindow.h | 4 +- .../BlurredSegment/blurredsegmentproto.cpp | 4 +- Code/Seg/BlurredSegment/bsdetector.cpp | 21 +- Code/Seg/BlurredSegment/bsdetector.h | 16 +- Code/Seg/BlurredSegment/bsfilter.cpp | 56 ++ Code/Seg/BlurredSegment/bsfilter.h | 74 ++ Code/Seg/BlurredSegment/linespacefilter.cpp | 694 ------------------ Code/Seg/BlurredSegment/linespacefilter.h | 295 -------- Code/Seg/Seg.pro | 8 +- Code/Seg/main.cpp | 4 +- 19 files changed, 294 insertions(+), 1482 deletions(-) delete mode 100755 Code/Seg/BSTools/bsaccumulatoritem.cpp delete mode 100755 Code/Seg/BSTools/bsaccumulatoritem.h delete mode 100755 Code/Seg/BSTools/bsaccumulatorview.cpp delete mode 100755 Code/Seg/BSTools/bsaccumulatorview.h create mode 100755 Code/Seg/BlurredSegment/bsfilter.cpp create mode 100755 Code/Seg/BlurredSegment/bsfilter.h delete mode 100755 Code/Seg/BlurredSegment/linespacefilter.cpp delete mode 100755 Code/Seg/BlurredSegment/linespacefilter.h diff --git a/Code/Seg/BSTools/bsaccumulatoritem.cpp b/Code/Seg/BSTools/bsaccumulatoritem.cpp deleted file mode 100755 index 30d1306..0000000 --- a/Code/Seg/BSTools/bsaccumulatoritem.cpp +++ /dev/null @@ -1,170 +0,0 @@ -#include <QtGui> -#include <iostream> -#include <cmath> -#include "bsaccumulatoritem.h" - -using namespace std; - - - -const int BSAccumulatorItem::DEFAULT_PEN_WIDTH = 1; -const int BSAccumulatorItem::LEFT_MARGIN = 16; -const int BSAccumulatorItem::TEXT_HEIGHT = 16; - - -BSAccumulatorItem::BSAccumulatorItem (BSDetector *sd, int w, int h) -{ - detector = sd; - width = w; - height = h; - selaccu = (sd->isFiltering (BSDetector::STEP_FINAL) ? - BSDetector::STEP_FINAL : BSDetector::STEP_INITIAL); - map[0] = NULL; - map[1] = NULL; - solution[0] = -1; - solution[1] = -1; - resol[0] = 1.; - resol[1] = 1.; - mask = NULL; - verbose = true; - infoPen = QPen (Qt::red, DEFAULT_PEN_WIDTH, Qt::SolidLine, - Qt::RoundCap, Qt::RoundJoin); - scalePen = QPen (Qt::red, 2); - markPen = QPen (Qt::blue, 4); -} - - -BSAccumulatorItem::~BSAccumulatorItem () -{ - delete [] map[0]; - delete [] map[1]; -} - - -QRectF BSAccumulatorItem::boundingRect () const -{ - return QRectF (0, 0, width, height); -} - - -void BSAccumulatorItem::paint (QPainter *painter, - const QStyleOptionGraphicsItem *option, - QWidget *widget) -{ - Q_UNUSED (option); - Q_UNUSED (widget); - - if (! (detector->getBlurredSegments().empty () - && detector->isFiltering (selaccu))) - { - painter->fillRect (0, 0, width, height, QBrush (Qt::black)); - return; - } - - // Updates the grid - LineSpaceFilter *hugues = detector->getFilter (selaccu); - int nbc = hugues->width (); - int nbl = hugues->height (); - int cw = width / nbc; - int ch = height / nbl; - - // Updates the accumulator - if (map[selaccu] == NULL) map[selaccu] = new uchar[nbc * nbl]; - hugues->getAccumulator (map[selaccu], solution); - resol[0] = hugues->angularResolution () * 180. / M_PI; - resol[1] = hugues->distanceResolution (); - mask = hugues->getMask (); - - // Draws the accumulator - if (solution[0] >= 0) - { - uchar *pix = map[selaccu]; - for (int i = 0; i < nbc * nbl; i++, pix++) - painter->fillRect ((i % nbc) * cw, (nbl - 1 - i / nbc) * ch, cw, ch, - QBrush (QColor ((int) *pix, (int) *pix, (int) *pix))); - - // Marks the filtering cells - if (mask != NULL) - { - painter->setPen (markPen); - bool *maski = mask; - for (int j = 0; j < nbl; j++) - for (int i = 0; i < nbc; i++) - if (*maski++) - painter->drawPoint ((i + 0.5) * cw, (nbl - j - 0.5) * ch); - } - - if (verbose) - { - // Displays the scale (one radian / one pixel) - painter->setPen (scalePen); - int sh = (int) (ch / resol[1] + 0.5); - painter->drawRect (0, height - 1 - sh, (int) (cw / resol[0] + 0.5), sh); - - // Displays information - initText (painter); - addText (painter, QString ("S size : ") + QString::number (nbc) - + QString ("x") + QString::number (nbl)); - addText (painter, QString ("R resolution : ") - + QString::number (resol[0]) + QString (" pixels x ") - + QString::number (resol[1]) + QString (" degrees")); - addText (painter, QString ("W sub-pixellisation level : ") - + QString::number (hugues->getSubpix ())); - addText (painter, QString ("F selectivity : ") - + QString::number (hugues->getSelectionThreshold ()) - + QString ("% of max vote")); - } - } -} - - -bool BSAccumulatorItem::resizeAccumulator (bool larger) -{ - if (! detector->isFiltering (selaccu)) return false; - LineSpaceFilter *hugues = detector->getFilter (selaccu); - bool res = hugues->resize (larger); - if (res) - { - delete [] map[selaccu]; - map[selaccu] = new uchar[hugues->width () * hugues->height ()]; - } - return (res); -} - - -bool BSAccumulatorItem::zoomAccumulator (bool in) -{ - if (! detector->isFiltering (selaccu)) return false; - LineSpaceFilter *hugues = detector->getFilter (selaccu); - return (hugues->zoom (in)); -} - - -bool BSAccumulatorItem::subpixellise (bool larger) -{ - if (! detector->isFiltering (selaccu)) return false; - LineSpaceFilter *hugues = detector->getFilter (selaccu); - return (hugues->subpixellise (larger)); -} - - -bool BSAccumulatorItem::setFilterSelectivity (bool larger) -{ - if (! detector->isFiltering (selaccu)) return false; - LineSpaceFilter *hugues = detector->getFilter (selaccu); - return (hugues->setSelectivity (larger)); -} - - -void BSAccumulatorItem::initText (QPainter *painter) -{ - painter->setPen (infoPen); - textOffset = 0; -} - - -void BSAccumulatorItem::addText (QPainter *painter, const QString &text) -{ - textOffset += TEXT_HEIGHT; - painter->drawText (LEFT_MARGIN, textOffset, text); -} diff --git a/Code/Seg/BSTools/bsaccumulatoritem.h b/Code/Seg/BSTools/bsaccumulatoritem.h deleted file mode 100755 index 6095f22..0000000 --- a/Code/Seg/BSTools/bsaccumulatoritem.h +++ /dev/null @@ -1,143 +0,0 @@ -#ifndef BS_ACCUMULATOR_ITEM_H -#define BS_ACCUMULATOR_ITEM_H - -#include <QGraphicsItem> -#include "bsdetector.h" - - -/** - * @class BSAccumulatorItem bsaccumulatoritem.h - * \brief Hough accumulator grid display and control. - * \author {P. Even} - */ -class BSAccumulatorItem : public QGraphicsItem -{ - -public: - - /** - * \brief Creates a Hough accumulator grid. - * @param sd Associated blurred segment detector. - * @param w Accumulator width. - * @param h Accumulator height. - */ - BSAccumulatorItem (BSDetector *sd, int w, int h); - - /** Deletes the Hough accumulator grid. - */ - ~BSAccumulatorItem (); - - /** \brief Inquires if the pre-filter accumulator is displayed. - */ - inline bool isPrefilterDisplayed () const { - return (selaccu == BSDetector::STEP_INITIAL); } - - /** \brief Switches the displayed accumulator filter. - */ - inline void switchAccumulator () { - selaccu = (selaccu != BSDetector::STEP_INITIAL ? - BSDetector::STEP_INITIAL : BSDetector::STEP_FINAL); } - - /** \brief Returns the size of the filter accumulator graphics item. - */ - QRectF boundingRect () const; - - /** \brief Draws the accumulator of the selected filter. - */ - void paint (QPainter *painter, - const QStyleOptionGraphicsItem *option, QWidget *widget); - - /** - * \brief Returns the accumulator width. - */ - inline int getWidth () const { return width; } - - /** - * \brief Returns the accumulator height. - */ - inline int getHeight () const { return height; } - - /** - * \brief Switches on or off the information text display modality. - */ - inline void switchInfoDisplay () { verbose = ! verbose; } - - /** \brief Resizes the accumulator array. - * @param larger Sets larger if true, smaller otherwise. - */ - bool resizeAccumulator (bool larger); - - /** \brief Zooms in or out the accumulator array. - * @param in Zooms in if true, out otherwise. - */ - bool zoomAccumulator (bool in); - - /** \brief Modifies the subpixellisation of the accumulator array. - * @param in Sets larger if true, smaller otherwise. - */ - bool subpixellise (bool larger); - - /** \brief Modifies the filter selectivity. - * @param larger Makes the filter more selective if true, less otherwise. - */ - bool setFilterSelectivity (bool larger); - - -private: - - /** Default value for pen width. */ - static const int DEFAULT_PEN_WIDTH; - /** Left margin for information text. */ - static const int LEFT_MARGIN; - /** Information text height. */ - static const int TEXT_HEIGHT; - - - /** Blurred segment detector. */ - BSDetector *detector; - /** Accumulator displayed (1 = prefilter, 0 = final filter). */ - int selaccu; - - /** Accumulator width. */ - int width; - /** Accumulator height. */ - int height; - /** Contents of the accumulator. - * The array of vote counts for each cell. */ - uchar *map[2]; - /** Coordinates of the cell with the highest vote. */ - int solution[2]; - /** Accumulator scale in pixels. - * One radian for the angles, and one pixel for the distances. */ - double resol[2]; - /** Contents of the applied accumulator mask. - * An array of booleans values for each cell, - * that are set to true if the cell belongs to the mask. */ - bool *mask; - - /** Information text modality. */ - bool verbose; - /** Information text style. */ - QPen infoPen; - /** Information text vertical offset. */ - int textOffset; - /** Scale display style. */ - QPen scalePen; - /** Mark display style. */ - QPen markPen; - - - /** - * \brief Initializes the text display (color and position). - * @param painter : Painter to be decorated. - */ - void initText (QPainter *painter); - - /** - * \brief Paints a new text in the graphics item (updates text position). - * @param painter : Painter to be decorated. - * @param text : Text to be displayed. - */ - void addText (QPainter *painter, const QString &text); -}; -#endif diff --git a/Code/Seg/BSTools/bsaccumulatorview.cpp b/Code/Seg/BSTools/bsaccumulatorview.cpp deleted file mode 100755 index a316774..0000000 --- a/Code/Seg/BSTools/bsaccumulatorview.cpp +++ /dev/null @@ -1,87 +0,0 @@ -#include <QtGui> -#include <iostream> -#include "bsaccumulatorview.h" - -using namespace std; - - -const int BSAccumulatorView::CELL_SIZE = 12; - - -BSAccumulatorView::BSAccumulatorView (BSDetector *sd) -{ - int w = LineSpaceFilter::DEFAULT_NB_ANG_CELLS * CELL_SIZE; - int h = LineSpaceFilter::DEFAULT_NB_DIST_CELLS * CELL_SIZE; - setBackgroundBrush (QBrush (Qt::yellow)); - setScene (new QGraphicsScene (0, 0, w, h)); - grid = new BSAccumulatorItem (sd, w, h); - scene()->addItem (grid); - setWindowTitle (grid->isPrefilterDisplayed () ? - "Pre-filter accumulator" : "Final filter accumulator"); -} - - -BSAccumulatorView::~BSAccumulatorView () -{ - scene()->removeItem (grid); - delete grid; -} - - -void BSAccumulatorView::paint (QPainter *painter, - const QStyleOptionGraphicsItem *option, - QWidget *widget) -{ - Q_UNUSED (painter); - Q_UNUSED (option); - Q_UNUSED (widget); -} - - -bool BSAccumulatorView::processKeyEvent (QKeyEvent *event) -{ - bool processed = false; - switch (event->key ()) - { - case Qt::Key_I : - grid->switchAccumulator (); - setWindowTitle (grid->isPrefilterDisplayed () ? - "Pre-filter accumulator" : "Final filter accumulator"); - processed = true; - break; - - case Qt::Key_V : - grid->switchInfoDisplay (); - processed = true; - break; - - case Qt::Key_S : - processed = grid->resizeAccumulator ( - (event->modifiers () & Qt::ShiftModifier) == 0); - break; - - case Qt::Key_R : - processed = grid->zoomAccumulator ( - (event->modifiers () & Qt::ShiftModifier) == 0); - break; - - case Qt::Key_W : - processed = grid->subpixellise ( - (event->modifiers () & Qt::ShiftModifier) != 0); - break; - - case Qt::Key_F : - processed = grid->setFilterSelectivity ( - (event->modifiers () & Qt::ShiftModifier) == 0); - break; - - case Qt::Key_P : // Capture - // viewport()->grab ( - // QRect (QPoint (0, 0), - // QSize (grid->getWidth(), grid->getHeight())) - // ).toImage().save ("accu.png"); - // cout << "Accumulator shot in capture.png" << endl; - break; - } - return processed; -} diff --git a/Code/Seg/BSTools/bsaccumulatorview.h b/Code/Seg/BSTools/bsaccumulatorview.h deleted file mode 100755 index 75ccfeb..0000000 --- a/Code/Seg/BSTools/bsaccumulatorview.h +++ /dev/null @@ -1,42 +0,0 @@ -#ifndef BS_ACCUMULATOR_H -#define BS_ACCUMULATOR_H - -#include <QGraphicsView> -#include "bsaccumulatoritem.h" - - -class BSAccumulatorView : public QGraphicsView -{ - -public: - - /** - * \brief Creates an accumulator analyzer. - */ - BSAccumulatorView (BSDetector *sd); - - /** - * \brief Deletes the accumulator analyzer. - */ - ~BSAccumulatorView (); - - /** - * \brief Redraws the accumulator analyzer. - */ - void paint (QPainter *painter, - const QStyleOptionGraphicsItem *option, QWidget *widget); - - /** - * \brief Processes key pressed events. - */ - bool processKeyEvent (QKeyEvent *event); - -protected: - -private: - static const int CELL_SIZE; - BSAccumulatorItem *grid; - -}; - -#endif diff --git a/Code/Seg/BSTools/bsdetectionwidget.cpp b/Code/Seg/BSTools/bsdetectionwidget.cpp index 33d7e77..e6e535c 100755 --- a/Code/Seg/BSTools/bsdetectionwidget.cpp +++ b/Code/Seg/BSTools/bsdetectionwidget.cpp @@ -31,7 +31,7 @@ BSDetectionWidget::BSDetectionWidget (QWidget *parent) // Initializes the gradient map and the auxiliary views gMap = NULL; - accuview = NULL; + // accuview = NULL; strucview = NULL; profileview = NULL; idetview = NULL; @@ -57,8 +57,10 @@ BSDetectionWidget::BSDetectionWidget (QWidget *parent) BSDetectionWidget::~BSDetectionWidget () { - if (accuview != NULL) delete accuview; + // if (accuview != NULL) delete accuview; if (strucview != NULL) delete strucview; + if (profileview != NULL) delete profileview; + if (idetview != NULL) delete idetview; } @@ -179,6 +181,7 @@ void BSDetectionWidget::paintEvent (QPaintEvent *) } +/* void BSDetectionWidget::closeAccuAnalyzer () { if (accuview != NULL) @@ -188,6 +191,7 @@ void BSDetectionWidget::closeAccuAnalyzer () accuview = NULL; } } +*/ void BSDetectionWidget::closePixelAnalyzer () @@ -223,6 +227,7 @@ void BSDetectionWidget::closeIdetAnalyzer () } +/* void BSDetectionWidget::switchAccuAnalyzer () { if (accuview != NULL) @@ -237,6 +242,7 @@ void BSDetectionWidget::switchAccuAnalyzer () accuview->show (); } } +*/ void BSDetectionWidget::switchPixelAnalyzer () @@ -801,7 +807,7 @@ void BSDetectionWidget::keyPressEvent (QKeyEvent *event) break; case Qt::Key_2 : - switchAccuAnalyzer (); + // switchAccuAnalyzer (); break; case Qt::Key_3 : @@ -847,10 +853,10 @@ void BSDetectionWidget::keyPressEvent (QKeyEvent *event) { if (strucview->processKeyEvent (event)) extract (); } - else if (accuview != NULL && accuview->isActiveWindow ()) + /* else if (accuview != NULL && accuview->isActiveWindow ()) { if (accuview->processKeyEvent (event)) extract (); - } + } */ else if (profileview != NULL && profileview->isActiveWindow ()) { if (profileview->processKeyEvent (event)) extract (); @@ -1083,7 +1089,7 @@ void BSDetectionWidget::displayDetectionResult () profileview->buildScans (p1, p2); profileview->scene()->update (); } - if (accuview != NULL) accuview->scene()->update (); + // if (accuview != NULL) accuview->scene()->update (); if (strucview != NULL) { strucview->scene()->update (); @@ -1519,7 +1525,7 @@ QSize BSDetectionWidget::setRandomImage (int type) AbsRat biasVal (7, 5); bool dispEach = false; bool dispLast = false; - int nbruns = 100; + int nbruns = 1000; int nbIniPts[nbruns]; int oldTrials[nbruns]; int newTrials[nbruns]; @@ -1541,6 +1547,10 @@ QSize BSDetectionWidget::setRandomImage (int type) int newFalse[nbruns]; double oldPrec[nbruns]; double newPrec[nbruns]; + double oldRecall[nbruns]; + double newRecall[nbruns]; + double oldFmeas[nbruns]; + double newFmeas[nbruns]; double oldNbMatched[nbruns]; double newNbMatched[nbruns]; double oldWidthBias[nbruns]; @@ -1766,13 +1776,18 @@ if (nbIniPts[run] == 0) cout << "CARTE VIDE" << endl; for (int i = 0; i < width * height; i++) if (detmap[i] < 0) oldFalse[run] ++; oldPrec[run] = nbIniPts[run] - oldUndet[run]; + oldRecall[run] = oldPrec[run] / nbIniPts[run]; oldPrec[run] = oldPrec[run] / (oldPrec[run] + oldFalse[run]); + oldFmeas[run] = 2 * oldPrec[run] * oldRecall[run] + / (oldPrec[run] + oldRecall[run]); if (dispEach) { cout << oldFalse[run] << " false points detected on " << nbIniPts[run] << " (" << oldFalse[run] * 100 / (double) nbIniPts[run] << " %)" << endl; cout << "Precision : " << oldPrec[run] << endl; + cout << "Recall : " << oldRecall[run] << endl; + cout << "F-measure : " << oldFmeas[run] << endl; cout << oldNbNomatch[run] << " unmatched blurred segment (mean length : " << (oldNbNomatch[run] != 0 ? nomatchlength / oldNbNomatch[run] : 0) << ")" << endl; @@ -1985,13 +2000,18 @@ if (nbIniPts[run] == 0) cout << "CARTE VIDE" << endl; for (int i = 0; i < width * height; i++) if (detmap[i] < 0) newFalse[run] ++; newPrec[run] = nbIniPts[run] - newUndet[run]; + newRecall[run] = newPrec[run] / nbIniPts[run]; newPrec[run] = newPrec[run] / (newPrec[run] + newFalse[run]); + newFmeas[run] = 2 * newPrec[run] * newRecall[run] + / (newPrec[run] + newRecall[run]); if (dispEach) { cout << newFalse[run] << " false points detected on " << nbIniPts[run] << " (" << newFalse[run] * 100 / (double) nbIniPts[run] << " %)" << endl; cout << "Precision : " << newPrec[run] << endl; + cout << "Recall : " << newRecall[run] << endl; + cout << "F-measure : " << newFmeas[run] << endl; cout << newNbNomatch[run] << " unmatched blurred segment (mean length : " << (newNbNomatch[run] != 0 ? nomatchlength / newNbNomatch[run] : 0) << ")" << endl; @@ -2124,7 +2144,7 @@ if (nbIniPts[run] == 0) cout << "CARTE VIDE" << endl; sdev += ((nbIniPts[i] - oldUndet[i]) / (double) nbIniPts[i] - mean) * ((nbIniPts[i] - oldUndet[i]) / (double) nbIniPts[i] - mean); sdev = sqrt (sdev / (nbruns - 1)); - cout << 100 * mean << " (pm " << 100 * sdev + cout << "Recall : " << 100 * mean << " (pm " << 100 * sdev << ") % of points found" << endl; mean = 0.; sdev = 0.; @@ -2160,6 +2180,30 @@ if (nbIniPts[run] == 0) cout << "CARTE VIDE" << endl; sdev += (oldPrec[i] - mean) * (oldPrec[i] - mean); sdev = sqrt (sdev / (nbruns - 1)); cout << "Precision : " << mean << " (pm " << sdev << ")" << endl; + mean = 0.; + sdev = 0.; + for (int i = 0; i < nbruns; i++) mean += oldPrec[i]; + mean /= nbruns; + for (int i = 0; i < nbruns; i++) + sdev += (oldPrec[i] - mean) * (oldPrec[i] - mean); + sdev = sqrt (sdev / (nbruns - 1)); + cout << "Statistical precision : " << mean << " (pm " << sdev << ")" << endl; + mean = 0.; + sdev = 0.; + for (int i = 0; i < nbruns; i++) mean += oldRecall[i]; + mean /= nbruns; + for (int i = 0; i < nbruns; i++) + sdev += (oldRecall[i] - mean) * (oldRecall[i] - mean); + sdev = sqrt (sdev / (nbruns - 1)); + cout << "Statistical recall : " << mean << " (pm " << sdev << ")" << endl; + mean = 0.; + sdev = 0.; + for (int i = 0; i < nbruns; i++) mean += oldFmeas[i]; + mean /= nbruns; + for (int i = 0; i < nbruns; i++) + sdev += (oldFmeas[i] - mean) * (oldFmeas[i] - mean); + sdev = sqrt (sdev / (nbruns - 1)); + cout << "Statistical F-measure : " << mean << " (pm " << sdev << ")" << endl; total = 0; for (int i = 0; i < nbruns; i++) total += oldNbMatched[i]; mean = 0.; @@ -2278,7 +2322,7 @@ if (nbIniPts[run] == 0) cout << "CARTE VIDE" << endl; sdev += ((nbIniPts[i] - newUndet[i]) / (double) nbIniPts[i] - mean) * ((nbIniPts[i] - newUndet[i]) / (double) nbIniPts[i] - mean); sdev = sqrt (sdev / (nbruns - 1)); - cout << 100 * mean << " (pm " << 100 * sdev + cout << "Recall : " << 100 * mean << " (pm " << 100 * sdev << ") % of points found" << endl; mean = 0.; sdev = 0.; @@ -2314,6 +2358,30 @@ if (nbIniPts[run] == 0) cout << "CARTE VIDE" << endl; sdev += (newPrec[i] - mean) * (newPrec[i] - mean); sdev = sqrt (sdev / (nbruns - 1)); cout << "Precision : " << mean << " (pm " << sdev << ")" << endl; + mean = 0.; + sdev = 0.; + for (int i = 0; i < nbruns; i++) mean += newPrec[i]; + mean /= nbruns; + for (int i = 0; i < nbruns; i++) + sdev += (newPrec[i] - mean) * (newPrec[i] - mean); + sdev = sqrt (sdev / (nbruns - 1)); + cout << "Statistical precision : " << mean << " (pm " << sdev << ")" << endl; + mean = 0.; + sdev = 0.; + for (int i = 0; i < nbruns; i++) mean += newRecall[i]; + mean /= nbruns; + for (int i = 0; i < nbruns; i++) + sdev += (newRecall[i] - mean) * (newRecall[i] - mean); + sdev = sqrt (sdev / (nbruns - 1)); + cout << "Statistical recall : " << mean << " (pm " << sdev << ")" << endl; + mean = 0.; + sdev = 0.; + for (int i = 0; i < nbruns; i++) mean += newFmeas[i]; + mean /= nbruns; + for (int i = 0; i < nbruns; i++) + sdev += (newFmeas[i] - mean) * (newFmeas[i] - mean); + sdev = sqrt (sdev / (nbruns - 1)); + cout << "Statistical F-measure : " << mean << " (pm " << sdev << ")" << endl; total = 0; for (int i = 0; i < nbruns; i++) total += newNbMatched[i]; mean = 0.; diff --git a/Code/Seg/BSTools/bsdetectionwidget.h b/Code/Seg/BSTools/bsdetectionwidget.h index dc02ffe..57993cb 100755 --- a/Code/Seg/BSTools/bsdetectionwidget.h +++ b/Code/Seg/BSTools/bsdetectionwidget.h @@ -8,7 +8,7 @@ #include <QVector> #include <fstream> #include "bsdetector.h" -#include "bsaccumulatorview.h" +// #include "bsaccumulatorview.h" #include "bsstructureview.h" #include "bsprofileview.h" #include "bsidetview.h" @@ -88,7 +88,7 @@ void createMap (QString name, bool *tofind, bool *found, int iw, int ih); /** * \brief Requires the accumulation window closure. */ - void closeAccuAnalyzer (); + // void closeAccuAnalyzer (); /** * \brief Requires the pixel analysis window closure. @@ -113,7 +113,7 @@ void createMap (QString name, bool *tofind, bool *found, int iw, int ih); /** * \brief Switches the accumulator display window on or off. */ - void switchAccuAnalyzer (); + // void switchAccuAnalyzer (); /** * \brief Switches the profile display window on or off. @@ -278,7 +278,7 @@ private: /** Scanned profile graphics view. */ BSProfileView *profileview; /** Filter accumulator view. */ - BSAccumulatorView *accuview; + // BSAccumulatorView *accuview; /** Blurred segment contents view. */ BSStructureView *strucview; diff --git a/Code/Seg/BSTools/bsstructureview.cpp b/Code/Seg/BSTools/bsstructureview.cpp index 606444f..758d5ce 100755 --- a/Code/Seg/BSTools/bsstructureview.cpp +++ b/Code/Seg/BSTools/bsstructureview.cpp @@ -20,6 +20,7 @@ BSStructureView::BSStructureView (QImage *im, BSDetector *sd) graylevelImage = im; currentImage = im; gradImage = NULL; + blevel = 0; det = sd; setBackgroundBrush (QBrush (*currentImage)); setScene (new QGraphicsScene (0, 0, w, h)); @@ -54,6 +55,18 @@ void BSStructureView::updateBackground () int h = currentImage->height (); int zf = grid->zoomFactor (); image = currentImage->scaled (w * zf, h * zf); + + if (blevel != 0) + { + for (int i = 0; i < image.height (); i++) + for(int j = 0; j < image.width (); j++) + { + int col = blevel + (QColor (image.pixel(j,i)).value () + * (255 - blevel)) / 255; + image.setPixel (j, i, col + col * 256 + col * 256 * 256); + } + } + QBrush qb (image); qb.setTransform (QTransform::fromTranslate ( w / 2 - zf * (w / 2 + grid->focusX ()), @@ -71,6 +84,14 @@ void BSStructureView::toggleBackground () } +void BSStructureView::incBlackLevel (int val) +{ + blevel += val * 5; + if (blevel < 0) blevel = 0; + if (blevel > 200) blevel = 200; +} + + void BSStructureView::paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) @@ -124,11 +145,20 @@ bool BSStructureView::processKeyEvent (QKeyEvent *event) break; case Qt::Key_P : // Capture - // viewport()->grab ( - // QRect (QPoint (0, 0), - // QSize (grid->getWidth(), grid->getHeight())) - // ).toImage().save ("structure.png"); - // cout << "Structure shot in structure.png" << endl; + viewport()->grab ( + QRect (QPoint (0, 0), + QSize (grid->getWidth(), grid->getHeight())) + ).toImage().save ("structure.png"); + cout << "Structure shot in structure.png" << endl; + break; + + case Qt::Key_Y : // Background lightening + incBlackLevel ((event->modifiers () & Qt::ShiftModifier) ? -1 : 1); + updateBackground (); + scene()->update (); + update (); + cout << "Background black level = " << getBlackLevel () << endl; + processed = false; break; case Qt::Key_Plus : // Zoom in diff --git a/Code/Seg/BSTools/bsstructureview.h b/Code/Seg/BSTools/bsstructureview.h index 51f407a..e113dd8 100755 --- a/Code/Seg/BSTools/bsstructureview.h +++ b/Code/Seg/BSTools/bsstructureview.h @@ -66,9 +66,12 @@ private: QImage *gradImage; /** Effective background image. */ QImage image; + /** Black level used to lighten background images. */ + int blevel; /** - * Updates the background image. + +* Updates the background image. */ void updateBackground (); @@ -77,6 +80,17 @@ private: */ void toggleBackground (); + /** + * \brief Returns the background black level. + */ + inline int getBlackLevel () const { return (blevel); } + + /** + * Increments the background intensity. + * @param val Increment value. + */ + void incBlackLevel (int val); + }; #endif diff --git a/Code/Seg/BSTools/bswindow.cpp b/Code/Seg/BSTools/bswindow.cpp index 4eae19d..4ea7253 100755 --- a/Code/Seg/BSTools/bswindow.cpp +++ b/Code/Seg/BSTools/bswindow.cpp @@ -10,7 +10,7 @@ BSWindow::BSWindow (int *val) Q_UNUSED (val); showIdet = false; showProf = false; - showAccu = false; + // showAccu = false; showSeg = false; gradType = VMap::TYPE_SOBEL_5X5; detectionWidget = new BSDetectionWidget; @@ -27,7 +27,7 @@ BSWindow::BSWindow () { showIdet = false; showProf = false; - showAccu = false; + // showAccu = false; showSeg = false; gradType = 0; detectionWidget = new BSDetectionWidget; @@ -58,7 +58,7 @@ void BSWindow::runOptions () { if (showIdet) detectionWidget->switchIdetAnalyzer (); if (showProf) detectionWidget->switchProfileAnalyzer (); - if (showAccu) detectionWidget->switchAccuAnalyzer (); + // if (showAccu) detectionWidget->switchAccuAnalyzer (); if (showSeg) detectionWidget->switchPixelAnalyzer (); } @@ -73,7 +73,7 @@ void BSWindow::closeEvent (QCloseEvent *event) { detectionWidget->closeIdetAnalyzer (); detectionWidget->closeProfileAnalyzer (); - detectionWidget->closeAccuAnalyzer (); + // detectionWidget->closeAccuAnalyzer (); detectionWidget->closePixelAnalyzer (); event->accept (); } diff --git a/Code/Seg/BSTools/bswindow.h b/Code/Seg/BSTools/bswindow.h index 6fd9e46..441147b 100755 --- a/Code/Seg/BSTools/bswindow.h +++ b/Code/Seg/BSTools/bswindow.h @@ -50,7 +50,7 @@ public: /** * Switches the accumulator analysis window on or off. */ - inline void toggleAccuWindow () { showAccu = ! showAccu; } + // inline void toggleAccuWindow () { showAccu = ! showAccu; } /** * Switches the segment analysis window on or off. @@ -89,7 +89,7 @@ private: BSDetectionWidget *detectionWidget; bool showIdet; bool showProf; - bool showAccu; + // bool showAccu; bool showSeg; int gradType; diff --git a/Code/Seg/BlurredSegment/blurredsegmentproto.cpp b/Code/Seg/BlurredSegment/blurredsegmentproto.cpp index 957e06c..99786a5 100755 --- a/Code/Seg/BlurredSegment/blurredsegmentproto.cpp +++ b/Code/Seg/BlurredSegment/blurredsegmentproto.cpp @@ -38,13 +38,13 @@ BlurredSegmentProto::BlurredSegmentProto (int maxWidth, Pt2i center, { if (itr == rightPts.end ()) scanningRight = false; else - addRight (*itr++); + if (! addRight (*itr++)) scanningRight = false; } if (scanningLeft) { if (itl == leftPts.end ()) scanningLeft = false; else - addLeft (*itl++); + if (! addLeft (*itl++)) scanningLeft = false; } } } diff --git a/Code/Seg/BlurredSegment/bsdetector.cpp b/Code/Seg/BlurredSegment/bsdetector.cpp index 2d0f8d2..a4b1b26 100755 --- a/Code/Seg/BlurredSegment/bsdetector.cpp +++ b/Code/Seg/BlurredSegment/bsdetector.cpp @@ -1,4 +1,5 @@ #include "bsdetector.h" +//#include "linespacefilter.h" const string BSDetector::VERSION = "0.1.5"; @@ -50,9 +51,11 @@ BSDetector::BSDetector () oldp = false; prefilteringOn = false; - lsf1 = (prefilteringOn ? new LineSpaceFilter () : NULL); + //lsf1 = (prefilteringOn ? new LineSpaceFilter () : NULL); + lsf1 = (prefilteringOn ? new BSFilter () : NULL); filteringOn = false; - lsf2 = (filteringOn ? new LineSpaceFilter () : NULL); + //lsf2 = (filteringOn ? new LineSpaceFilter () : NULL); + lsf2 = (filteringOn ? new BSFilter () : NULL); edgeDirection = 0; // detects strokes (not only edges) bsMinSize = DEFAULT_BS_MIN_SIZE; @@ -500,8 +503,8 @@ void BSDetector::detect (const Pt2i &p1, const Pt2i &p2, } } - // Hough filtering on the initial segment - //--------------------------------------- + // Filtering the initial segment + //------------------------------ if (prefilteringOn) { BlurredSegment *fbs = lsf1->filter (bsini); @@ -614,8 +617,8 @@ void BSDetector::detect (const Pt2i &p1, const Pt2i &p2, } - // Line space filtering - //--------------------- + // Final filtering + //---------------- if (filteringOn) { BlurredSegment *fbsf = lsf2->filter (bsf); @@ -715,12 +718,14 @@ void BSDetector::switchFiltering (int step) if (step == STEP_FINAL) { filteringOn = ! filteringOn; - if (filteringOn && lsf2 == NULL) lsf2 = new LineSpaceFilter (); + //if (filteringOn && lsf2 == NULL) lsf2 = new LineSpaceFilter (); + if (filteringOn && lsf2 == NULL) lsf2 = new BSFilter (); } else if (step == STEP_INITIAL) { prefilteringOn = ! prefilteringOn; - if (prefilteringOn && lsf1 == NULL) lsf1 = new LineSpaceFilter (); + //if (prefilteringOn && lsf1 == NULL) lsf1 = new LineSpaceFilter (); + if (prefilteringOn && lsf1 == NULL) lsf1 = new BSFilter (); } } diff --git a/Code/Seg/BlurredSegment/bsdetector.h b/Code/Seg/BlurredSegment/bsdetector.h index d53850a..85f352b 100755 --- a/Code/Seg/BlurredSegment/bsdetector.h +++ b/Code/Seg/BlurredSegment/bsdetector.h @@ -2,7 +2,7 @@ #define BLURRED_SEGMENT_DETECTOR_H #include "bstracker.h" -#include "linespacefilter.h" +#include "bsfilter.h" using namespace std; @@ -442,14 +442,14 @@ public: inline bool isOneFilterSet () { return (filteringOn || prefilteringOn); } /** - * \brief Returns the line space based filter. + * \brief Returns a blurred segment filter. * @param step Initial step addressed if set to 0, final step otherwise. */ - inline LineSpaceFilter *getFilter (int step) const { + inline BSFilter *getFilter (int step) const { return (step == STEP_FINAL ? lsf2 : lsf1); } /** - * \brief Returns the accepted points by the line space based filter. + * \brief Returns the accepted points by the blurred segment filter. * @param step Initial step addressed if set to 0, final step otherwise. */ inline vector<Pt2i> getAccepted (int step) const { @@ -699,13 +699,13 @@ private : /** Initial segment filtering modality. */ bool prefilteringOn; - /** Line space based pre-filter. */ - LineSpaceFilter *lsf1; + /** Blurred segment pre-filter. */ + BSFilter *lsf1; /** Detected segment filtering modality. */ bool filteringOn; - /** Line space based post-filter. */ - LineSpaceFilter *lsf2; + /** Blurred segment post-filter. */ + BSFilter *lsf2; /** diff --git a/Code/Seg/BlurredSegment/bsfilter.cpp b/Code/Seg/BlurredSegment/bsfilter.cpp new file mode 100755 index 0000000..ba081d3 --- /dev/null +++ b/Code/Seg/BlurredSegment/bsfilter.cpp @@ -0,0 +1,56 @@ +#include "bsfilter.h" +#include "blurredsegmentproto.h" + + + +BSFilter::BSFilter () +{ + bsInitialSize = 0; + bsFinalSize = 0; +} + + +BSFilter::~BSFilter () +{ +} + + +void BSFilter::clear () +{ + leftIn.clear (); + rightIn.clear (); + out.clear (); +} + + +BlurredSegment *BSFilter::filter (BlurredSegment *bs) +{ + leftIn.clear (); + rightIn.clear (); + vector<Pt2i> *pts = bs->getAllLeft (); + vector<Pt2i>::iterator it = pts->end (); + while (it-- != pts->begin ()) leftIn.push_back (*it); + pts = bs->getAllRight (); + it = pts->begin (); + while (it != pts->end ()) rightIn.push_back (*it++); + + int mw = 1; + AbsRat sw = bs->minimalWidth (); + if (sw.denominator () != 0) mw += sw.numerator () / sw.denominator (); + BlurredSegmentProto resbs (mw, bs->getCenter (), leftIn, rightIn); + bsFinalSize = resbs.size (); + return (resbs.endOfBirth ()); +} + + +vector<Pt2i> BSFilter::getAccepted () +{ + vector<Pt2i> res; + for (vector<Pt2i>::iterator it = leftIn.begin (); + it != leftIn.end (); it ++) + res.push_back (*it); + for (vector<Pt2i>::iterator it = rightIn.begin (); + it != rightIn.end (); it ++) + res.push_back (*it); + return res; +} diff --git a/Code/Seg/BlurredSegment/bsfilter.h b/Code/Seg/BlurredSegment/bsfilter.h new file mode 100755 index 0000000..e7bee9c --- /dev/null +++ b/Code/Seg/BlurredSegment/bsfilter.h @@ -0,0 +1,74 @@ +#ifndef BLURRED_SEGMENT_FILTER_H +#define BLURRED_SEGMENT_FILTER_H + +#include <vector> +#include "pt2i.h" +#include "blurredsegment.h" + +using namespace std; + + +/** + * @class Blurred segment filter. + * \author {P. Even} + */ +class BSFilter +{ +public: + + /** + * \brief Creates a empty blurred segment filter. + */ + BSFilter (); + + /** + * \brief Deletes the filter. + */ + virtual ~BSFilter (); + + /** + * \brief Clears the stored information. + */ + virtual void clear (); + + /** \brief Filters and returns a blurred segment. + * @param bs The blurred segment to be processed. + */ + virtual BlurredSegment *filter (BlurredSegment *bs); + + /** + * \brief Returns the accepted points by the line space filter. + */ + vector<Pt2i> getAccepted (); + + /** + * \brief Returns the rejected points by the line space filter. + */ + inline vector<Pt2i> getRejected () const { return out; } + + /** + * \brief Returns the blurred segment size before filtering. + */ + inline int blurredSegmentInitialSize () const { return bsInitialSize; } + + /** + * \brief Returns the blurred segment size after filtering. + */ + inline int blurredSegmentFinalSize () const { return bsFinalSize; } + + +protected : + + /** Blurred segment size before filtering. */ + int bsInitialSize; + /** Blurred segment size after filtering. */ + int bsFinalSize; + /** Accepted left points after line space filtering. */ + vector<Pt2i> leftIn; + /** Accepted right points after line space filtering. */ + vector<Pt2i> rightIn; + /** Rejected points after line space filtering. */ + vector<Pt2i> out; + +}; +#endif diff --git a/Code/Seg/BlurredSegment/linespacefilter.cpp b/Code/Seg/BlurredSegment/linespacefilter.cpp deleted file mode 100755 index 85248f3..0000000 --- a/Code/Seg/BlurredSegment/linespacefilter.cpp +++ /dev/null @@ -1,694 +0,0 @@ -#include <cmath> -#include "linespacefilter.h" -#include "blurredsegmentproto.h" - - - -const int LineSpaceFilter::DEFAULT_NB_ANG_CELLS = 32; -const int LineSpaceFilter::DEFAULT_NB_DIST_CELLS = 32; -const int LineSpaceFilter::MIN_NB_ANG_CELLS = 8; -const int LineSpaceFilter::MAX_NB_ANG_CELLS = 64; -const int LineSpaceFilter::MIN_NB_DIST_CELLS = 8; -const int LineSpaceFilter::MAX_NB_DIST_CELLS = 64; -const int LineSpaceFilter::DEFAULT_SELECTION_THRESHOLD = 75; -const int LineSpaceFilter::MIN_SELECTION_THRESHOLD = 20; -const int LineSpaceFilter::MAX_SELECTION_THRESHOLD = 90; -const int LineSpaceFilter::INC_SELECTION_THRESHOLD = 5; -const int LineSpaceFilter::NO_SUBPIXEL = 1; -const int LineSpaceFilter::MAX_SUBPIXEL = 64; -const int LineSpaceFilter::ANG_DEF_ZOOM = 8; -const int LineSpaceFilter::ANG_MIN_ZOOM = 2; -const int LineSpaceFilter::ANG_MAX_ZOOM = 32; -const int LineSpaceFilter::DIST_DEF_ZOOM = 4; -const int LineSpaceFilter::DIST_MIN_ZOOM = 1; -const int LineSpaceFilter::DIST_MAX_ZOOM = 16; -const int LineSpaceFilter::INPUT_MIN_SIZE = 8; - - -LineSpaceFilter::LineSpaceFilter () -{ - nt = DEFAULT_NB_ANG_CELLS; - nr = DEFAULT_NB_DIST_CELLS; - acc = new int[nt*nr]; - ncos = new double[nt]; - nsin = new double[nt]; - mask = new bool[nt*nr]; - cellMax = -1; - minsel = DEFAULT_SELECTION_THRESHOLD; - azoom = ANG_DEF_ZOOM; - dzoom = DIST_DEF_ZOOM; - nbSubpix = NO_SUBPIXEL; -} - - -LineSpaceFilter::~LineSpaceFilter () -{ - delete [] acc; - delete [] ncos; - delete [] nsin; - delete [] mask; -} - - -void LineSpaceFilter::clear () -{ - leftIn.clear (); - rightIn.clear (); - out.clear (); -} - - -BlurredSegment *LineSpaceFilter::filter (BlurredSegment *bs) -{ - bsInitialSize = 0; - bsFinalSize = 0; - if (bs == NULL || ! bs->isThick ()) return NULL; - bsInitialSize = bs->size (); - if (bsInitialSize < INPUT_MIN_SIZE) return NULL; - - // Gets the line spacefilter - const Pt2i bsstart = bs->getCenter (); - const vector<Pt2i> *bslineleft = bs->getLeftLine (); - const vector<Pt2i> *bsleft = bs->getLeftPoints (); - const vector<Pt2i> *bslineright = bs->getRightLine (); - const vector<Pt2i> *bsright = bs->getRightPoints (); - Vr2i sv = bs->getSupportVector (); - AbsRat segwidth = bs->minimalWidth (); - Vr2i bbs = bs->boundingBoxSize (); - init (bsstart.x (), bsstart.y (), -sv.y (), sv.x (), - sqrt (bbs.x () * bbs.x () + bbs.y () * bbs.y ()), - segwidth.numerator () / (double) segwidth.denominator ()); - vote (bsstart); - for (vector<Pt2i>::const_iterator it = bslineleft->begin (); - it != bslineleft->end (); it ++) - vote (*it); - for (vector<Pt2i>::const_iterator it = bsleft->begin (); - it != bsleft->end (); it ++) - vote (*it); - for (vector<Pt2i>::const_iterator it = bslineright->begin (); - it != bslineright->end (); it ++) - vote (*it); - for (vector<Pt2i>::const_iterator it = bsright->begin (); - it != bsright->end (); it ++) - vote (*it); - findMaxThroughOrigin (); - fitMask (); - - // Filters the previous points - if (! (bsleft->empty ())) - { - vector<Pt2i>::const_iterator mit = bsleft->end (); - do - { - mit --; - if (voteInMask (*mit)) leftIn.push_back (Pt2i (*mit)); - else out.push_back (Pt2i (*mit)); - } - while (mit != bsleft->begin ()); - } - for (vector<Pt2i>::const_iterator it = bsright->begin (); - it != bsright->end (); it ++) - { - if (voteInMask (*it)) rightIn.push_back (Pt2i (*it)); - else out.push_back (Pt2i (*it)); - } - - // Returns a blurred segment with the accepted points - int mw = 1; - AbsRat sw = bs->minimalWidth (); - if (sw.denominator () != 0) mw += sw.numerator () / sw.denominator (); - BlurredSegmentProto resbs (mw, bsstart, leftIn, rightIn); - bsFinalSize = resbs.size (); - return (resbs.endOfBirth ()); -} - - -void LineSpaceFilter::getAccumulator (unsigned char *map, int *solution) -{ - if (cellMax != -1) - { - int max = 0; - for (int i = 0; i < nt * nr; i++) if (acc[i] > max) max = acc[i]; - for (int i = 0; i < nt * nr; i++) - map[i] = (unsigned char) ((acc[i] * 255) / max); - solution[0] = cellMax % nt; - solution[1] = cellMax / nt; - } -} - - -bool LineSpaceFilter::resize (bool larger) -{ - bool ok = false; - if (larger) - { - if (nt > MIN_NB_ANG_CELLS) - { - nt /= 2; - nr /= 2; - ok = true; - } - } - else - { - if (nt < MAX_NB_ANG_CELLS) - { - nt *= 2; - nr *= 2; - ok = true; - } - } - if (ok) - { - delete [] acc; - delete [] ncos; - delete [] nsin; - delete [] mask; - acc = new int[nt*nr]; - ncos = new double[nt]; - nsin = new double[nt]; - mask = new bool[nt*nr]; - } - return (ok); -} - - -bool LineSpaceFilter::zoom (bool in) -{ - bool ok = false; - if (in) - { - if (dzoom > DIST_MIN_ZOOM) - { - dzoom /= 2; - azoom /= 2; - ok = true; - } - } - else - { - if (dzoom < DIST_MAX_ZOOM) - { - dzoom *= 2; - azoom *= 2; - ok = true; - } - } - return (ok); -} - - -bool LineSpaceFilter::subpixellise (bool larger) -{ - bool ok = false; - if (larger) - { - if (nbSubpix < MAX_SUBPIXEL) - { - nbSubpix *= 2; - ok = true; - } - } - else - { - if (nbSubpix > NO_SUBPIXEL) - { - nbSubpix /= 2; - ok = true; - } - } - return (ok); -} - - -bool LineSpaceFilter::setSelectivity (bool larger) -{ - bool ok = false; - if (larger) - { - if (minsel < MAX_SELECTION_THRESHOLD) - { - minsel += INC_SELECTION_THRESHOLD; - ok = true; - } - } - else - { - if (minsel > MIN_SELECTION_THRESHOLD) - { - minsel -= INC_SELECTION_THRESHOLD; - ok = true; - } - } - return (ok); -} - - -vector<Pt2i> LineSpaceFilter::getAccepted () -{ - vector<Pt2i> res; - for (vector<Pt2i>::iterator it = leftIn.begin (); - it != leftIn.end (); it ++) - res.push_back (*it); - for (vector<Pt2i>::iterator it = rightIn.begin (); - it != rightIn.end (); it ++) - res.push_back (*it); - return res; -} - - -void LineSpaceFilter::checkManhattanScan () -{ - if (cellMax == -1) findMax (); // default choice if not already done - int cell0 = cellMax; - int x0 = cell0 % nt; - int y0 = cell0 / nt; - int nrt = nr * nt; - bool poursuite = true; - int tour = 1; -int val = 1; -int vtour = 6; - - while (poursuite) - { - // bottom cell first - int cell = cell0 - nt * tour; - if (cell < 0) - { - // first cell on the diagonal inside the accumulator - cell += (nt + 1) * (1 + (-cell) / nt); - if (cell >= nt) cell = cell0; - } - while (cell < cell0) - { - // process cell HERE -if (tour == vtour) acc[cell] = val++; - cell += nt + 1; - if (cell % nt == 0) cell = cell0; - } - - // right cell next - cell = cell0 + tour; - if (cell % nt <= x0) - { - // first cell on the diagonal inside the accumulator - cell += (nt - 1) * (x0 + tour + 1 - nt); - if (cell >= nrt) cell = cell0; - } - while (cell % nt > x0) - { - // process cell HERE -if (tour == vtour) acc[cell] = val++; - cell += nt - 1; - if (cell >= nrt) cell = cell0; - } - - // top cell next - cell = cell0 + nt * tour; - if (cell >= nrt) - { - // first cell on the diagonal inside the accumulator - cell -= (nt + 1) * (y0 + tour + 1 - nr); - if (cell % nt >= x0) cell = cell0; - } - while (cell / nt > y0) - { - // process cell HERE -if (tour == vtour) acc[cell] = val++; - cell -= nt + 1; - if (cell % nt >= x0) cell = cell0; - } - - // left cell next - cell = cell0 - tour; - if (tour > x0) - { - // first cell on the diagonal inside the accumulator - cell -= (nt - 1) * (tour - x0); - if (cell < 0) cell = cell0; - } - while (cell % nt < x0) - { - // process cell HERE -if (tour == vtour) acc[cell] = val++; - cell -= nt - 1; - if (cell < 0) cell = cell0; - } - - tour ++; - poursuite = (tour != 12); - } -} - - -void LineSpaceFilter::init (double x0, double y0, int a, int b, - double length, double width) -{ - // Clears the accumulator - int *ac = acc; - bool *m = mask; - for (int i = 0; i < nt * nr; i++) - { - *ac++ = 0; - *m++ = false; - } - cellMax = -1; - - // Computes the column values (normal vector deviations) - double w = azoom * width / nt; - double hyp = sqrt (w * w + length * length); - double dcos = length / hyp; - da = acos (dcos); - double dsin = w / hyp; - double n = sqrt (a * a + b * b); - ncos[nt/2] = a / n; - nsin[nt/2] = b / n; - for (int i = nt / 2; i > 0; i--) - { - ncos[i-1] = ncos[i] * dcos + nsin[i] * dsin; - nsin[i-1] = nsin[i] * dcos - ncos[i] * dsin; - } - for (int i = nt / 2 + 1; i < nt; i++) - { - ncos[i] = ncos[i-1] * dcos - nsin[i-1] * dsin; - nsin[i] = nsin[i-1] * dcos + ncos[i-1] * dsin; - } - - // Computes the row values (distance parameter) - cx = x0; - cy = y0; - dr = dzoom * width / nr; - r0 = - ((nr / 2) + 0.5) * dr; -} - - -void LineSpaceFilter::vote (int i, int j) -{ - acc[i + j * nt] ++; -} - - -void LineSpaceFilter::vote (Pt2i pix) -{ - int x = pix.x () - cx; - int y = pix.y () - cy; - for (int i = 0; i < nt; i++) - { - if (nbSubpix == 1) - { - double d = x * ncos[i] + y * nsin[i]; - if (d >= r0) - { - int rho = (int) ((d - r0) / dr); - if (rho < nr) acc[i + rho * nt] ++; - } - } - else - { - for (int ix = 0; ix < nbSubpix; ix ++) - for (int jy = 0; jy < nbSubpix; jy ++) - { - double d = (x + (2 * ix - 15) / 32.) * ncos[i] - + (y + (2 * jy - 15) / 32.) * nsin[i]; - if (d >= r0) - { - int rho = (int) ((d - r0) / dr); - if (rho < nr) acc[i + rho * nt] ++; - } - } - } - } -} - - -void LineSpaceFilter::vote (const vector<Pt2i>& pts) -{ - vector<Pt2i>::const_iterator it = pts.begin (); - while (it != pts.end ()) - { - int x = it->x () - cx; - int y = it->y () - cy; - for (int i = 0; i < nt; i++) - { - if (nbSubpix == 1) - { - double d = x * ncos[i] + y * nsin[i]; - if (d >= r0) - { - int rho = (int) ((d - r0) / dr); - if (rho < nr) acc[i + rho * nt] ++; - } - } - else - { - for (int ix = 0; ix < nbSubpix; ix ++) - for (int jy = 0; jy < nbSubpix; jy ++) - { - double d = (x + (2 * ix - 15) / 32.) * ncos[i] - + (y + (2 * jy - 15) / 32.) * nsin[i]; - if (d >= r0) - { - int rho = (int) ((d - r0) / dr); - if (rho < nr) acc[i + rho * nt] ++; - } - } - } - } - it ++; - } -} - - -bool LineSpaceFilter::voteInMask (Pt2i pix) -{ - int x = pix.x () - cx; - int y = pix.y () - cy; - for (int i = 0; i < nt; i++) - { - if (nbSubpix == 1) - { - double d = x * ncos[i] + y * nsin[i]; - if (d >= r0) - { - int rho = (int) ((d - r0) / dr); - if (rho < nr && mask[i + rho * nt]) return true; - } - } - else - { - for (int ix = 0; ix < nbSubpix; ix ++) - for (int jy = 0; jy < nbSubpix; jy ++) - { - double d = (x + (2 * ix - 15) / 32.) * ncos[i] - + (y + (2 * jy - 15) / 32.) * nsin[i]; - if (d >= r0) - { - int rho = (int) ((d - r0) / dr); - if (rho < nr && mask[i + rho * nt]) return true; - } - } - } - } - return false; -} - - -vector<Pt2i> LineSpaceFilter::voteInMask (vector<Pt2i>& pts) -{ - vector<Pt2i> vpix; - vector<Pt2i>::iterator it = pts.begin (); - while (it != pts.end ()) - { - int x = it->x () - cx; - int y = it->y () - cy; - for (int i = 0; i < nt; i++) - { - double d = x * ncos[i] + y * nsin[i]; - if (d >= r0) - { - int rho = (int) ((d - r0) / dr); - if (rho < nr && mask[i + rho * nt]) vpix.push_back (*it); - } - } - it ++; - } - return (vpix); -} - - -void LineSpaceFilter::findMax () -{ - cellMax = 0; - for (int i = 1; i < nt * nr; i++) - if (acc[i] > acc[cellMax]) cellMax = i; -} - - -void LineSpaceFilter::findMaxThroughOrigin () -{ - cellMax = (nr / 2) * nt; - for (int i = 1; i < nt; i++) - if (acc[cellMax + i] > acc[cellMax]) cellMax = cellMax + i; -} - - -void LineSpaceFilter::fitMask () -{ - if (cellMax == -1) findMax (); - int cell0 = cellMax; - int x0 = cell0 % nt; - int y0 = cell0 / nt; - int nrt = nr * nt; - bool rt = true, tl = true, lb = true, br = true; - int tour = 1; - int cell; - - mask[cellMax] = true; - while (br || rt || tl || lb) - { - // bottom cell first - if (br) - { - br = false; - cell = cell0 - nt * tour; - if (cell < 0) - { - // first cell on the diagonal inside the accumulator - cell += (nt + 1) * (1 + (-cell) / nt); - if (cell >= nt) cell = cell0; - } - else - { - // process bottom cell HERE - if (mask[cell+nt] && acc[cell] > (acc[cellMax] * minsel) / 100) - { - mask[cell] = true; - br = true; - } - cell += nt + 1; - if (cell % nt == 0) cell = cell0; - } - while (cell < cell0) - { - // process cell HERE - if ((mask[cell+nt] || mask[cell-1]) - && acc[cell] > (acc[cellMax] * minsel) / 100) - { - mask[cell] = true; - br = true; - } - cell += nt + 1; - if (cell % nt == 0) cell = cell0; - } - } - - // right cell next - if (rt) - { - rt = false; - cell = cell0 + tour; - if (cell % nt <= x0) - { - // first cell on the diagonal inside the accumulator - cell += (nt - 1) * (x0 + tour + 1 - nt); - if (cell >= nrt) cell = cell0; - } - else - { - // process left cell HERE - if (mask[cell-1] && acc[cell] > (acc[cellMax] * minsel) / 100) - { - mask[cell] = true; - rt = true; - } - cell += nt - 1; - if (cell >= nrt) cell = cell0; - } - while (cell % nt > x0) - { - // process cell HERE - if ((mask[cell-1] || mask[cell-nt]) - && acc[cell] > (acc[cellMax] * minsel) / 100) - { - mask[cell] = true; - rt = true; - } - cell += nt - 1; - if (cell >= nrt) cell = cell0; - } - } - - // top cell next - if (tl) - { - tl = false; - cell = cell0 + nt * tour; - if (cell >= nrt) - { - // first cell on the diagonal inside the accumulator - cell -= (nt + 1) * (y0 + tour + 1 - nr); - if (cell % nt >= x0) cell = cell0; - } - else - { - // process top cell HERE - if (mask[cell-nt] && acc[cell] > (acc[cellMax] * minsel) / 100) - { - mask[cell] = true; - tl = true; - } - cell -= nt + 1; - if (cell % nt >= x0) cell = cell0; - } - while (cell / nt > y0) - { - // process cell HERE - if ((mask[cell-nt] || mask[cell+1]) - && acc[cell] > (acc[cellMax] * minsel) / 100) - { - mask[cell] = true; - tl = true; - } - cell -= nt + 1; - if (cell % nt >= x0) cell = cell0; - } - } - - // left cell next - if (lb) - { - lb = false; - cell = cell0 - tour; - if (tour > x0) - { - // first cell on the diagonal inside the accumulator - cell -= (nt - 1) * (tour - x0); - if (cell < 0) cell = cell0; - } - else - { - // process left cell HERE - if (mask[cell+1] && acc[cell] > (acc[cellMax] * minsel) / 100) - { - mask[cell] = true; - lb = true; - } - cell -= nt - 1; - if (cell < 0) cell = cell0; - } - while (cell % nt < x0) - { - // process cell HERE - if ((mask[cell+1] || mask[cell+nt]) - && acc[cell] > (acc[cellMax] * minsel) / 100) - { - mask[cell] = true; - lb = true; - } - cell -= nt - 1; - if (cell < 0) cell = cell0; - } - } - tour ++; - } -} diff --git a/Code/Seg/BlurredSegment/linespacefilter.h b/Code/Seg/BlurredSegment/linespacefilter.h deleted file mode 100755 index da14661..0000000 --- a/Code/Seg/BlurredSegment/linespacefilter.h +++ /dev/null @@ -1,295 +0,0 @@ -#ifndef LINE_SPACE_FILTER_H -#define LINE_SPACE_FILTER_H - -#include <vector> -#include "pt2i.h" -#include "blurredsegment.h" - -using namespace std; - - -/** - * @class Parameter space filter for detecting thick straight lines. - * \author {P. Even} - */ -class LineSpaceFilter -{ - -public: - - /** Default number of line space filter angle cells. */ - static const int DEFAULT_NB_ANG_CELLS; - /** Default number of line space filter distance cells. */ - static const int DEFAULT_NB_DIST_CELLS; - - - /** - * \brief Creates a empty line space. - */ - LineSpaceFilter (); - - /** - * \brief Deletes the line space. - */ - ~LineSpaceFilter (); - - /** - * \brief Clears the stored information. - */ - void clear (); - - /** \brief Filters and returns a blurred segment. - * @param bs The blurred segment to be processed. - */ - BlurredSegment *filter (BlurredSegment *bs); - - /** - * \brief Gets the filtering cells. - */ - inline bool *getMask () const - { - return mask; - } - - /** - * \brief Gets the accumulator values. - * @param map Accumulator vote cells - * @param solution Accumulator max cell coordinates - */ - void getAccumulator (unsigned char *map, int *solution); - - /** \brief Returns the number of columns of the accumulation filter. - */ - inline int width () const { return nt; } - - /** \brief Returns the number of lines of the accumulation filter. - */ - inline int height () const { return nr; } - - /** \brief Resizes the accumulation array. - * Returns true if the required modification is actually performed. - * @param larger Sets larger if true, smaller otherwise. - */ - bool resize (bool larger); - - /** - * \brief Returns the angular resolution in radians. - */ - inline double angularResolution () const - { - return da; - } - - /** \brief Returns the distance resolution in pixels. - */ - inline double distanceResolution () const - { - return dr; - } - - /** \brief Returns the distance zoom factor of the accumulator display. - */ - inline int getZoom () const - { - return (dzoom); - } - - /** \brief Zooms in or out the accumulator display. - * Returns true if the required modification is actually performed. - * @param in Zooms in if true, out otherwise. - */ - bool zoom (bool in); - - /** \brief Returns the sub-pixel resolution used for voting. - */ - inline int getSubpix () const - { - return (nbSubpix); - } - - /** \brief Modifies the subpixellic resolution for voting. - * Returns true if the required modification is actually performed. - * @param larger Sets larger if true, smaller otherwise. - */ - bool subpixellise (bool larger); - - /** \brief Returns the selection threshold (in percent). - */ - inline int getSelectionThreshold () const - { - return (minsel); - } - - /** \brief Modifies the filter selection threshold. - * Returns true if the required modification is actually performed. - * @param larger Sets larger if true, smaller otherwise. - */ - bool setSelectivity (bool larger); - - /** - * \brief Returns the accepted points by the line space filter. - */ - vector<Pt2i> getAccepted (); - - /** - * \brief Returns the rejected points by the line space filter. - */ - inline vector<Pt2i> getRejected () const { return out; } - - /** - * \brief Returns the blurred segment size before filtering. - */ - inline int blurredSegmentInitialSize () const { return bsInitialSize; } - - /** - * \brief Returns the blurred segment size after filtering. - */ - inline int blurredSegmentFinalSize () const { return bsFinalSize; } - - /** - * \brief Scans manhattan circles around the highest vote. - * Votes for one specific radius to test the scan correctness. - */ - void checkManhattanScan (); - - -private : - - /** Min number of line space filter angle cells. */ - static const int MIN_NB_ANG_CELLS; - /** Max number of line space filter angle cells. */ - static const int MAX_NB_ANG_CELLS; - /** Min number of line space filter distance cells. */ - static const int MIN_NB_DIST_CELLS; - /** Max number of line space filter distance cells. */ - static const int MAX_NB_DIST_CELLS; - /** Default filter selection threshold (in percentage). */ - static const int DEFAULT_SELECTION_THRESHOLD; - /** Minimal filter selection threshold (in percentage). */ - static const int MIN_SELECTION_THRESHOLD; - /** Maximal filter selection threshold (in percentage). */ - static const int MAX_SELECTION_THRESHOLD; - /** Increment value for the selection threshold setting. */ - static const int INC_SELECTION_THRESHOLD; - /** Default sub-pixellic resolution for voting. */ - static const int NO_SUBPIXEL; - /** Maximal sub-pixellic resolution for voting. */ - static const int MAX_SUBPIXEL; - /** Angle zoom factor default value. */ - static const int ANG_DEF_ZOOM; - /** Angle zoom factor min value. */ - static const int ANG_MIN_ZOOM; - /** Angle zoom factor max value. */ - static const int ANG_MAX_ZOOM; - /** Distance zoom factor default value. */ - static const int DIST_DEF_ZOOM; - /** Distance zoom factor min value. */ - static const int DIST_MIN_ZOOM; - /** Distance zoom factor max value. */ - static const int DIST_MAX_ZOOM; - /** Segment minimal size to accept voting. */ - static const int INPUT_MIN_SIZE; - - /** Accumulator. */ - int *acc; - /** Angle zoom factor. */ - int azoom; - /** Distance zoom factor. */ - int dzoom; - /** Subpixel resolution for voting. */ - int nbSubpix; - - /** Count of accumulator rows (angles). */ - int nt; - /** Pre-computed array of deviated normal vectors. */ - double *ncos, *nsin; - /** Angular resolution (in readians). */ - double da; - - /** Count of accumulator columns (distances). */ - int nr; - /** Distance resolution (offset between consecutive accumulator columns). */ - double dr; - /** Origin of the line space. */ - int cx, cy; - /** Distance value of the accumulator bottom line. */ - double r0; - - /** Dominant cell (-1 if not yet determined) */ - int cellMax; - /** Extraction mask used to prune outlier candidates. */ - bool *mask; - /** Filter selection ratio (in %) */ - int minsel; - - /** Blurred segment size before filtering. */ - int bsInitialSize; - /** Blurred segment size after filtering. */ - int bsFinalSize; - /** Accepted left points after line space filtering. */ - vector<Pt2i> leftIn; - /** Accepted right points after line space filtering. */ - vector<Pt2i> rightIn; - /** Rejected points after line space filtering. */ - vector<Pt2i> out; - - - /** - * \brief Clears the accumulator and centers it on a new blurred segment. - * @param x0 Segment center abscissae - * @param y0 Segment center ordinate - * @param a Segment normal vector abscissae - * @param b Segment normal vector ordinate - * @param length Segment length - * @param width Segment width - */ - void init (double x0, double y0, int a, int b, - double length, double width); - - /** - * \brief Direct vote into the accumulator for testing - */ - void vote (int i, int j); - - /** - * \brief Adds one point votes into the accumulator - * @param pix Voting point - */ - void vote (Pt2i pix); - - /** - * \brief Adds multiple points votes into the accumulator - * @param points Voting points - */ - void vote (const vector<Pt2i>& points); - - /** - * \brief Checks whether the point votes in the active part of the accumulator - * @param pix Voting point - */ - bool voteInMask (Pt2i pix); - - /** - * \brief Tests multiple points votes into the active part of the accumulator - * @param points Voting points - * Returns a vector of inlier points - */ - vector<Pt2i> voteInMask (vector<Pt2i>& points); - - /** - * \brief Determines the cell with the highest vote. - */ - void findMax (); - - /** - * \brief Determines the rho=0 cell with the highest vote. - */ - void findMaxThroughOrigin (); - - /** - * \brief Fits the extraction mask around the interest area. - */ - void fitMask (); - -}; -#endif diff --git a/Code/Seg/Seg.pro b/Code/Seg/Seg.pro index 028b9e8..1a3b565 100644 --- a/Code/Seg/Seg.pro +++ b/Code/Seg/Seg.pro @@ -18,10 +18,8 @@ HEADERS += BlurredSegment/biptlist.h \ BlurredSegment/blurredsegment.h \ BlurredSegment/blurredsegmentproto.h \ BlurredSegment/bsdetector.h \ + BlurredSegment/bsfilter.h \ BlurredSegment/bstracker.h \ - BlurredSegment/linespacefilter.h \ - BSTools/bsaccumulatoritem.h \ - BSTools/bsaccumulatorview.h \ BSTools/bsdetectionwidget.h \ BSTools/bsidetitem.h \ BSTools/bsidetview.h \ @@ -59,10 +57,8 @@ SOURCES += main.cpp \ BlurredSegment/blurredsegment.cpp \ BlurredSegment/blurredsegmentproto.cpp \ BlurredSegment/bsdetector.cpp \ + BlurredSegment/bsfilter.cpp \ BlurredSegment/bstracker.cpp \ - BlurredSegment/linespacefilter.cpp \ - BSTools/bsaccumulatoritem.cpp \ - BSTools/bsaccumulatorview.cpp \ BSTools/bsdetectionwidget.cpp \ BSTools/bsidetitem.cpp \ BSTools/bsidetview.cpp \ diff --git a/Code/Seg/main.cpp b/Code/Seg/main.cpp index d484716..befb15a 100755 --- a/Code/Seg/main.cpp +++ b/Code/Seg/main.cpp @@ -27,7 +27,7 @@ int main (int argc, char *argv[]) if (string(argv[i]).at(0) == '-') { if (string(argv[i]) == string ("-profile")) window.toggleProfWindow (); - else if (string(argv[i]) == string ("-accu")) window.toggleAccuWindow (); + // else if (string(argv[i]) == string ("-acc"))window.toggleAccuWindow (); else if (string(argv[i]) == string ("-seg")) window.toggleSegWindow (); else if (string(argv[i]) == string ("-idet")) window.toggleIdetWindow (); // Test command : time ./Seg -test ../Images/couloir.jpg @@ -56,7 +56,7 @@ int main (int argc, char *argv[]) { char carac = string(argv[i]).at(j); if (carac == 'p') window.toggleProfWindow (); - else if (carac == 'a') window.toggleAccuWindow (); + // else if (carac == 'a') window.toggleAccuWindow (); else if (carac == 's') window.toggleSegWindow (); else if (carac == 'i') window.toggleIdetWindow (); } -- GitLab