From 5277bda7f62bbb8dbbb79ab8b3cc29af4aeee2f4 Mon Sep 17 00:00:00 2001 From: even <philippe.even@loria.fr> Date: Fri, 16 Nov 2018 14:45:19 +0100 Subject: [PATCH] Width handling --- Code/Seg/BSTools/bsdetectionwidget.cpp | 32 +++++++++++------ Code/Seg/BlurredSegment/bsdetector.cpp | 36 +++++++++---------- Code/Seg/BlurredSegment/bsdetector.h | 24 +++++++++---- Code/Seg/BlurredSegment/bstracker.cpp | 8 +++-- Code/Seg/BlurredSegment/bstracker.h | 4 +-- Code/Seg/DirectionalScanner/scannerprovider.h | 2 +- Methode/ctrl.tex | 4 ++- Methode/methode.tex | 7 ++++ 8 files changed, 75 insertions(+), 42 deletions(-) diff --git a/Code/Seg/BSTools/bsdetectionwidget.cpp b/Code/Seg/BSTools/bsdetectionwidget.cpp index 2ee6df3..246fafa 100755 --- a/Code/Seg/BSTools/bsdetectionwidget.cpp +++ b/Code/Seg/BSTools/bsdetectionwidget.cpp @@ -292,9 +292,9 @@ void BSDetectionWidget::keyPressEvent (QKeyEvent *event) case Qt::Key_W : // Fast tracks max width if (event->modifiers () & Qt::ControlModifier) { - detector.switchAutoWidth (); - cout << "Final step max width " << (detector.autoWidthOn () ? - "fitted to initial segment" : "left unchanged") << endl; + detector.switchScanRecentering (); + cout << "Fine tracking centered on " << (detector.isScanRecentering () ? + "detected segment" : "initial scan") << endl; extract (); } else @@ -307,6 +307,24 @@ void BSDetectionWidget::keyPressEvent (QKeyEvent *event) } break; + case Qt::Key_X : + if (event->modifiers () & Qt::ControlModifier) + { + detector.switchScanFitting (); + cout << "Fine tracking fitted to " << (detector.isScanFitting () ? + "detected segment width" : "assigned width") << endl; + extract (); + } + else + { + detector.setFastTracksMaxWidth (detector.fastTracksMaxWidth () + + (event->modifiers () & Qt::ShiftModifier ? -1 : 1)); + extract (); + cout << "Fast tracks max width = " + << detector.fastTracksMaxWidth () << endl; + } + break; + case Qt::Key_K : // Output blurred segment min size detector.setBSminSize (detector.getBSminSize () + (event->modifiers () & Qt::ShiftModifier ? -1 : 1)); @@ -343,14 +361,6 @@ void BSDetectionWidget::keyPressEvent (QKeyEvent *event) << (detector.isThinningActivated () ? "on" : "off") << endl; break; - case Qt::Key_X : - detector.setFastTracksMaxWidth (detector.fastTracksMaxWidth () + - (event->modifiers () & Qt::ShiftModifier ? -1 : 1)); - extract (); - cout << "Fast tracks max width = " - << detector.fastTracksMaxWidth () << endl; - break; - case Qt::Key_S : detector.switchDynamicScans (); cout << (detector.dynamicScansOn () ? diff --git a/Code/Seg/BlurredSegment/bsdetector.cpp b/Code/Seg/BlurredSegment/bsdetector.cpp index c047401..85ffdd2 100755 --- a/Code/Seg/BlurredSegment/bsdetector.cpp +++ b/Code/Seg/BlurredSegment/bsdetector.cpp @@ -38,7 +38,8 @@ BSDetector::BSDetector () edgeDirection = 0; // detects line (not only edges) bsMinSize = DEFAULT_BS_MIN_SIZE; connectMinSize = DEFAULT_CONNECT_MIN_SIZE; - autowidth = true; + recenteringOn = true; + fittingOn = false; ccOn = true; densityTestOn = true; multiSelection = false; @@ -234,30 +235,29 @@ void BSDetector::detect (const Pt2i &p1, const Pt2i &p2, Pt2i *p0) return; } - // Finer detection based on gradient maxima with orientation constraint - //--------------------------------------------------------------------- + // Gradient reference selection + //----------------------------- Pt2i pCenter = bsini->getCenter (); - Vr2i gRef = gMap->getValue (pCenter.x (), pCenter.y ()); + Vr2i gRef = gMap->getValue (pCenter); if (edgeDirection == -1) gRef.invert (); - int bswidth = bst1->fastTracksMaxWidth (); - int scanwidth2 = 4 * bswidth; - if (autowidth) + + // Scan recentering and fitting + //----------------------------- + if (recenteringOn) + pCenter = bsini->getSegment()->centerOfIntersection (pt1, pt2); + int bswidth = bst1->fineTracksMaxWidth (); + if (fittingOn) { - bswidth = bst1->fineTracksMaxWidth (); -/* DigitalStraightSegment *dss = bsini->getSegment (); if (dss != NULL) - { - bswidth = (dss->width () / dss->period ()); - if (bswidth < bst1->fineTracksMaxWidth ()) - bswidth = bst1->fineTracksMaxWidth (); - } -*/ - scanwidth2 = bswidth; - pCenter = bsini->getSegment()->centerOfIntersection (pt1, pt2); + bswidth = 1 + dss->width () / dss->period (); } + int scanwidth = bswidth + bswidth / 2; + + // Finer detection based on gradient maxima with orientation constraint + //--------------------------------------------------------------------- bsf = bst2->fineTrack (pCenter, bsini->getSupportVector(), - scanwidth2, bswidth, gRef); + scanwidth, bswidth, gRef); if (bsf == NULL || bsf->size () < bsMinSize) { diff --git a/Code/Seg/BlurredSegment/bsdetector.h b/Code/Seg/BlurredSegment/bsdetector.h index f7897f4..f714849 100755 --- a/Code/Seg/BlurredSegment/bsdetector.h +++ b/Code/Seg/BlurredSegment/bsdetector.h @@ -222,14 +222,24 @@ public: } /** - * \brief Returns true if the automatic width selection is set. + * \brief Returns true if the fine scan is recentred on the detected segment. */ - inline bool autoWidthOn () { return autowidth; } + inline bool isScanRecentering () { return recenteringOn; } /** - * \brief Switches on or off the automatic width selection. + * \brief Switches on or off the scan recentering modality. */ - inline void switchAutoWidth () { autowidth = ! autowidth; } + 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. @@ -433,8 +443,10 @@ private : int bsMinSize; /** Minimal size of the connected components to validate a blurred segment. */ int connectMinSize; - /** Automatic width selection (based on previous detection). */ - bool autowidth; + /** 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; /** Segment multi-selection modality status. */ diff --git a/Code/Seg/BlurredSegment/bstracker.cpp b/Code/Seg/BlurredSegment/bstracker.cpp index 72831a5..676204e 100755 --- a/Code/Seg/BlurredSegment/bstracker.cpp +++ b/Code/Seg/BlurredSegment/bstracker.cpp @@ -196,9 +196,12 @@ BlurredSegment *BSTracker::fastTrack (const Pt2i &p1, const Pt2i &p2, BlurredSegment *BSTracker::fineTrack (const Pt2i ¢er, const Vr2i &scandir, - int scanwidth2, int bswidth, + int scanwidth, int bswidth, const Vr2i &gref) { + // Checks scan width minimal size + if (scanwidth < MIN_SCAN) scanwidth = MIN_SCAN; + // Gets detected segment normal vector Vr2i normal = scandir.orthog (); if (! normal.orientedAs (gref)) normal.invert (); @@ -207,7 +210,7 @@ BlurredSegment *BSTracker::fineTrack (const Pt2i ¢er, const Vr2i &scandir, // Creation of the directional scanner and the array of candidates DirectionalScanner *ds = scanp.getScanner ( - center, normal, scanwidth2, dynamicScans, + center, normal, scanwidth, dynamicScans, 0, 0, gMap->getWidth (), gMap->getHeight ()); if (ds == NULL) { @@ -403,7 +406,6 @@ void BSTracker::switchOrthoScans () { orthoScan = ! orthoScan; scanp.setOrtho (orthoScan); - cout << "OrthoScan is " << (orthoScan ? "on" : "off") << endl; } diff --git a/Code/Seg/BlurredSegment/bstracker.h b/Code/Seg/BlurredSegment/bstracker.h index 1816d8b..ff8893c 100755 --- a/Code/Seg/BlurredSegment/bstracker.h +++ b/Code/Seg/BlurredSegment/bstracker.h @@ -48,12 +48,12 @@ public: * Finer detection using gradient ridges and direction input. * @param center Central point of the scan. * @param scandir Scan direction - * @param scanwidth2 Half width of the scan strip. + * @param scanwidth Width of the scan strip. * @param bswidth Initial maximal width of the blurred segment to build. * @param gref Gradient vector reference to select candidates. */ BlurredSegment *fineTrack (const Pt2i ¢er, const Vr2i &scandir, - int scanwidth2, int bswidth, + int scanwidth, int bswidth, const Vr2i &gref); /** diff --git a/Code/Seg/DirectionalScanner/scannerprovider.h b/Code/Seg/DirectionalScanner/scannerprovider.h index 3dd5be3..1b0eac7 100755 --- a/Code/Seg/DirectionalScanner/scannerprovider.h +++ b/Code/Seg/DirectionalScanner/scannerprovider.h @@ -90,7 +90,7 @@ public: * of (p1,p2) and aligned on (v1,v2). * @param centre central point * @param normal scan strip normal vector - * @param length half length of a scan line + * @param length length of a scan line * @param controlable controlability request (true for a dynamical scanner) * @param xmin left border of the scan area * @param xmax right border of the scan area diff --git a/Methode/ctrl.tex b/Methode/ctrl.tex index 4993910..6a0721f 100755 --- a/Methode/ctrl.tex +++ b/Methode/ctrl.tex @@ -49,7 +49,9 @@ f && Commute le filtrage final \\ g && Commute la contrainte de connectivit\'e \\ s && Commute l'aspect dynamique des scans \\ o && Commute l'aspect directionel des scans \\ -Ctrl-w && Commute l'ajustement de la consigne d'\'epaisseur \\ +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 \\ P && Capture la fen\^etre principale \\ 1 && Commute la visu des segments (pixels) \\ 2 && Commute la visu de l'accumulateur \\ diff --git a/Methode/methode.tex b/Methode/methode.tex index 0dbb5b0..6fc8e93 100755 --- a/Methode/methode.tex +++ b/Methode/methode.tex @@ -63,6 +63,7 @@ sur sur le segment d\'etect\'e. \begin{itemize} \item Balayage directionnel statique pour cr\'eer et \'etendre un segment flou \`a partir du gradient maximal trouv\'e dans la barre. +\item Consigne d'\'epaisseur : par d\'efaut 5 pixels, ajustable. \item En phase d'extension, on applique un test de voisinage par rapport au dernier pixel ins\'er\'e (4 pixels). \item Aucun test angulaire. @@ -87,6 +88,12 @@ dernier pixel ins\'er\'e (4 pixels). \begin{itemize} \item Balayage directionnel statique pour cr\'eer et \'etendre un segment flou \`a partir du gradient maximal trouv\'e dans la barre. +\item Consigne d'\'epaisseur : si la modalit\'e {\tt scanFitting} est +active, elle est cal\'ee sur l'\'epaisseur du segment d\'etect\'e \`a +l'\'etape pr\'ec\'edente. Sinon, par d\'efaut 8 pixels, ajustable. +\item Centrage : si la modalit\'e {\tt scanRecentering} est active, le +balayage est centr\'e sur le segment d\'etect\'e \`a l'\'etape pr\'ec\'edente. +Sinon, il est centr\'e sur la barre utilisateur ($P_1P_2$). \item En phase d'extension, on applique un test de voisinage par rapport au dernier pixel ins\'er\'e (4 pixels). \item Aucun test angulaire. -- GitLab