diff --git a/Code/FBSD/BSTools/bscannyitem.cpp b/Code/FBSD/BSTools/bscannyitem.cpp deleted file mode 100755 index 6715820155ac28b2b7cdfe9ed02c179d2cfba201..0000000000000000000000000000000000000000 --- a/Code/FBSD/BSTools/bscannyitem.cpp +++ /dev/null @@ -1,179 +0,0 @@ -#include <QtGui> -#include <iostream> -#include <fstream> -#include "bscannyitem.h" -#include "pt2i.h" - -using namespace std; - - -const int BSCannyItem::ALONE = 0; -const int BSCannyItem::WITH_BS = 1; -const int BSCannyItem::WITH_DSS = 2; -const QColor BSCannyItem::BS_COLOR = Qt::blue; -const QColor BSCannyItem::CANNY_COLOR = Qt::green; -const QColor BSCannyItem::BOTH_COLOR = Qt::red; -const int BSCannyItem::DEFAULT_PEN_WIDTH = 1; - - -BSCannyItem::BSCannyItem (int width, int height, const QImage *im, - BSDetector *detector) -{ - w = width; - h = height; - int size = w * h; - this->im = im; - bsmap = new bool[size]; - clmap = new bool[size]; - det = detector; - type = ALONE; - int nb = readCannyLines (); - cout << nb << " cannys" << endl; -} - - -BSCannyItem::~BSCannyItem () -{ - delete [] bsmap; -} - - -QRectF BSCannyItem::boundingRect () const -{ - return QRectF (0, 0, w - 1, h - 1); // ZZZ -} - - -void BSCannyItem::paint (QPainter *painter, - const QStyleOptionGraphicsItem *option, - QWidget *widget) -{ - Q_UNUSED (option); - Q_UNUSED (widget); - - if (type == WITH_BS) drawBS (painter); - else if (type == WITH_DSS) drawDSS (painter); - drawCannyLines (painter); - int nboth = 0, ncl = 0, nbs = 0; - for (int i = 0; i < w * h; i++) - if (clmap[i]) - if (bsmap[i]) nboth++; - else ncl++; - else if (bsmap[i]) nbs++; - cout << nboth << " both, " << ncl << " canny, " << nbs << " bs" << endl; -} - - -int BSCannyItem::readCannyLines () -{ - double val[5]; - int i = 0, nb = 0; - ifstream input ("/home/even/cannyLinesModif/cannylines.txt", ios::in); - bool reading = true; - if (input) - { - while (reading) - { - input >> val[i]; - if (input.eof ()) reading = false; - if (++i == 5) - { - CannyLine cl; - cl.xs = (int) (val[0] + 0.5); - cl.ys = h - 1 - (int) (val[1] + 0.5); - cl.xe = (int) (val[2] + 0.5); - cl.ye = h - 1 - (int) (val[3] + 0.5); - cl.id = (int) (val[4] + 0.5); - cannys.push_back (cl); - i = 0; - nb++; - } - } - } - -return (nb); -} - - -void BSCannyItem::drawBS (QPainter *painter) -{ - painter->setPen (QPen (BS_COLOR, DEFAULT_PEN_WIDTH, Qt::SolidLine, - Qt::RoundCap, Qt::RoundJoin)); - for (int i = 0; i < w * h; i++) bsmap[i] = false; - vector<BlurredSegment *> bss = det->getBlurredSegments (); - if (! bss.empty ()) - { - vector<BlurredSegment *>::const_iterator it = bss.begin (); - while (it != bss.end ()) - { - if (*it != NULL) drawPoints (painter, (*it)->getAllPoints ()); - it++; - } - } -} - - -void BSCannyItem::drawDSS (QPainter *painter) -{ - painter->setPen (QPen (BS_COLOR, DEFAULT_PEN_WIDTH, Qt::SolidLine, - Qt::RoundCap, Qt::RoundJoin)); - for (int i = 0; i < w * h; i++) bsmap[i] = false; - vector<BlurredSegment *> bss = det->getBlurredSegments (); - if (! bss.empty ()) - { - vector<BlurredSegment *>::const_iterator it = bss.begin (); - while (it != bss.end ()) - { - if ((*it) != NULL) - { - DigitalStraightSegment *dss = (*it)->getSegment (); - if (dss != NULL) - { - vector<Pt2i> pts; - dss->getPoints (pts); - drawPoints (painter, pts); - } - } - it++; - } - } -} - - -void BSCannyItem::drawPoints (QPainter *painter, vector<Pt2i> pts) -{ - vector<Pt2i>::iterator iter = pts.begin (); - while (iter != pts.end ()) - { - Pt2i p = *iter++; - if (p.x() < w && p.y() < h && p.x() >= 0 && p.y() >= 0) - { - bsmap[p.y()*w+p.x()] = true; - painter->drawPoint (QPoint (p.x(), h - 1 - p.y())); // dec 1 - } - } -} - - -void BSCannyItem::drawCannyLines (QPainter *painter) -{ - int n = 0; - Pt2i *pts = NULL; - vector<CannyLine>::iterator it = cannys.begin (); - while (it != cannys.end ()) - { - pts = Pt2i (it->xs, it->ys).drawing (Pt2i (it->xe, it->ye), &n); - for (int i = 0; i < n; i++) - { - painter->setPen (QPen (bsmap[pts[i].y()*w+pts[i].x()] ? - BOTH_COLOR : CANNY_COLOR, - DEFAULT_PEN_WIDTH, Qt::SolidLine, - Qt::RoundCap, Qt::RoundJoin)); - painter->drawPoint (QPoint (pts[i].x (), - h - 1 - pts[i].y ())); // dec 1 - clmap[pts[i].y()*w+pts[i].x()] = true; - } - delete [] pts; - it++; - } -} diff --git a/Code/FBSD/BSTools/bscannyitem.h b/Code/FBSD/BSTools/bscannyitem.h deleted file mode 100755 index 39443caa7b30cc97266444b37056a2b3d3db5363..0000000000000000000000000000000000000000 --- a/Code/FBSD/BSTools/bscannyitem.h +++ /dev/null @@ -1,113 +0,0 @@ -#ifndef BS_CANNY_ITEM_H -#define BS_CANNY_ITEM_H - -#include <QGraphicsItem> -#include "bsdetector.h" - -using namespace std; - - -/** - * @class BSCannyItem bscannyitem.h - * \brief Blurred segment comparator with CannyLine. - * \author {P. Even} - */ -class BSCannyItem : public QGraphicsItem -{ -public: - - /** - * \brief Creates a CannyLine comparator. - */ - BSCannyItem (int width, int height, const QImage *im, BSDetector *detector); - - /** - * \brief Deletes the CannyLine comparator. - */ - ~BSCannyItem (); - - /** - * \brief Returns the grid area. - */ - QRectF boundingRect () const; - - /** - * \brief Redraws the CannyLine comparator grid. - */ - void paint (QPainter *painter, - const QStyleOptionGraphicsItem *option, QWidget *widget); - - /** - * \brief Toggles display modality. - */ - inline void toggleType () { if (++type == 3) type = 0; } - - - -private: - - /** Canny lines alone display modality. */ - static const int ALONE; - /** With BS display modality. */ - static const int WITH_BS; - /** With DSS display modality. */ - static const int WITH_DSS; - /** Default color for blurred segments. */ - static const QColor BS_COLOR; - /** Default color for Canny lines. */ - static const QColor CANNY_COLOR; - /** Default color for both tools. */ - static const QColor BOTH_COLOR; - /** Default value for pen width. */ - static const int DEFAULT_PEN_WIDTH; - - /** Aggregation of segment extraction results with initial conditions. */ - struct CannyLine - { - /** Canny line start point X coordinate. */ - int xs; - /** Canny line start point Y coordinate. */ - int ys; - /** Canny line end point X coordinate. */ - int xe; - /** Canny line end point Y coordinate. */ - int ye; - /** Canny line identifier. */ - int id; - }; - /** List of Canny lines. */ - vector<CannyLine> cannys; - - /** Background image. */ - const QImage *im; - /** Grid width. */ - int w; - /** Grid height. */ - int h; - /** Segment detector. */ - BSDetector *det; - /** Blurred segments map */ - bool *bsmap; - /** Canny lines map */ - bool *clmap; - /** Display modality */ - int type; - - /** Reads Canny lines file */ - int readCannyLines (); - - /** Displays blurred segments points */ - void drawBS (QPainter *painter); - - /** Displays blurred segments DSS */ - void drawDSS (QPainter *painter); - - /** Displays a set of points */ - void drawPoints (QPainter *painter, vector<Pt2i> pts); - - /** Displays Canny lines */ - void drawCannyLines (QPainter *painter); - -}; - -#endif diff --git a/Code/FBSD/BSTools/bscannyview.cpp b/Code/FBSD/BSTools/bscannyview.cpp deleted file mode 100755 index f12bc68a1f5a61bb2a426d0ec0eafe1f6a67106e..0000000000000000000000000000000000000000 --- a/Code/FBSD/BSTools/bscannyview.cpp +++ /dev/null @@ -1,51 +0,0 @@ -#include <QtGui> -#include <iostream> -#include "bscannyview.h" -#include "math.h" - -using namespace std; - - -BSCannyView::BSCannyView (QImage *im, BSDetector *sd) -{ - int w = im->width (); - int h = im->height (); - image = im; - setScene (new QGraphicsScene (0, 0, w, h)); - canny = new BSCannyItem (w, h, image, sd); - //setBackgroundBrush (QBrush (*image)); - scene()->addItem (canny); - setWindowTitle ("CannyLine comparator"); -} - - -BSCannyView::~BSCannyView () -{ - scene()->removeItem (canny); - delete canny; -} - - -void BSCannyView::paint (QPainter *painter, - const QStyleOptionGraphicsItem *option, - QWidget *widget) -{ - Q_UNUSED (painter); - Q_UNUSED (option); - Q_UNUSED (widget); -} - - -bool BSCannyView::processKeyEvent (QKeyEvent *event) -{ - bool processed = false; - switch (event->key ()) - { - case Qt::Key_I : // Info - canny->toggleType (); - scene()->update (); - update (); - break; - } - return processed; -} diff --git a/Code/FBSD/BSTools/bscannyview.h b/Code/FBSD/BSTools/bscannyview.h deleted file mode 100755 index 16ce9caf2c9db48541a00f81b716e83d8b763292..0000000000000000000000000000000000000000 --- a/Code/FBSD/BSTools/bscannyview.h +++ /dev/null @@ -1,52 +0,0 @@ -#ifndef BS_CANNY_VIEW_H -#define BS_CANNY_VIEW_H - -#include <QGraphicsView> -#include <QImage> -#include "bscannyitem.h" - - -/** - * @class BSCannyView bscannyview.h - * \brief A Qt window to compare detected segments with CannyLines. - * \author {P. Even} - */ -class BSCannyView : public QGraphicsView -{ - -public: - - /** - * \brief Creates a CannyLine comparator view. - */ - BSCannyView (QImage *im, BSDetector *sd); - - /** - * \brief Deletes the CannyLine comparator view. - */ - ~BSCannyView (); - - /** - * \brief Redraws the CannyLine comparator view. - */ - void paint (QPainter *painter, - const QStyleOptionGraphicsItem *option, QWidget *widget); - - /** - * \brief Processes key pressed events. - */ - bool processKeyEvent (QKeyEvent *event); - - -protected: - -private: - - /** Pointer to the blurred segment structure graphics item. */ - BSCannyItem *canny; - /** Pointer to the displayed image. */ - QImage *image; - -}; - -#endif diff --git a/Code/FBSD/BSTools/bsdetectionwidget.cpp b/Code/FBSD/BSTools/bsdetectionwidget.cpp index 0fb3b6aec97c30d30b656a79890a5d6e609dcb3d..e50ef5c8d7ffab44428f61848ecc379d309c6147 100755 --- a/Code/FBSD/BSTools/bsdetectionwidget.cpp +++ b/Code/FBSD/BSTools/bsdetectionwidget.cpp @@ -38,8 +38,7 @@ BSDetectionWidget::BSDetectionWidget (QWidget *parent) strucview = NULL; // DEV profileview = NULL; // DEV idetview = NULL; // DEV - cannyview = NULL; // DEV - yorkview = NULL; // DEV + gtview = NULL; // DEV // Sets initial user outputs parameters verbose = false; @@ -74,8 +73,7 @@ BSDetectionWidget::~BSDetectionWidget () if (strucview != NULL) delete strucview; // DEV if (profileview != NULL) delete profileview; // DEV if (idetview != NULL) delete idetview; // DEV - if (cannyview != NULL) delete cannyview; // DEV - if (yorkview != NULL) delete yorkview; // DEV + if (gtview != NULL) delete gtview; // DEV } @@ -479,16 +477,18 @@ void BSDetectionWidget::keyPressEvent (QKeyEvent *event) clearSavedSegments (); break; +// DEV IN case Qt::Key_D : if (event->modifiers () & Qt::ControlModifier) { // Switches density test at initial step - detector.switchDensityTest (); - cout << "Density test : " - << (detector.isDensityTestOn () ? "on" : "off") << endl; + detector.switchInitialSparsityTest (); + cout << "Initial density test : " + << (detector.isInitialSparsityTestOn () ? "on" : "off") << endl; extract (); } break; +// DEV OUT case Qt::Key_E : // Handles directed edge or stroke detection @@ -523,22 +523,11 @@ void BSDetectionWidget::keyPressEvent (QKeyEvent *event) break; case Qt::Key_G : - if (event->modifiers () & Qt::ControlModifier) - { - // Switches length test at final step - detector.switchFinalLengthTest (); - cout << "Final length test : " - << (detector.isFinalLengthTestOn () ? "on" : "off") << endl; - extract (); - } - else - { - // Tunes the gradient threshold for maximal value detection - detector.incSensitivity ( - (event->modifiers () & Qt::ShiftModifier ? -1 : 1)); - cout << "Sensitivity = " << detector.getSensitivity () << endl; - extract (); - } + // Tunes the gradient threshold for maximal value detection + detector.incSensitivity ( + (event->modifiers () & Qt::ShiftModifier ? -1 : 1)); + cout << "Sensitivity = " << detector.getSensitivity () << endl; + extract (); break; case Qt::Key_H : @@ -577,20 +566,20 @@ void BSDetectionWidget::keyPressEvent (QKeyEvent *event) case Qt::Key_K : if (event->modifiers () & Qt::ControlModifier) { - // Switches the final step connectivity constraint - detector.switchConnectivityConstraint (); - cout << "Fragmentation test " - << (detector.isConnectivityConstraintOn () ? "on" : "off") + // Switches the final fragmentation test + detector.switchFinalFragmentationTest (); + cout << "Final fragmentation test " + << (detector.isFinalFragmentationTestOn () ? "on" : "off") << endl; extract (); } else { - // Tunes the minimal size of connected components - detector.incConnectedComponentMinSize ( + // Tunes the minimal size of segment fragments + detector.incFragmentSizeMinValue ( (event->modifiers () & Qt::ShiftModifier) == 0); cout << "Fragments minimal size = " - << detector.getConnectedComponentMinSize () << endl; + << detector.fragmentSizeMinValue () << endl; extract (); } break; @@ -598,19 +587,19 @@ void BSDetectionWidget::keyPressEvent (QKeyEvent *event) case Qt::Key_L : if (event->modifiers () & Qt::ControlModifier) { - // Switches density test at final step - detector.switchFinalDensityTest (); - cout << "Final density test : " - << (detector.isFinalDensityTestOn () ? "on" : "off") << endl; + // Switches sparsity test at final step + detector.switchFinalSparsityTest (); + cout << "Final sparsity test : " + << (detector.isFinalSparsityTestOn () ? "on" : "off") << endl; extract (); } else { - // Tunes the output blurred segment minimal size - detector.setBSminSize (detector.getBSminSize () + + // Tunes the initial segment minimal size + detector.setInitialMinSize (detector.initialSizeMinValue () + (event->modifiers () & Qt::ShiftModifier ? -1 : 1)); - cout << "Detected blurred segments min size = " - << detector.getBSminSize () << endl; + cout << "Initial segment min size = " + << detector.initialSizeMinValue () << endl; extract (); } break; @@ -737,8 +726,8 @@ void BSDetectionWidget::keyPressEvent (QKeyEvent *event) } else { - // Tunes the detector assigned thickness - detector.setAssignedThickness (detector.finalSizeMinValue () + + // Tunes the final size threshold + detector.setFinalSizeMinValue (detector.finalSizeMinValue () + (event->modifiers () & Qt::ShiftModifier ? -1 : 1)); cout << "Minimal size of detected blurred segments = " << detector.finalSizeMinValue () << " points" << endl; @@ -799,24 +788,15 @@ void BSDetectionWidget::keyPressEvent (QKeyEvent *event) "detected segment" : "initial scan") << endl; extract (); } - else - { - // Tunes the assigned max width margin for fine tracks - detector.setFastTracksMaxMargin (detector.fastTracksMaxMargin () + - (event->modifiers () & Qt::ShiftModifier ? -1 : 1)); - cout << "Fast tracks max width margin = " - << detector.fastTracksMaxMargin () << endl; - extract (); - } break; case Qt::Key_X : if (event->modifiers () & Qt::ControlModifier) { - // Switches the setting of the assigned width on the detected segment - detector.switchScanFitting (); - cout << "Fine tracking fitted to " << (detector.isScanFitting () ? - "detected segment width" : "assigned width") << endl; + detector.setStaticDetector (! (detector.staticDetectorOn ())); + cout << (detector.staticDetectorOn () ? + "Static (without ADS and ATC) detector set" : + "Static (without ADS and ATC) detector released") << endl; extract (); } else @@ -824,7 +804,7 @@ void BSDetectionWidget::keyPressEvent (QKeyEvent *event) // Tunes the assigned thickness to detector detector.setAssignedThickness (detector.assignedThickness () + (event->modifiers () & Qt::ShiftModifier ? -1 : 1)); - cout << "Assigned width = " + cout << "Assigned thickness = " << detector.assignedThickness () << endl; extract (); } @@ -895,16 +875,10 @@ void BSDetectionWidget::keyPressEvent (QKeyEvent *event) break; // DEV IN - case Qt::Key_Percent : - if (cannyview == NULL) - cannyview = new BSCannyView (&loadedImage, &detector); - cannyview->show (); - break; - case Qt::Key_Semicolon : - if (yorkview == NULL) - yorkview = new BSYorkView (&loadedImage, &detector); - yorkview->show (); + if (gtview == NULL) + gtview = new BSGroundtruthView (&loadedImage, &detector); + gtview->show (); break; // DEV OUT @@ -992,13 +966,6 @@ void BSDetectionWidget::keyPressEvent (QKeyEvent *event) << (detector.trackCrosswiseOn () ? "on" : "off") << endl; break; - case Qt::Key_6 : - detector.setStaticDetector (! (detector.staticDetectorOn ())); - cout << (detector.staticDetectorOn () ? - "Static detector set" : "Static detector released") << endl; - extract (); - break; - case Qt::Key_7 : storeUserInput (); break; @@ -1034,13 +1001,9 @@ void BSDetectionWidget::keyPressEvent (QKeyEvent *event) { if (idetview->processKeyEvent (event)) extract (); } - else if (yorkview != NULL && yorkview->isActiveWindow ()) - { - if (yorkview->processKeyEvent (event)) extract (); - } - else if (cannyview != NULL && cannyview->isActiveWindow ()) + else if (gtview != NULL && gtview->isActiveWindow ()) { - if (cannyview->processKeyEvent (event)) extract (); + if (gtview->processKeyEvent (event)) extract (); } // DEV OUT } @@ -1460,12 +1423,15 @@ void BSDetectionWidget::writeDetectionStatus () else if (res == BSDetector::RESULT_FINAL_NO_DETECTION) cout << "Extraction : no final detection (bsini == NULL)." << endl; else if (res == BSDetector::RESULT_FINAL_TOO_FEW) - cout << "Extraction : two few points at final detection." << endl; + cout << "Extraction : unsuccessful size test at final detection." << endl; else if (res == BSDetector::RESULT_FINAL_TOO_SPARSE) - cout << "Extraction : unsuccessful density test at final detection." + cout << "Extraction : unsuccessful sparsity test at final detection." << endl; else if (res == BSDetector::RESULT_FINAL_TOO_SMALL) - cout << "Extraction : unsuccessful spread test at final detection." + cout << "Extraction : unsuccessful size test at final detection." + << endl; + else if (res == BSDetector::RESULT_FINAL_TOO_FRAGMENTED) + cout << "Extraction : unsuccessful fragmentation test at final detection." << endl; else if (res == BSDetector::RESULT_FINAL_TOO_MANY_OUTLIERS) cout << "Extraction : unsuccessful filter test at final detection." @@ -1624,38 +1590,13 @@ void BSDetectionWidget::performanceTest () { if (p1.equals (p2)) { -// DEV IN -/* - if (cannyview) - { - // Canny compare -> automatic - cout << "Automatic extraction test" << endl; - clock_t start = clock (); - for (int i = 0; i < 100; i++) - { - if (gMap != NULL) delete gMap; - gMap = new VMap (width, height, getBitmap (augmentedImage), - VMap::TYPE_SOBEL_5X5); - detector.setGradientMap (gMap); - buildGradientImage (0); - detector.detectAll (); - } - double diff = (clock () - start) / (double) CLOCKS_PER_SEC; - cout << "Test run : " << diff << endl; - extract (); - } - else - { -*/ -// DEV OUT - // No stroke -> automatic - cout << "Automatic extraction test" << endl; - clock_t start = clock (); - for (int i = 0; i < 100; i++) detector.detectAll (); - double diff = (clock () - start) / (double) CLOCKS_PER_SEC; - cout << "Test run : " << diff << endl; - extract (); -// } // DEV + // No stroke -> automatic + cout << "Automatic extraction test" << endl; + clock_t start = clock (); + for (int i = 0; i < 100; i++) detector.detectAll (); + double diff = (clock () - start) / (double) CLOCKS_PER_SEC; + cout << "Test run : " << diff << endl; + extract (); } else { diff --git a/Code/FBSD/BSTools/bsdetectionwidget.h b/Code/FBSD/BSTools/bsdetectionwidget.h index 94572bd7ab89cd1ca8b33f12cc859dbcb206b9f9..ae3daa4a545feab9eea566aaa653a2b5454c13fe 100755 --- a/Code/FBSD/BSTools/bsdetectionwidget.h +++ b/Code/FBSD/BSTools/bsdetectionwidget.h @@ -8,12 +8,11 @@ #include <QVector> #include <fstream> #include "bsdetector.h" -// #include "bsaccumulatorview.h" // DEV -#include "bsstructureview.h" // DEV -#include "bsprofileview.h" // DEV -#include "bsidetview.h" // DEV -#include "bscannyview.h" // DEV -#include "bsyorkview.h" // DEV +// #include "bsaccumulatorview.h" // DEV +#include "bsstructureview.h" // DEV +#include "bsprofileview.h" // DEV +#include "bsidetview.h" // DEV +#include "bsgroundtruthview.h" // DEV using namespace std; @@ -308,10 +307,8 @@ private: // BSAccumulatorView *accuview; // DEV /** Blurred segment contents view. */ // DEV BSStructureView *strucview; // DEV - /** CannyLine comparator view. */ // DEV - BSCannyView *cannyview; // DEV - /** YorkLine comparator view. */ // DEV - BSYorkView *yorkview; // DEV + /** Groundtruth comparator view. */ // DEV + BSGroundtruthView *gtview; // DEV /** Aggregation of segment extraction results with initial conditions. */ struct ExtractedSegment diff --git a/Code/FBSD/BSTools/bsyorkitem.cpp b/Code/FBSD/BSTools/bsgroundtruthitem.cpp similarity index 83% rename from Code/FBSD/BSTools/bsyorkitem.cpp rename to Code/FBSD/BSTools/bsgroundtruthitem.cpp index e95a64aa238ec51a4171b49ff5f4148a679da74c..77f8faf45e078da2f6280998199bb09d29a6ae78 100755 --- a/Code/FBSD/BSTools/bsyorkitem.cpp +++ b/Code/FBSD/BSTools/bsgroundtruthitem.cpp @@ -1,38 +1,38 @@ #include <QtGui> #include <iostream> #include <fstream> -#include "bsyorkitem.h" +#include "bsgroundtruthitem.h" #include "pt2i.h" using namespace std; -const int BSYorkItem::GT_ALONE = 0; -const int BSYorkItem::LSD_ALONE = 1; -const int BSYorkItem::DILATED_LSD_ALONE = 2; -const int BSYorkItem::GT_OVER_LSD = 3; -const int BSYorkItem::ED_ALONE = 4; -const int BSYorkItem::DILATED_ED_ALONE = 5; -const int BSYorkItem::GT_OVER_ED = 6; -const int BSYorkItem::CANNY_ALONE = 7; -const int BSYorkItem::DILATED_CANNY_ALONE = 8; -const int BSYorkItem::GT_OVER_CANNY = 9; -const int BSYorkItem::FBSD_LINES = 10; -const int BSYorkItem::FBSD_ALONE = 11; -const int BSYorkItem::GT_OVER_BS = 12; -const int BSYorkItem::GT_OVER_DSS = 13; -const int BSYorkItem::GT_WITH_CANNY = 14; -const int BSYorkItem::GT_WITH_DSS = 15; -const int BSYorkItem::NO_INFO = 16; -const QColor BSYorkItem::ALONE_COLOR = Qt::black; -const QColor BSYorkItem::OVER_COLOR = Qt::lightGray; -const QColor BSYorkItem::UNDER_COLOR = Qt::yellow; -const QColor BSYorkItem::BOTH_COLOR = Qt::black; -const int BSYorkItem::DEFAULT_PEN_WIDTH = 1; - - -BSYorkItem::BSYorkItem (int width, int height, const QImage *im, - BSDetector *detector) +const int BSGroundtruthItem::GT_ALONE = 0; +const int BSGroundtruthItem::LSD_ALONE = 1; +const int BSGroundtruthItem::DILATED_LSD_ALONE = 2; +const int BSGroundtruthItem::GT_OVER_LSD = 3; +const int BSGroundtruthItem::ED_ALONE = 4; +const int BSGroundtruthItem::DILATED_ED_ALONE = 5; +const int BSGroundtruthItem::GT_OVER_ED = 6; +const int BSGroundtruthItem::CANNY_ALONE = 7; +const int BSGroundtruthItem::DILATED_CANNY_ALONE = 8; +const int BSGroundtruthItem::GT_OVER_CANNY = 9; +const int BSGroundtruthItem::FBSD_LINES = 10; +const int BSGroundtruthItem::FBSD_ALONE = 11; +const int BSGroundtruthItem::GT_OVER_BS = 12; +const int BSGroundtruthItem::GT_OVER_DSS = 13; +const int BSGroundtruthItem::GT_WITH_CANNY = 14; +const int BSGroundtruthItem::GT_WITH_DSS = 15; +const int BSGroundtruthItem::NO_INFO = 16; +const QColor BSGroundtruthItem::ALONE_COLOR = Qt::black; +const QColor BSGroundtruthItem::OVER_COLOR = Qt::lightGray; +const QColor BSGroundtruthItem::UNDER_COLOR = Qt::yellow; +const QColor BSGroundtruthItem::BOTH_COLOR = Qt::black; +const int BSGroundtruthItem::DEFAULT_PEN_WIDTH = 1; + + +BSGroundtruthItem::BSGroundtruthItem (int width, int height, + const QImage *im, BSDetector *detector) { w = width; h = height; @@ -51,21 +51,21 @@ BSYorkItem::BSYorkItem (int width, int height, const QImage *im, } -BSYorkItem::~BSYorkItem () +BSGroundtruthItem::~BSGroundtruthItem () { delete [] bsmap; } -QRectF BSYorkItem::boundingRect () const +QRectF BSGroundtruthItem::boundingRect () const { return QRectF (0, 0, w - 1, h - 1); // ZZZ } -void BSYorkItem::paint (QPainter *painter, - const QStyleOptionGraphicsItem *option, - QWidget *widget) +void BSGroundtruthItem::paint (QPainter *painter, + const QStyleOptionGraphicsItem *option, + QWidget *widget) { Q_UNUSED (option); Q_UNUSED (widget); @@ -126,7 +126,7 @@ void BSYorkItem::paint (QPainter *painter, } -void BSYorkItem::drawBS (QPainter *painter, bool alone) +void BSGroundtruthItem::drawBS (QPainter *painter, bool alone) { painter->setPen (QPen (alone ? ALONE_COLOR : UNDER_COLOR, DEFAULT_PEN_WIDTH, Qt::SolidLine, @@ -144,7 +144,7 @@ void BSYorkItem::drawBS (QPainter *painter, bool alone) } -void BSYorkItem::drawDSS (QPainter *painter, bool alone, bool disp) +void BSGroundtruthItem::drawDSS (QPainter *painter, bool alone, bool disp) { painter->setPen (QPen (alone ? ALONE_COLOR : UNDER_COLOR, DEFAULT_PEN_WIDTH, Qt::SolidLine, @@ -171,7 +171,8 @@ void BSYorkItem::drawDSS (QPainter *painter, bool alone, bool disp) } -void BSYorkItem::drawPoints (QPainter *painter, vector<Pt2i> pts, bool disp) +void BSGroundtruthItem::drawPoints (QPainter *painter, + vector<Pt2i> pts, bool disp) { vector<Pt2i>::iterator iter = pts.begin (); while (iter != pts.end ()) @@ -186,7 +187,7 @@ void BSYorkItem::drawPoints (QPainter *painter, vector<Pt2i> pts, bool disp) } -void BSYorkItem::drawGroundTruth (QPainter *painter, bool alone) +void BSGroundtruthItem::drawGroundTruth (QPainter *painter, bool alone) { if (gts->areLinesLoaded ()) { @@ -217,7 +218,7 @@ void BSYorkItem::drawGroundTruth (QPainter *painter, bool alone) } -void BSYorkItem::drawLsdLines (QPainter *painter, bool alone, bool disp) { +void BSGroundtruthItem::drawLsdLines (QPainter *painter, bool alone, bool disp) { int n = 0; Pt2i *pts = NULL; int nb = lsds->countOfLines (); @@ -246,7 +247,7 @@ void BSYorkItem::drawLsdLines (QPainter *painter, bool alone, bool disp) { } -void BSYorkItem::drawDilatedLsdLines (QPainter *painter, bool disp) +void BSGroundtruthItem::drawDilatedLsdLines (QPainter *painter, bool disp) { int nb = lsds->countOfLines (); for (int i = 0; i < nb; i++) @@ -294,7 +295,8 @@ cout << "Dilation of " << dil << endl; } -void BSYorkItem::drawEdLines (QPainter *painter, bool alone, bool disp) { +void BSGroundtruthItem::drawEdLines (QPainter *painter, bool alone, bool disp) +{ int n = 0; Pt2i *pts = NULL; int nb = eds->countOfLines (); @@ -323,7 +325,7 @@ void BSYorkItem::drawEdLines (QPainter *painter, bool alone, bool disp) { } -void BSYorkItem::drawDilatedEdLines (QPainter *painter, bool disp) +void BSGroundtruthItem::drawDilatedEdLines (QPainter *painter, bool disp) { int nb = eds->countOfLines (); for (int i = 0; i < nb; i++) @@ -371,7 +373,8 @@ cout << "Dilation of " << dil << endl; } -void BSYorkItem::drawCannyLines (QPainter *painter, bool alone, bool disp) +void BSGroundtruthItem::drawCannyLines (QPainter *painter, + bool alone, bool disp) { int n = 0; Pt2i *pts = NULL; @@ -401,7 +404,7 @@ void BSYorkItem::drawCannyLines (QPainter *painter, bool alone, bool disp) } -void BSYorkItem::drawDilatedCannyLines (QPainter *painter, bool disp) +void BSGroundtruthItem::drawDilatedCannyLines (QPainter *painter, bool disp) { int nb = cannys->countOfLines (); for (int i = 0; i < nb; i++) @@ -448,7 +451,7 @@ void BSYorkItem::drawDilatedCannyLines (QPainter *painter, bool disp) } -void BSYorkItem::drawFbsdLines (QPainter *painter, bool alone, bool disp) +void BSGroundtruthItem::drawFbsdLines (QPainter *painter, bool alone, bool disp) { int n = 0; Pt2i *pts = NULL; @@ -478,7 +481,7 @@ void BSYorkItem::drawFbsdLines (QPainter *painter, bool alone, bool disp) } -bool BSYorkItem::toggleDilationType () +bool BSGroundtruthItem::toggleDilationType () { if (++dilationType == 4) dilationType = 0; return (type == DILATED_CANNY_ALONE diff --git a/Code/FBSD/BSTools/bsyorkitem.h b/Code/FBSD/BSTools/bsgroundtruthitem.h similarity index 77% rename from Code/FBSD/BSTools/bsyorkitem.h rename to Code/FBSD/BSTools/bsgroundtruthitem.h index a051a8206ee44cc6bdc935977ff155dc2f64af89..996bd759e70038ae7f29ccb97d3f0df380b8cc24 100755 --- a/Code/FBSD/BSTools/bsyorkitem.h +++ b/Code/FBSD/BSTools/bsgroundtruthitem.h @@ -1,5 +1,5 @@ -#ifndef BS_GT_ITEM_H -#define BS_GT_ITEM_H +#ifndef BS_GROUNDTRUTH_ITEM_H +#define BS_GROUNDTRUTH_ITEM_H #include <QGraphicsItem> #include "bsdetector.h" @@ -9,23 +9,24 @@ using namespace std; /** - * @class BSYorkItem bsyorkitem.h - * \brief Blurred segment comparator with YorkLine. + * @class BSGroundtruthItem bsgroundtruthitem.h + * \brief Blurred segment comparator with groundtruth lines. * \author {P. Even} */ -class BSYorkItem : public QGraphicsItem +class BSGroundtruthItem : public QGraphicsItem { public: /** - * \brief Creates a YorkLine comparator. + * \brief Creates a groundtruth comparator. */ - BSYorkItem (int width, int height, const QImage *im, BSDetector *detector); + BSGroundtruthItem (int width, int height, + const QImage *im, BSDetector *detector); /** - * \brief Deletes the YorkLine comparator. + * \brief Deletes the groundtruth comparator. */ - ~BSYorkItem (); + ~BSGroundtruthItem (); /** * \brief Returns the grid area. @@ -33,7 +34,7 @@ public: QRectF boundingRect () const; /** - * \brief Redraws the YorkLine comparator grid. + * \brief Redraws the groundtruth comparator grid. */ void paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); @@ -66,37 +67,37 @@ public: */ inline QString itemTitle () const { if (type == GT_ALONE) - return ("York Urban DB ground truth"); + return ("Groundtruth lines alone"); else if (type == DILATED_LSD_ALONE) return ("Dilated_LSD lines"); else if (type == LSD_ALONE) return ("LSD lines"); else if (type == GT_OVER_LSD) - return ("York over LSD lines"); + return ("Groundtruth over LSD lines"); else if (type == DILATED_ED_ALONE) return ("Dilated_ED lines"); else if (type == ED_ALONE) return ("ED lines"); else if (type == GT_OVER_ED) - return ("York over ED lines"); + return ("Groundtruth over ED lines"); else if (type == DILATED_CANNY_ALONE) return ("Dilated_Canny lines"); else if (type == CANNY_ALONE) return ("Canny lines"); else if (type == GT_OVER_CANNY) - return ("York over Canny lines"); + return ("Groundtruth over Canny lines"); else if (type == FBSD_LINES) return ("FBSD output lines"); else if (type == FBSD_ALONE) return ("FBSD detection"); else if (type == GT_OVER_BS) - return ("York over blurred segments points"); + return ("Groundtruth over blurred segments points"); else if (type == GT_OVER_DSS) - return ("York over digital straight segments"); + return ("Groundtruth over digital straight segments"); else if (type == GT_WITH_CANNY) - return ("York blend with Canny lines"); + return ("Groundtruth blend with Canny lines"); else if (type == GT_WITH_DSS) - return ("York blend with digital straight lines"); + return ("Groundtruth blend with digital straight lines"); else return ("No info"); } @@ -104,37 +105,37 @@ public: private: - /** York lines alone display modality. */ + /** Groundtruth alone display modality. */ static const int GT_ALONE; /** Lsd lines alone display modality. */ static const int LSD_ALONE; /** Dilated Lsd lines alone display modality. */ static const int DILATED_LSD_ALONE; - /** York over Lsd display modality. */ + /** Groundtruth lines over Lsd display modality. */ static const int GT_OVER_LSD; /** ED lines alone display modality. */ static const int ED_ALONE; /** Dilated ED lines alone display modality. */ static const int DILATED_ED_ALONE; - /** York over ED display modality. */ + /** Groundtruth lines over ED display modality. */ static const int GT_OVER_ED; /** Canny lines alone display modality. */ static const int CANNY_ALONE; /** Dilated Canny lines alone display modality. */ static const int DILATED_CANNY_ALONE; - /** York over Canny display modality. */ + /** Groundtruth lines over Canny display modality. */ static const int GT_OVER_CANNY; /** FBSD output lines alone display modality. */ static const int FBSD_LINES; /** FBSD detected lines alone display modality. */ static const int FBSD_ALONE; - /** York over BS display modality. */ + /** Groundtruth lines over BS display modality. */ static const int GT_OVER_BS; - /** York over DSS display modality. */ + /** Groundtruth lines over DSS display modality. */ static const int GT_OVER_DSS; - /** York with Canny display modality. */ + /** Groundtruth lines with Canny display modality. */ static const int GT_WITH_CANNY; - /** York with DSS display modality. */ + /** Groundtruth lines with DSS display modality. */ static const int GT_WITH_DSS; /** No info display modality. */ static const int NO_INFO; @@ -149,7 +150,7 @@ private: /** Default value for pen width. */ static const int DEFAULT_PEN_WIDTH; - /** Set of Ground truths lines. */ + /** Set of groundtruth lines. */ ExtLines *gts; /** Set of Lsd lines. */ ExtLines *lsds; @@ -170,7 +171,7 @@ private: BSDetector *det; /** Blurred segments map */ bool *bsmap; - /** York lines map */ + /** Groundtruth lines map */ bool *clmap; /** Display modality */ int type; @@ -186,7 +187,7 @@ private: /** Displays a set of points */ void drawPoints (QPainter *painter, vector<Pt2i> pts, bool disp = true); - /** Displays ground truth */ + /** Displays groundtruth lines */ void drawGroundTruth (QPainter *painter, bool alone); /** Displays Lsd lines */ diff --git a/Code/FBSD/BSTools/bsyorkview.cpp b/Code/FBSD/BSTools/bsgroundtruthview.cpp similarity index 50% rename from Code/FBSD/BSTools/bsyorkview.cpp rename to Code/FBSD/BSTools/bsgroundtruthview.cpp index 15addd0e7338a02eabee183f0f17117a2a3f87d2..e13238a97cbe8904480bd3da78a4a250c9ffbedf 100755 --- a/Code/FBSD/BSTools/bsyorkview.cpp +++ b/Code/FBSD/BSTools/bsgroundtruthview.cpp @@ -1,34 +1,34 @@ #include <QtGui> #include <iostream> -#include "bsyorkview.h" +#include "bsgroundtruthview.h" #include "math.h" using namespace std; -BSYorkView::BSYorkView (QImage *im, BSDetector *sd) +BSGroundtruthView::BSGroundtruthView (QImage *im, BSDetector *sd) { int w = im->width (); int h = im->height (); image = im; setScene (new QGraphicsScene (0, 0, w, h)); - york = new BSYorkItem (w, h, image, sd); + groundtruth = new BSGroundtruthItem (w, h, image, sd); //setBackgroundBrush (QBrush (*image)); - scene()->addItem (york); - setWindowTitle (york->itemTitle ()); + scene()->addItem (groundtruth); + setWindowTitle (groundtruth->itemTitle ()); } -BSYorkView::~BSYorkView () +BSGroundtruthView::~BSGroundtruthView () { - scene()->removeItem (york); - delete york; + scene()->removeItem (groundtruth); + delete groundtruth; } -void BSYorkView::paint (QPainter *painter, - const QStyleOptionGraphicsItem *option, - QWidget *widget) +void BSGroundtruthView::paint (QPainter *painter, + const QStyleOptionGraphicsItem *option, + QWidget *widget) { Q_UNUSED (painter); Q_UNUSED (option); @@ -36,20 +36,20 @@ void BSYorkView::paint (QPainter *painter, } -bool BSYorkView::processKeyEvent (QKeyEvent *event) +bool BSGroundtruthView::processKeyEvent (QKeyEvent *event) { bool processed = false; switch (event->key ()) { case Qt::Key_I : // Info - york->toggleType (event->modifiers () & Qt::ShiftModifier); + groundtruth->toggleType (event->modifiers () & Qt::ShiftModifier); scene()->update (); update (); - setWindowTitle (york->itemTitle ()); + setWindowTitle (groundtruth->itemTitle ()); break; case Qt::Key_D : // Canny dilation - if (york->toggleDilationType ()) + if (groundtruth->toggleDilationType ()) { scene()->update (); update (); @@ -59,7 +59,7 @@ bool BSYorkView::processKeyEvent (QKeyEvent *event) case Qt::Key_P : // Capture viewport()->grab ( QRect (QPoint (0, 0), - QSize (york->getWidth(), york->getHeight())) + QSize (groundtruth->getWidth(), groundtruth->getHeight())) ).toImage().save ("external.png"); cout << "External detectors view shot in external.png" << endl; break; diff --git a/Code/FBSD/BSTools/bsgroundtruthview.h b/Code/FBSD/BSTools/bsgroundtruthview.h new file mode 100755 index 0000000000000000000000000000000000000000..35759fb794b337f5ba77e984cf20fcb4b29e25c2 --- /dev/null +++ b/Code/FBSD/BSTools/bsgroundtruthview.h @@ -0,0 +1,52 @@ +#ifndef BS_GROUNDTRUTH_VIEW_H +#define BS_GROUNDTRUTH_VIEW_H + +#include <QGraphicsView> +#include <QImage> +#include "bsgroundtruthitem.h" + + +/** + * @class BSGroundtruthView bsgroundtruthview.h + * \brief A Qt window to compare detected segments with groundtruth lines. + * \author {P. Even} + */ +class BSGroundtruthView : public QGraphicsView +{ + +public: + + /** + * \brief Creates a groundtruth comparator view. + */ + BSGroundtruthView (QImage *im, BSDetector *sd); + + /** + * \brief Deletes the groundtruth comparator view. + */ + ~BSGroundtruthView (); + + /** + * \brief Redraws the groundtruth comparator view. + */ + void paint (QPainter *painter, + const QStyleOptionGraphicsItem *option, QWidget *widget); + + /** + * \brief Processes key pressed events. + */ + bool processKeyEvent (QKeyEvent *event); + + +protected: + +private: + + /** Pointer to the blurred segment structure graphics item. */ + BSGroundtruthItem *groundtruth; + /** Pointer to the displayed image. */ + QImage *image; + +}; + +#endif diff --git a/Code/FBSD/BSTools/bsrandomtester.cpp b/Code/FBSD/BSTools/bsrandomtester.cpp index 06410b85762ce184892d5f1a297734c55b9991d7..91df0c5c75c524cf52d1973a2a708906a1c047af 100755 --- a/Code/FBSD/BSTools/bsrandomtester.cpp +++ b/Code/FBSD/BSTools/bsrandomtester.cpp @@ -73,8 +73,8 @@ BSRandomTester::BSRandomTester () for (int i = 0; i < nbdets; i++) { detectors[i].setAssignedThickness (smaxwidth + swmargin); - if (! detectors[i].isFinalLengthTestOn ()) - detectors[i].switchFinalLengthTest (); + if (! detectors[i].isFinalSizeTestOn ()) + detectors[i].switchFinalSizeTest (); } detectors[0].setStaticDetector (true); detectors[1].setStaticDetector (false); diff --git a/Code/FBSD/BSTools/bsstructureitem.cpp b/Code/FBSD/BSTools/bsstructureitem.cpp index ce538863195149dcf4f8724c34e6a3b60bc68113..995c5d7e511b95f3b673ca47f52ba0b63037fd51 100755 --- a/Code/FBSD/BSTools/bsstructureitem.cpp +++ b/Code/FBSD/BSTools/bsstructureitem.cpp @@ -143,7 +143,7 @@ void BSStructureItem::paintBlurredSegment (QPainter *painter, int step) addText (painter, QString ("W : assigned thickness = ") + QString::number (det->assignedThickness ())); addText (painter, QString ("L : output BS min size = ") - + QString::number (det->getBSminSize ())); + + QString::number (det->finalSizeMinValue ())); addText (painter, QString ("H : pixel lack tolerence = ") + QString::number (det->getPixelLackTolerence ())); if (step == 0) @@ -186,26 +186,26 @@ void BSStructureItem::paintConnectedComponents (QPainter *painter, int step) initText (painter); if (bs != NULL) { - int ccs = det->getConnectedComponentMinSize (); + int ccs = det->fragmentSizeMinValue (); int bsccp = bs->countOfConnectedPoints (ccs); int bssize = bs->getAllPoints().size (); bool ccon = (step == BSDetector::STEP_FINAL - && det->isConnectivityConstraintOn ()); - addText (painter, QString ("Connectivity constraint ") + (ccon ? + && det->isFinalFragmentationTestOn ()); + addText (painter, QString ("Fragmentation test ") + (ccon ? QString ("on") : QString ("off"))); addText (painter, QString::number (bssize) + QString (" points")); addText (painter, QString::number (bs->countOfConnectedComponents ()) - + QString (" connected components")); + + QString (" fragments")); addText (painter, QString::number (bs->countOfConnectedPoints ()) - + QString (" connected points")); + + QString (" points in fragments")); addText (painter, QString::number (bs->countOfConnectedComponents (ccs)) - + QString (" connected components with min size ") + + QString (" fragments with min size ") + QString::number (ccs)); addText (painter, QString::number (bsccp) - + QString (" connected points with min size ") + + QString (" points in fragments with min size ") + QString::number (ccs)); if (ccon && bsccp < bssize / 2) - addText (painter, QString ("BS too sparse !")); + addText (painter, QString ("BS too fragmented !")); } } } diff --git a/Code/FBSD/BSTools/bsyorkview.h b/Code/FBSD/BSTools/bsyorkview.h deleted file mode 100755 index 1739f67155160a79a0ae1b53b67f0f144fd55a3e..0000000000000000000000000000000000000000 --- a/Code/FBSD/BSTools/bsyorkview.h +++ /dev/null @@ -1,52 +0,0 @@ -#ifndef BS_YORK_VIEW_H -#define BS_YORK_VIEW_H - -#include <QGraphicsView> -#include <QImage> -#include "bsyorkitem.h" - - -/** - * @class BSYorkView bsyorkview.h - * \brief A Qt window to compare detected segments with York Urban image base. - * \author {P. Even} - */ -class BSYorkView : public QGraphicsView -{ - -public: - - /** - * \brief Creates a York Urban image database comparator view. - */ - BSYorkView (QImage *im, BSDetector *sd); - - /** - * \brief Deletes the York comparator view. - */ - ~BSYorkView (); - - /** - * \brief Redraws the York comparator view. - */ - void paint (QPainter *painter, - const QStyleOptionGraphicsItem *option, QWidget *widget); - - /** - * \brief Processes key pressed events. - */ - bool processKeyEvent (QKeyEvent *event); - - -protected: - -private: - - /** Pointer to the blurred segment structure graphics item. */ - BSYorkItem *york; - /** Pointer to the displayed image. */ - QImage *image; - -}; - -#endif diff --git a/Code/FBSD/BSTools/extlines.cpp b/Code/FBSD/BSTools/extlines.cpp index 8baeb16215c57b89fecee6fe2db14f5b26641e48..55cfe327a428ffc1ed919993f8ecec6d21505687 100755 --- a/Code/FBSD/BSTools/extlines.cpp +++ b/Code/FBSD/BSTools/extlines.cpp @@ -10,7 +10,7 @@ using namespace std; const double ExtLines::MIN_LENGTH = 10.; -ExtLines::ExtLines (bool groundTruth) +ExtLines::ExtLines (bool groundTruth, bool extdets) { QImage im; im.load ("Data/york.jpg"); @@ -50,11 +50,15 @@ ExtLines::ExtLines (bool groundTruth) loaded = true; } } - stats (im); - stats ("Data/cannylines.txt", 5, "Data/cannycov.txt", "Data/cannyln.txt"); - stats ("Data/edlines.txt", 4, "Data/edcov.txt", "Data/edln.txt"); - stats ("Data/lsdlines.txt", 7, "Data/lsdcov.txt", "Data/lsdln.txt"); - stats ("Data/naivelines.txt", 5, "Data/naivecov.txt", "Data/naiveln.txt"); + stats (im, false); + if (extdets) + { + stats ("Data/cannylines.txt", 5, "Data/cannycov.txt", "Data/cannyln.txt"); + stats ("Data/edlines.txt", 4, "Data/edcov.txt", "Data/edln.txt"); + stats ("Data/lsdlines.txt", 7, "Data/lsdcov.txt", "Data/lsdln.txt"); + stats ("Data/naivelines.txt", 5, "Data/naivecov.txt", "Data/naiveln.txt"); + } + else stats (im, true); } @@ -283,9 +287,10 @@ cout << "COUNTING" << endl; } -void ExtLines::stats (const QImage &im) +void ExtLines::stats (const QImage &im, bool alt) { BSDetector detector; + if (alt) detector.setStaticDetector (true); int **tabImage = new int*[height]; for (int i = 0; i < height; i++) { @@ -310,12 +315,21 @@ void ExtLines::stats (const QImage &im) if (loaded) { double covFBSD = covering (bss); - ofstream outf ("Data/fbsdcov.txt", ios::out); - outf << covFBSD << endl; - outf.close (); + if (alt) + { + ofstream outf ("Data/altcov.txt", ios::out); + outf << covFBSD << endl; + outf.close (); + } + else + { + ofstream outf ("Data/fbsdcov.txt", ios::out); + outf << covFBSD << endl; + outf.close (); + } } - double mylength, mylg = 0.; + double mylength, mylg = 0., myth = 0.; int mynb = 0; // int nbs = (int) bss.size (); vector<BlurredSegment *>::iterator it = bss.begin (); @@ -329,14 +343,36 @@ void ExtLines::stats (const QImage &im) * (lastleft.y () - lastright.y ())); if (mylength >= MIN_LENGTH) { + DigitalStraightSegment *dss = (*it)->getSegment (); + if (dss != NULL) + { + AbsRat eth2 = dss->squaredEuclideanThickness (); + double eth = sqrt (eth2.num () / (double) (eth2.den ())); + myth += eth * mylength; + } mylg += mylength; mynb++; } it ++; } - ofstream outl ("Data/fbsdln.txt", ios::out); - outl << mynb << " " << mylg << " " << (mylg / mynb) << endl; - outl.close (); + if (alt) + { + ofstream outl ("Data/altln.txt", ios::out); + outl << mynb << " " << mylg << " " << (mylg / mynb) << endl; + outl.close (); + ofstream outth ("Data/altth.txt", ios::out); + outth << myth << " " << (myth / mylg) << endl; + outth.close (); + } + else + { + ofstream outl ("Data/fbsdln.txt", ios::out); + outl << mynb << " " << mylg << " " << (mylg / mynb) << endl; + outl.close (); + ofstream outth ("Data/fbsdth.txt", ios::out); + outth << myth << " " << (myth / mylg) << endl; + outth.close (); + } for (int i = 0; i < height; i++) delete [] tabImage[i]; delete [] tabImage; diff --git a/Code/FBSD/BSTools/extlines.h b/Code/FBSD/BSTools/extlines.h index 2088bf685acbfd8bc840c9ebed400097dbee040b..bdf9d6fd675d323a8fc53ae85494452581f04b43 100755 --- a/Code/FBSD/BSTools/extlines.h +++ b/Code/FBSD/BSTools/extlines.h @@ -19,8 +19,10 @@ public: /** * \brief Creates an external lines set and runs statistics. + * @param groundTruth Indicates if testing with a lines groundtruth. + * @param extdets Indicates if testing with external detectors. */ - ExtLines (bool groundTruth); + ExtLines (bool groundTruth, bool extdets); /** * \brief Creates an external lines set. @@ -121,7 +123,18 @@ private: int height; - void stats (const QImage &im); + /** Extracts covering stats on the detector. + * @param im Test image. + * @param alt Alternate version tested. + */ + void stats (const QImage &im, bool alt); + + /** Extracts covering stats on an external detector. + * @param lname Input line file from external detector. + * @param nbinfo Count of values per line in the file. + * @param covname Output file of covering value. + * @param lgname Output file of lines count and length. + */ void stats (const char *lname, int nbinfo, const char *covname, const char *lgname); diff --git a/Code/FBSD/BlurredSegment/bsdetector.cpp b/Code/FBSD/BlurredSegment/bsdetector.cpp index d3652fdc80219c80dc7b62008428c84442953fcc..bcb64bb8ea9cd6c571f5c0b9cb81dc648e5b43ff 100755 --- a/Code/FBSD/BlurredSegment/bsdetector.cpp +++ b/Code/FBSD/BlurredSegment/bsdetector.cpp @@ -21,16 +21,17 @@ const int BSDetector::RESULT_FINAL_NO_DETECTION = 21; const int BSDetector::RESULT_FINAL_TOO_FEW = 22; const int BSDetector::RESULT_FINAL_TOO_SPARSE = 23; const int BSDetector::RESULT_FINAL_TOO_SMALL = 24; -const int BSDetector::RESULT_FINAL_TOO_MANY_OUTLIERS = 25; +const int BSDetector::RESULT_FINAL_TOO_FRAGMENTED = 25; +const int BSDetector::RESULT_FINAL_TOO_MANY_OUTLIERS = 26; const int BSDetector::DEFAULT_FAST_TRACK_SCAN_WIDTH = 16; const int BSDetector::DEFAULT_ASSIGNED_THICKNESS = 3; -const int BSDetector::DEFAULT_FAST_TRACK_MAX_MARGIN = 2; +const int BSDetector::FAST_TRACK_MARGIN = 2; -const int BSDetector::DEFAULT_BS_MIN_SIZE = 5; -const int BSDetector::ABSOLUTE_BS_MIN_SIZE = 3; +const int BSDetector::BS_MIN_SIZE = 3; +const int BSDetector::DEFAULT_INITIAL_MIN_SIZE = 5; const int BSDetector::DEFAULT_FINAL_MIN_SIZE = 10; -const int BSDetector::DEFAULT_CONNECT_MIN_SIZE = 5; +const int BSDetector::DEFAULT_FRAGMENT_MIN_SIZE = 5; const int BSDetector::DEFAULT_AUTO_SWEEPING_STEP = 15; const int BSDetector::PRELIM_MIN_HALF_WIDTH = 10; @@ -38,21 +39,23 @@ const int BSDetector::PRELIM_MIN_HALF_WIDTH = 10; BSDetector::BSDetector () { gMap = NULL; - inThick = DEFAULT_ASSIGNED_THICKNESS; - imaxMargin = DEFAULT_FAST_TRACK_MAX_MARGIN; - prelimDetectionOn = false; + staticDetOn = false; + bst0 = (prelimDetectionOn ? new BSTracker () : NULL); bst1 = new BSTracker (); // bst1->setPixelLackTolerence (bst1->getVicinityThreshold ()); bst2 = new BSTracker (); - bstold = new BSTracker (); - if (bstold->dynamicScansOn ()) bstold->toggleDynamicScans (); - if (bstold->isAssignedThicknessControlOn ()) - bstold->toggleAssignedThicknessControl (); + bstStatic = NULL; + if (staticDetOn) + { + bstStatic = new BSTracker (); + if (bstStatic->dynamicScansOn ()) bstStatic->toggleDynamicScans (); + if (bstStatic->isAssignedThicknessControlOn ()) + bstStatic->toggleAssignedThicknessControl (); + } - staticDetOn = false; prefilteringOn = false; //lsf1 = (prefilteringOn ? new LineSpaceFilter () : NULL); lsf1 = (prefilteringOn ? new BSFilter () : NULL); @@ -61,16 +64,14 @@ BSDetector::BSDetector () lsf2 = (filteringOn ? new BSFilter () : NULL); edgeDirection = 0; // detects strokes (not only edges) - bsMinSize = DEFAULT_BS_MIN_SIZE; - ccOn = false; - ccMinSize = DEFAULT_CONNECT_MIN_SIZE; + initialMinSize = DEFAULT_INITIAL_MIN_SIZE; + finalFragmentationTestOn = false; + fragmentMinSize = DEFAULT_FRAGMENT_MIN_SIZE; recenteringOn = true; - fittingOn = false; - densityTestOn = true; - finalDensityTestOn = false; - finalLengthTestOn = false; + initialSparsityTestOn = true; finalSizeTestOn = true; - finalSizeMinVal = DEFAULT_FINAL_MIN_SIZE; + finalMinSize = DEFAULT_FINAL_MIN_SIZE; + finalSparsityTestOn = false; // nbSmallBS = 0; multiSelection = false; autodet = false; @@ -88,6 +89,7 @@ BSDetector::BSDetector () BSDetector::~BSDetector () { if (prelimDetectionOn) delete bst0; + if (staticDetOn) delete bstStatic; delete bst1; delete bst2; if (lsf1 != NULL) delete lsf1; @@ -103,9 +105,9 @@ void BSDetector::setGradientMap (VMap *data) { gMap = data; if (prelimDetectionOn) bst0->setGradientMap (data); + if (staticDetOn) bstStatic->setGradientMap (data); bst1->setGradientMap (data); bst2->setGradientMap (data); - bstold->setGradientMap (data); } @@ -123,11 +125,13 @@ void BSDetector::detectAll () int height = gMap->getHeight (); for (int x = width / 2; isnext && x > 0; x -= autoSweepingStep) isnext = runMultiDetection (Pt2i (x, 0), Pt2i (x, height - 1)); - for (int x = width / 2 + autoSweepingStep; isnext && x < width - 1; x += autoSweepingStep) + for (int x = width / 2 + autoSweepingStep; + isnext && x < width - 1; x += autoSweepingStep) isnext = runMultiDetection (Pt2i (x, 0), Pt2i (x, height - 1)); for (int y = height / 2; isnext && y > 0; y -= autoSweepingStep) isnext = runMultiDetection (Pt2i (0, y), Pt2i (width - 1, y)); - for (int y = height / 2 + autoSweepingStep; isnext && y < height - 1; y += autoSweepingStep) + for (int y = height / 2 + autoSweepingStep; + isnext && y < height - 1; y += autoSweepingStep) isnext = runMultiDetection (Pt2i (0, y), Pt2i (width - 1, y)); if (maxtrials > (int) (mbsf.size ())) maxtrials = 0; // cout << nbSmallBS << " petits BS elimines" << endl; @@ -289,9 +293,9 @@ int BSDetector::detect (const Pt2i &p1, const Pt2i &p2, //--------------------------------------------------------------------- if (prelimDetectionOn) { - bspre = bst0->fastTrack (inThick + imaxMargin, + bspre = bst0->fastTrack (inThick + FAST_TRACK_MARGIN, prep1, prep2, prewidth, prepc); - if (bspre == NULL || bspre->size () < bsMinSize) + if (bspre == NULL || bspre->size () < initialMinSize) return (bspre == NULL ? RESULT_PRELIM_NO_DETECTION : RESULT_PRELIM_TOO_FEW); @@ -319,15 +323,15 @@ int BSDetector::detect (const Pt2i &p1, const Pt2i &p2, // Initial detection based on highest gradient without orientation constraint //--------------------------------------------------------------------------- - bsini = bst1->fastTrack (inThick + imaxMargin, + bsini = bst1->fastTrack (inThick + FAST_TRACK_MARGIN, inip1, inip2, iniwidth, inipc); - if (bsini == NULL || bsini->size () < bsMinSize) + if (bsini == NULL || bsini->size () < initialMinSize) return (bsini == NULL ? RESULT_INITIAL_NO_DETECTION : RESULT_INITIAL_TOO_FEW); - // Density test + // Sparsity test //------------- - if (densityTestOn) + if (initialSparsityTestOn) { DigitalStraightLine mydsl (inip1, inip2, DigitalStraightLine::DSL_NAIVE); int mydrlf = mydsl.manhattan (bsini->getLastRight ()) @@ -348,7 +352,7 @@ int BSDetector::detect (const Pt2i &p1, const Pt2i &p2, delete bsini; bsini = fbs; } - if (bsini->size () < bsMinSize) + if (bsini->size () < initialMinSize) return RESULT_INITIAL_TOO_MANY_OUTLIERS; } @@ -368,18 +372,11 @@ int BSDetector::detect (const Pt2i &p1, const Pt2i &p2, //----------------------------- if (recenteringOn) pCenter = bsini->getSegment()->centerOfIntersection (inip1, inip2); - int bswidth = inThick; - if (fittingOn) - { - DigitalStraightSegment *dss = bsini->getSegment (); - if (dss != NULL) - bswidth = 1 + dss->width () / dss->period (); - } // Finer detection based on gradient maxima with orientation constraint //--------------------------------------------------------------------- - bsf = bst2->fineTrack (bswidth, pCenter, bsinidir, 2 * bswidth, gRef); - if (bsf == NULL || bsf->size () < bsMinSize) + bsf = bst2->fineTrack (inThick, pCenter, bsinidir, 2 * inThick, gRef); + if (bsf == NULL || bsf->size () < initialMinSize) return (bsf == NULL ? RESULT_FINAL_NO_DETECTION : RESULT_FINAL_TOO_FEW); // Size test @@ -387,29 +384,19 @@ int BSDetector::detect (const Pt2i &p1, const Pt2i &p2, if (finalSizeTestOn) { // DigitalStraightSegment *dss = bsf->getSegment (); - if ((int) (bsf->getAllPoints().size ()) < finalSizeMinVal) + if ((int) (bsf->getAllPoints().size ()) < finalMinSize) { // nbSmallBS ++; return RESULT_FINAL_TOO_SMALL; } } - // Length test - //------------ - if (finalLengthTestOn) + // Sparsity test + //-------------- + if (finalSparsityTestOn) { - DigitalStraightSegment *dss = bsf->getSegment (); - if ((int) (bsf->getAllPoints().size ()) - < (3 * dss->width ()) / dss->period ()) - // if ((int) (bsf->getAllPoints().size ()) < 10) - return RESULT_FINAL_TOO_SPARSE; - } - - // New density test - //----------------- - if (finalDensityTestOn) - { - DigitalStraightLine mydsl (inip1, inip2, DigitalStraightLine::DSL_NAIVE); + Pt2i pOrtho (pCenter.x () + bsinidir.y (), pCenter.y () - bsinidir.y ()); + DigitalStraightLine mydsl (pCenter, pOrtho, DigitalStraightLine::DSL_NAIVE); int mydrlf = mydsl.manhattan (bsf->getLastRight ()) - mydsl.manhattan (bsf->getLastLeft ()); if (mydrlf < 0) mydrlf = -mydrlf; // Case of horizontal P1P2 @@ -418,19 +405,13 @@ int BSDetector::detect (const Pt2i &p1, const Pt2i &p2, return RESULT_FINAL_TOO_SPARSE; } - // Connected components analysis */ - //------------------------------*/ - if (ccOn) + // Fragmentation test */ + //--------------------*/ + if (finalFragmentationTestOn) { - int bsccp = bsf->countOfConnectedPoints (ccMinSize); + int bsccp = bsf->countOfConnectedPoints (fragmentMinSize); int bssize = bsf->getAllPoints().size (); - if (bsccp < bssize / 2) - return RESULT_FINAL_TOO_SPARSE; - -/* - if (bssize < 20 || bsf->countOfConnectedComponents (bssize / 2) == 0) - return RESULT_FINAL_TOO_SPARSE; -*/ + if (bsccp < bssize / 2) return RESULT_FINAL_TOO_FRAGMENTED; } @@ -452,7 +433,7 @@ int BSDetector::detect (const Pt2i &p1, const Pt2i &p2, int BSDetector::staticDetect (const Pt2i &p1, const Pt2i &p2, - bool centralp, const Pt2i &pc) + bool centralp, const Pt2i &pc) { // Entry check //------------ @@ -463,7 +444,7 @@ int BSDetector::staticDetect (const Pt2i &p1, const Pt2i &p2, // Clearance //---------- bst1->clear (); - bst2->clear (); + bstStatic->clear (); if (bsini != NULL) delete bsini; bsini = NULL; if (bsf != NULL) delete bsf; @@ -478,14 +459,14 @@ int BSDetector::staticDetect (const Pt2i &p1, const Pt2i &p2, //--------------------------------------------------------------------------- bsini = bst1->fastTrack (DEFAULT_FAST_TRACK_SCAN_WIDTH / 4, inip1, inip2, iniwidth, inipc); - if (bsini == NULL || bsini->size () < bsMinSize) + if (bsini == NULL || bsini->size () < initialMinSize) return (bsini == NULL ? RESULT_INITIAL_NO_DETECTION : RESULT_INITIAL_TOO_FEW); - // Density test + // Sparsity test //------------- /* - if (densityTestOn) + if (initialSparsityTestOn) { DigitalStraightLine mydsl (inip1, inip2, DigitalStraightLine::DSL_NAIVE); int mydrlf = mydsl.manhattan (bsini->getLastRight ()) @@ -516,9 +497,9 @@ int BSDetector::staticDetect (const Pt2i &p1, const Pt2i &p2, // Finer detection based on gradient maxima with orientation constraint //--------------------------------------------------------------------- - bsf = bstold->fineTrack (inThick, pCenter, bsinidir, - 4 * inThick, gRef); - if (bsf == NULL || bsf->size () < bsMinSize) + bsf = bstStatic->fineTrack (inThick, pCenter, bsinidir, + 4 * inThick, gRef); + if (bsf == NULL || bsf->size () < initialMinSize) return (bsf == NULL ? RESULT_FINAL_NO_DETECTION : RESULT_FINAL_TOO_FEW); // Scan recentering and fitting @@ -529,10 +510,10 @@ int BSDetector::staticDetect (const Pt2i &p1, const Pt2i &p2, // Third detection based on gradient maxima with orientation constraint //--------------------------------------------------------------------- - BlurredSegment *bsf2 = bstold->fineTrack (inThick, - pCenter, bsf->getSupportVector(), - 4 * inThick, gRef); - if (bsf2 == NULL || bsf2->size () < bsMinSize) + BlurredSegment *bsf2 = bstStatic->fineTrack (inThick, + pCenter, bsf->getSupportVector(), + 4 * inThick, gRef); + if (bsf2 == NULL || bsf2->size () < initialMinSize) { if (bsf2 != NULL) { @@ -547,21 +528,12 @@ int BSDetector::staticDetect (const Pt2i &p1, const Pt2i &p2, bsf = bsf2; } - // Length test - //------------ - if (finalLengthTestOn) - { - DigitalStraightSegment *dss = bsf->getSegment (); - if (dss == NULL || (int) (bsf->getAllPoints().size ()) - < (10 * dss->period ()) / dss->width ()) - return RESULT_FINAL_TOO_SPARSE; - } - - // New density test + // Final sparsity test //----------------- - if (finalDensityTestOn) + if (finalSparsityTestOn) { - DigitalStraightLine mydsl (inip1, inip2, DigitalStraightLine::DSL_NAIVE); + Pt2i pOrtho (pCenter.x () + bsinidir.y (), pCenter.y () - bsinidir.y ()); + DigitalStraightLine mydsl (pCenter, pOrtho, DigitalStraightLine::DSL_NAIVE); int mydrlf = mydsl.manhattan (bsf->getLastRight ()) - mydsl.manhattan (bsf->getLastLeft ()); if (mydrlf < 0) mydrlf = -mydrlf; // Case of horizontal P1P2 @@ -572,17 +544,11 @@ int BSDetector::staticDetect (const Pt2i &p1, const Pt2i &p2, // Connected components analysis //------------------------------ - if (ccOn) + if (finalFragmentationTestOn) { - int bsccp = bsf->countOfConnectedPoints (ccMinSize); + int bsccp = bsf->countOfConnectedPoints (fragmentMinSize); int bssize = bsf->getAllPoints().size (); - if (bsccp < bssize / 2) - return RESULT_FINAL_TOO_SPARSE; - -/* - if (bssize < 20 || bsf->countOfConnectedComponents (bssize / 4) == 0) - return RESULT_FINAL_TOO_SPARSE; -*/ + if (bsccp < bssize / 2) return RESULT_FINAL_TOO_FRAGMENTED; } return RESULT_OK; @@ -651,6 +617,7 @@ void BSDetector::setFinalScansRecord (bool status) void BSDetector::switchOrthoScans () { if (prelimDetectionOn) bst0->switchOrthoScans (); + if (staticDetOn) bstStatic->switchOrthoScans (); bst1->switchOrthoScans (); bst2->switchOrthoScans (); } @@ -685,10 +652,10 @@ void BSDetector::switchFiltering (int step) } -bool BSDetector::incConnectedComponentMinSize (bool increase) +bool BSDetector::incFragmentSizeMinValue (bool increase) { - if ((! increase) && ccMinSize <= 1) return false; - ccMinSize += (increase ? 1 : -1); + if ((! increase) && fragmentMinSize <= 1) return false; + fragmentMinSize += (increase ? 1 : -1); return true; } @@ -710,6 +677,25 @@ void BSDetector::switchPreliminary () } +void BSDetector::setStaticDetector (bool status) +{ + if (staticDetOn && ! status) + { + delete bstStatic; + staticDetOn = false; + } + else if (status && ! staticDetOn) + { + bstStatic = new BSTracker (); + bstStatic->setGradientMap (gMap); + if (bstStatic->dynamicScansOn ()) bstStatic->toggleDynamicScans (); + if (bstStatic->isAssignedThicknessControlOn ()) + bstStatic->toggleAssignedThicknessControl (); + staticDetOn = true; + } +} + + std::string BSDetector::version () { return BSDetector::VERSION; diff --git a/Code/FBSD/BlurredSegment/bsdetector.h b/Code/FBSD/BlurredSegment/bsdetector.h index cfb1f0168dc5d7a8d9731f47a9a924ed737ed36f..4ecb3289ae36939a4ddb18a0911b53dbe93e87c2 100755 --- a/Code/FBSD/BlurredSegment/bsdetector.h +++ b/Code/FBSD/BlurredSegment/bsdetector.h @@ -55,6 +55,8 @@ public: static const int RESULT_FINAL_TOO_SPARSE; /** Extraction result : unsuccessful spread test at final detection. */ static const int RESULT_FINAL_TOO_SMALL; + /** Extraction result : unsuccessful fragmentation test at final detection. */ + static const int RESULT_FINAL_TOO_FRAGMENTED; /** Extraction result : unsuccessful filter test at final detection. */ static const int RESULT_FINAL_TOO_MANY_OUTLIERS; @@ -176,28 +178,16 @@ public: */ inline void setAssignedThickness (int val) { if (val > 0) inThick = val; } - /** - * \brief Returns the assigned maximal width margin for the fast tracks. - */ - inline int fastTracksMaxMargin () const { return imaxMargin; } - - /** - * \brief Sets the assigned maximal width margin for the fast tracks. - * @param val New width value. - */ - inline void setFastTracksMaxMargin (int val) { - if (val >= 0) imaxMargin = val; } - /** * \brief Returns the output blurred segment minimal size. */ - inline int getBSminSize () const { return bsMinSize; } + inline int initialSizeMinValue () const { return initialMinSize; } /** * \brief Sets the output blurred segment minimal size. */ - inline void setBSminSize (int value) { - if (value >= ABSOLUTE_BS_MIN_SIZE) bsMinSize = value; } + inline void setInitialMinSize (int value) { + initialMinSize = (value >= BS_MIN_SIZE ? value : BS_MIN_SIZE); } /** * \brief Returns the threshold used for maximal gradient detection. @@ -316,16 +306,6 @@ public: */ inline void switchScanRecentering () { recenteringOn = ! recenteringOn; } - /** - * \brief Returns true if the fine scan is fitted to the detected segment. - */ - inline bool isScanFitting () { return fittingOn; } - - /** - * \brief Switches on or off the scan fitting modality. - */ - inline void switchScanFitting () { fittingOn = ! fittingOn; } - /** * \brief Returns true if the multi-selection modality is set. */ @@ -493,23 +473,25 @@ public: /** * \brief Returns whether the density test at initial step is set. */ - inline bool isDensityTestOn () const { return (densityTestOn); } + inline bool isInitialSparsityTestOn () const { + return (initialSparsityTestOn); } /** - * \brief Switches on or off the density test modality. + * \brief Switches on or off the initial density test modality. */ - inline void switchDensityTest () { densityTestOn = ! densityTestOn; } + inline void switchInitialSparsityTest () { + initialSparsityTestOn = ! initialSparsityTestOn; } /** * \brief Returns whether the density test at final step is set. */ - inline bool isFinalDensityTestOn () const { return (finalDensityTestOn); } + inline bool isFinalSparsityTestOn () const { return (finalSparsityTestOn); } /** * \brief Switches on or off the final density test modality. */ - inline void switchFinalDensityTest () { - finalDensityTestOn = ! finalDensityTestOn; } + inline void switchFinalSparsityTest () { + finalSparsityTestOn = ! finalSparsityTestOn; } /** * \brief Returns whether the size test at final step is set. @@ -526,45 +508,36 @@ public: * \brief Returns the minimal size of final blurred segments. */ inline int finalSizeMinValue () const { - return (finalSizeTestOn ? finalSizeMinVal : 0); } + return (finalSizeTestOn ? finalMinSize : BS_MIN_SIZE); } /** * \brief Returns the minimal spread of final blurred segments. */ inline void setFinalSizeMinValue (int val) { - finalSizeMinVal = (val < 0 ? 0 : val); } - - /** - * \brief Returns whether the length test at final step is set. - */ - inline bool isFinalLengthTestOn () const { return (finalLengthTestOn); } - - /** - * \brief Switches on or off the final length test modality. - */ - inline void switchFinalLengthTest () { - finalLengthTestOn = ! finalLengthTestOn; } + finalMinSize = (val < BS_MIN_SIZE ? BS_MIN_SIZE : val); } /** * \brief Returns the connectivity constraint status. */ - inline bool isConnectivityConstraintOn () const { return (ccOn); } + inline bool isFinalFragmentationTestOn () const { + return (finalFragmentationTestOn); } /** * \brief Switches on or off the connectivity constraint. */ - inline void switchConnectivityConstraint () { ccOn = ! ccOn; } + inline void switchFinalFragmentationTest () { + finalFragmentationTestOn = ! finalFragmentationTestOn; } /** * \brief Returns the minimal size of the segment connected components. */ - inline int getConnectedComponentMinSize () { return ccMinSize; } + inline int fragmentSizeMinValue () const { return fragmentMinSize; } /** * \brief Increments the minimal size of the connected components. * @param increase Positive increment if true, negative otherwise. */ - bool incConnectedComponentMinSize (bool increase); + bool incFragmentSizeMinValue (bool increase); /* * \brief Returns the count of trials in a multi-detection. @@ -612,15 +585,15 @@ public: Pt2i &p1, Pt2i &p2, int &swidth, Pt2i &pc) const; /** - * \brief Retuns whether the static detector (IWCIA '09) is used. + * \brief Retuns whether static detections (without ADS and ATC) are used. */ - inline bool staticDetectorOn () { return staticDetOn; } + inline bool staticDetectorOn () const { return staticDetOn; } /** - * \brief Sets the static detector activation (IWCIA '09). + * \brief Sets the static detection (without ADS and ATC) activation. * @param status Activation status. */ - inline void setStaticDetector (bool status) { staticDetOn = status; } + void setStaticDetector (bool status); /** * \brief Returns the version number. @@ -634,16 +607,16 @@ private : static const int DEFAULT_FAST_TRACK_SCAN_WIDTH; /** Default value for the assigned thickess to detection method. */ static const int DEFAULT_ASSIGNED_THICKNESS; - /** Default value for the max segment width margin for fast tracks. */ - static const int DEFAULT_FAST_TRACK_MAX_MARGIN; - /** Default value for the minimal size of the detected blurred segment. */ - static const int DEFAULT_BS_MIN_SIZE; - /** Absolute value for the minimal size of the detected blurred segment. */ - static const int ABSOLUTE_BS_MIN_SIZE; + /** Additional assigned thickness margin for fast tracks. */ + static const int FAST_TRACK_MARGIN; + /** Default minimal size of the initial blurred segment. */ + static const int DEFAULT_INITIAL_MIN_SIZE; + /** Minimal size of a blurred segment. */ + static const int BS_MIN_SIZE; /** Default minimal size of the final blurred segment. */ static const int DEFAULT_FINAL_MIN_SIZE; - /** Default value for the minimal size of connected components. */ - static const int DEFAULT_CONNECT_MIN_SIZE; + /** Default value for the minimal size of segment fragments. */ + static const int DEFAULT_FRAGMENT_MIN_SIZE; /** Default value of the stroke sweeping step for automatic detections. */ static const int DEFAULT_AUTO_SWEEPING_STEP; /** Default value for the preliminary stroke half length. */ @@ -659,26 +632,22 @@ private : * 0 : no direction condition (detects lines as well as edges) */ int edgeDirection; - /** Minimal size of the detected blurred segment. */ - int bsMinSize; - /** Connectivity constraint status. */ - bool ccOn; - /** Minimal size of the connected components to validate a blurred segment. */ - int ccMinSize; + /** Minimal size of the initial segment. */ + int initialMinSize; + /** Final fragmentation test status. */ + bool finalFragmentationTestOn; + /** Minimal size of the segment fragments. */ + int fragmentMinSize; /** Automatic scan recentering (based on previous detection). */ bool recenteringOn; - /** Automatic scan width selection (based on previous detection). */ - bool fittingOn; - /** Density test modality after initial detection. */ - bool densityTestOn; - /** Density test modality after final detection. */ - bool finalDensityTestOn; - /** Length test modality after final detection. */ - bool finalLengthTestOn; + /** Sparsity test modality after initial detection. */ + bool initialSparsityTestOn; + /** Sparsity test modality after final detection. */ + bool finalSparsityTestOn; /** Size test modality after final detection. */ bool finalSizeTestOn; - /** Size test minimal value. */ - int finalSizeMinVal; + /** Minimal size of the final segment. */ + int finalMinSize; /** Count of small BS eliminated by the spread test. */ int nbSmallBS; /** Segment multi-selection modality status. */ @@ -698,8 +667,6 @@ private : /** Assigned maximal thickness to the detector. */ int inThick; - /** Assigned maximal width margin for fast tracks. */ - int imaxMargin; /** Last input start point. */ Pt2i prep1; @@ -731,8 +698,8 @@ private : /** Fine tracker. */ BSTracker *bst2; - /** Old detector (IWCIA'09) fine tracker. */ - BSTracker *bstold; + /** Fine tracker for static detections (without ADS and ATC). */ + BSTracker *bstStatic; /** Detected blurred segment (final result). */ BlurredSegment *bsf; /** Detected blurred segments in case of multi-detection (final results). */ diff --git a/Code/FBSD/FBSD.pro b/Code/FBSD/FBSD.pro index d4a2c206cd58ff415254504ff98c3d8dd246a4cd..38325a9670507fda824e5283e0b9631b148aa1e3 100644 --- a/Code/FBSD/FBSD.pro +++ b/Code/FBSD/FBSD.pro @@ -20,9 +20,9 @@ HEADERS += BlurredSegment/biptlist.h \ BlurredSegment/bsdetector.h \ BlurredSegment/bsfilter.h \ BlurredSegment/bstracker.h \ - BSTools/bscannyitem.h \ - BSTools/bscannyview.h \ BSTools/bsdetectionwidget.h \ + BSTools/bsgroundtruthitem.h \ + BSTools/bsgroundtruthview.h \ BSTools/bsidetitem.h \ BSTools/bsidetview.h \ BSTools/bsprofileitem.h \ @@ -31,8 +31,6 @@ HEADERS += BlurredSegment/biptlist.h \ BSTools/bsstructureitem.h \ BSTools/bsstructureview.h \ BSTools/bswindow.h \ - BSTools/bsyorkitem.h \ - BSTools/bsyorkview.h \ BSTools/extlines.h \ ConvexHull/antipodal.h \ ConvexHull/chvertex.h \ @@ -65,9 +63,9 @@ SOURCES += main.cpp \ BlurredSegment/bsdetector.cpp \ BlurredSegment/bsfilter.cpp \ BlurredSegment/bstracker.cpp \ - BSTools/bscannyitem.cpp \ - BSTools/bscannyview.cpp \ BSTools/bsdetectionwidget.cpp \ + BSTools/bsgroundtruthitem.cpp \ + BSTools/bsgroundtruthview.cpp \ BSTools/bsidetitem.cpp \ BSTools/bsidetview.cpp \ BSTools/bsprofileitem.cpp \ @@ -76,8 +74,6 @@ SOURCES += main.cpp \ BSTools/bsstructureitem.cpp \ BSTools/bsstructureview.cpp \ BSTools/bswindow.cpp \ - BSTools/bsyorkitem.cpp \ - BSTools/bsyorkview.cpp \ BSTools/extlines.cpp \ ConvexHull/antipodal.cpp \ ConvexHull/chvertex.cpp \ diff --git a/Code/FBSD/main.cpp b/Code/FBSD/main.cpp index 5ac3ebe08e734974417e44384cf7f248949e5fcd..0d98a824c2bc6f8c139bfe5976c3d1c51368b696 100755 --- a/Code/FBSD/main.cpp +++ b/Code/FBSD/main.cpp @@ -1,6 +1,6 @@ #include <QApplication> #include <string> -#include <cmath> // DEV +#include <cmath> #include "bswindow.h" #include "bsrandomtester.h" // #include "scanwindow.h" // DEV @@ -11,8 +11,8 @@ int main (int argc, char *argv[]) int val = 0; int imageName = 0; bool random = false, testing = false; - bool yt = false; // DEV - bool out = false; // DEV + bool xt = false, yt = false; // DEV + bool out = false; QApplication app (argc, argv); // DEV IN @@ -37,15 +37,20 @@ int main (int argc, char *argv[]) // DEV IN else if (string(argv[i]) == string ("-own")) { - new ExtLines (false); + new ExtLines (false, true); return (EXIT_SUCCESS); } else if (string(argv[i]) == string ("-york")) { - new ExtLines (true); + new ExtLines (true, true); return (EXIT_SUCCESS); } - else if (string(argv[i]) == string ("-out")) out = true; + else if (string(argv[i]) == string ("-altyork")) + { + new ExtLines (true, false); + return (EXIT_SUCCESS); + } + else if (string(argv[i]) == string ("-xt")) { xt = true; yt = true; } else if (string(argv[i]) == string ("-yt")) yt = true; else if (string(argv[i]) == string ("-profile")) window.toggleProfWindow (); @@ -57,6 +62,8 @@ int main (int argc, char *argv[]) window.toggleIdetWindow (); // Test command : time ./Seg -test ../Images/couloir.jpg // DEV OUT + else if (string(argv[i]) == string ("-out")) out = true; + else if (string(argv[i]) == string ("-oud")) { out = true; xt = true; } else if (string(argv[i]) == string ("-sobel3x3")) window.useGradient (VMap::TYPE_SOBEL_3X3); else if (string(argv[i]) == string ("-sobel5x5")) @@ -97,7 +104,6 @@ int main (int argc, char *argv[]) delete tester; return (EXIT_SUCCESS); } -// DEV IN else if (out) { QImage im; @@ -116,6 +122,7 @@ int main (int argc, char *argv[]) } } BSDetector detector; + if (xt) detector.setStaticDetector (true); AbsRat x1, y1, x2, y2; VMap *gMap = NULL; if (gMap != NULL) delete gMap; @@ -147,6 +154,7 @@ int main (int argc, char *argv[]) outf.close (); return (EXIT_SUCCESS); } +// DEV IN else if (yt) { int repetitions = 100; @@ -167,6 +175,7 @@ int main (int argc, char *argv[]) } } BSDetector detector; + if (xt) detector.setStaticDetector (true); clock_t start = clock (); VMap *gMap = NULL; for (int i = 0; i < repetitions; i++) diff --git a/Methode/ctrl.tex b/Methode/ctrl.tex index eee263d03b6592a624eed6c6502ae107f5a07ae4..aafa0e508f8c41980c78037741c09eb373a757ad 100755 --- a/Methode/ctrl.tex +++ b/Methode/ctrl.tex @@ -28,7 +28,7 @@ b && Ajuste la r\'esolution du gradient pour le filtrage des max locaux \\ e && Inverse la direction de r\'ef\'erence (autre bord) \\ g && Ajuste le seuil du gradient \\ j && Ajuste le seuil de voisinage pour les suivis rapides \\ -k && Ajuste la taille minimale des composantes connexes \\ +k && Ajuste la taille minimale des fragments \\ l && Ajuste la taille minimale du segment final \\ m && D\'etection exhaustive de tous les segments \\ n && Allume le segment suivant dans une d\'etection multiple \\ @@ -38,17 +38,16 @@ r && Ajuste la r\'esolution de la grille de d\'etection automatique \\ s && Ajuste la taille minimale des segments flous d\'etect\'es \\ t && Ajuste la longueur tol\'er\'ee pour les sauts de d\'etection \\ u && Relance la d\'etection sur la derni\`ere s\'election (update) \\ -w && Ajuste la consigne d'\'epaisseur du segment flou pour le suivi fin \\ x && Ajuste la marge de consigne d'\'epaisseur du segment flou pour le suivi rapide \\ y && Ajuste le contraste de l'image \\ -z && Ajuste le seuil du contr\^ole de la consigne d'\'epaisseur \\ +z && Ajuste le d\'elai de d\'eclenchement du contr\^ole de la consigne d'\'epaisseur \\ Ctrl-b && Commute le fond d'\'ecran de la fen\^etre principale \\ Ctrl-d && Commute le test de densit\'e \\ Ctrl-e && Commute la prise en compte de la direction du bord (trait / contour) \\ Ctrl-f && Commute le pr\'e-filtrage (segment initial) \\ Ctrl-h && Commute le filtrage du segment final \\ Ctrl-j && Commute la contrainte de voisinage pour les suivis rapides \\ -Ctrl-k && Commute la contrainte de konnectivit\'e \\ +Ctrl-k && Commute le test de fragmentation \\ Ctrl-m && Commute la d\'etection multiple \\ Ctrl-n && Commute la limitation de l'extension de la d\'etection initiale \\ Ctrl-o && Commute la directionnalit\'e des scans \\ @@ -60,7 +59,7 @@ Ctrl-t && Commute la gestion des reprises sur interruption (1 / longueur absence Ctrl-u && Commute l'affichage des bords des segments flous. \\ Ctrl-v && Commute l'affichage du r\'esultat de la d\'etection en console (verbose) \\ Ctrl-w && Commute le recentrage du scan sur le segment d\'etect\'e \\ -Ctrl-x && Commute l'ajustement de la consigne d'\'epaisseur sur le segment d\'etect\'e \\ +Ctrl-x && Commute l'ancien (sans ADS et ATC) et le nouveau d\'etecteur \\ Ctrl-y && Commute l'affichage des pixels des segments flous \\ Ctrl-z && Commute le contr\^ole de la consigne d'\'epaisseur \\ Ctrl-! && Commute la couleur de s\'election des segments flous \\ @@ -71,11 +70,9 @@ $\wedge$v && D\'ecale verticalement l'affichage sur une grosse image \\ 2 && Commute la visu de l'accumulateur \\ 3 && Commute la visu des profils \\ 4 && Commute la visu de la d\'etection initiale \\ -6 && Commute l'ancien et le nouveau d\'etecteur \\ -0 && Teste avec la derni\`ere barre enregistr\'ee (test.txt) \\ -9 && Teste la performance sur la derni\`ere barre trac\'ee \\ -8 && Teste comparativement sur diff\'erents contextes de d\'etection \\ 7 && Enregistre la barre initiale dans test.txt \\ +9 && Teste la performance sur la derni\`ere barre trac\'ee \\ +0 && Teste avec la derni\`ere barre enregistr\'ee (test.txt) \\ LeftMouse && Contr\^ole la barre de s\'election pour la d\'etection \\ RightMouse && S\'electionne l'une des lignes d\'etect\'ees \\ \hline diff --git a/Methode/evals.tex b/Methode/evals.tex index d7e1602d9ab1ea1e7691fae7c6239e87d70a98ef..73ea3f931c8b14c78c972119f0428a1e078aac8a 100755 --- a/Methode/evals.tex +++ b/Methode/evals.tex @@ -158,7 +158,12 @@ Une fois qu'on a compl\'et\'e et rang\'e les 4 fichiers {\tt data/<det>times.txt}, le programme {\tt Scripts/moyennes/mtimes} calcule et affiche une valeur moyenne et un \'ecart-type pour chacun des 4 d\'etecteurs. -Attention, il faut les dur\'ees pour les 102 images. +Attention, il faut les dur\'ees pour les 102 images. \\ + +Pour les comparaisons avec et sans les scans directionnels adaptatifs +et le contr\^ole de la consigne d'\'epaisseur, le principe est le m\^eme. +Juste remplacer {\tt yorktimes} par {\tt xorktimes} et {\tt mtimes} +par {\tt oldtimes}. \subsection{Comparaisons des lignes en nombre et longueur} @@ -168,7 +173,7 @@ Elles sont dans les r\'epertoires {\tt lines/<det>lines/output}. \\ Le script {\tt Scripts/appli.sh createnaive} lance l'extraction des lignes pour toutes les images par FBSD (commande {\tt FBSD -out <image>}). Les lignes sont rang\'ees dans le r\'epertoire -{\tt lines/cannylines/output} (qui doit \^etre pr\'ealablement cr\'e\'e, +{\tt lines/naivelines/output} (qui doit \^etre pr\'ealablement cr\'e\'e, dans des fichier {\tt <image>.txt}. Attention, les anciens fichiers sont \'ecras\'es : pr\'evoir de recopier le r\'epertoire ailleurs avant de lancer cette commande. \\ @@ -180,7 +185,12 @@ Le programme ouvre tous les fichiers {\tt lines/<det>lines/output/<image>.txt}. Les lignes de longueur inf\'erieure \`a {\tt MIN\_LENGTH = 10} ne sont pas prises en compte. -Le r\'esultat est plac\'e dans un fichier {\tt data/meanlength.txt}. +Le r\'esultat est plac\'e dans un fichier {\tt data/meanlength.txt}. \\ + +Pour les comparaisons avec et sans les scans directionnels adaptatifs +et le contr\^ole de la consigne d'\'epaisseur, le principe est le m\^eme. +Juste remplacer {\tt createnaives} par {\tt createold}, {\tt naivelines} +par {\tt oldlines} et {\tt meanlength} par {\tt oldlength}. \subsection{Comparaisons avec les v\'erit\'es de terrain} @@ -208,6 +218,15 @@ La moyenne sur ces mesures peut ensuite \^etre obtenue par les scripts {\tt data/moyennes/mcov} et {\tt data/moyennes/mlines}, ce dernier \'etant redondant avec une obtention via {\tt meanlength}. \\ +Pour les comparaisons avec et sans les scans directionnels adaptatifs +et le contr\^ole de la consigne d'\'epaisseur, le principe est le m\^eme. +Juste remplacer {\tt compalines} par {\tt compaversions}, +{\tt FBSD york} par {\tt FBSD altyork}, {\tt mcov} par {\tt maltcov} et +{\tt mlines} par {\tt maltlines}. Dans ce cas, des fichiers +suppl\'ementaires {\tt <vers>th.txt} con\-tien\-nent l'\'epaisseur lin\'eaire +cumul\'ee et l'\'epaisseur moyenne, et les moyennes sont obtenues par +la commande {\tt data/moyennes/maltth}. \\ + {\bf Ecarts angulaires} \\ Commencer par d\'etruire les fichiers {\tt data/<det>ang.txt}. \\ {\tt > source appli.sh compepais}. \\