diff --git a/Code/Seg/BSTools/bsdetectionwidget.cpp b/Code/Seg/BSTools/bsdetectionwidget.cpp index f3a4314ced71ba4ea14b18dbe5a78a04332a8747..7f770c736cc591c5fecb7540be5552fa629b8cb6 100755 --- a/Code/Seg/BSTools/bsdetectionwidget.cpp +++ b/Code/Seg/BSTools/bsdetectionwidget.cpp @@ -27,6 +27,7 @@ BSDetectionWidget::BSDetectionWidget (QWidget *parent) setFocus (); grabKeyboard (); udef = false; + nodrag = true; // Sets initial values for the gradient map gMap = NULL; @@ -302,7 +303,9 @@ void BSDetectionWidget::mouseMoveEvent (QMouseEvent *event) && (width > p2.x() && height > p2.y() && p2.x() > 0 && p2.y() > 0)) { - extract (false); + nodrag = false; + extract (); + nodrag = true; } } @@ -322,7 +325,7 @@ void BSDetectionWidget::keyPressEvent (QKeyEvent *event) // Toggles background image toggleBackground (); if (p1.equals (p2)) displayBackground (); - else displayDetectionResult (true); + else displayDetectionResult (); } break; @@ -378,9 +381,9 @@ void BSDetectionWidget::keyPressEvent (QKeyEvent *event) // Tunes the gradient threshold for maximal value detection detector.incGradientThreshold ( (event->modifiers () & Qt::ShiftModifier ? -1 : 1)); - extract (); cout << "Gradient threshold = " << detector.getGradientThreshold () << endl; + extract (); break; case Qt::Key_H : @@ -426,7 +429,9 @@ void BSDetectionWidget::keyPressEvent (QKeyEvent *event) else { // Runs an automatic detection - extractAll (); + udef = false; + exam = -1; + extract (); } break; @@ -763,7 +768,7 @@ void BSDetectionWidget::writeDetectionResult () } -void BSDetectionWidget::displayDetectionResult (bool aux, int hnum) +void BSDetectionWidget::displayDetectionResult (int hnum) { if (background == BACK_BLACK) augmentedImage.fill (qRgb (0, 0, 0)); else if (background == BACK_WHITE) augmentedImage.fill (qRgb (255, 255, 255)); @@ -784,7 +789,7 @@ void BSDetectionWidget::displayDetectionResult (bool aux, int hnum) update (QRect (QPoint (0, 0), QPoint (width, height))); // Update auxiliary view if not dragging - if (aux) + if (nodrag) { if (idetview != NULL) { @@ -814,7 +819,7 @@ void BSDetectionWidget::displayNext (int dir) { exam = (exam + dir) % size; if (strucview != NULL) strucview->setExamined (exam); - displayDetectionResult (true, exam); + displayDetectionResult (exam); } } @@ -915,33 +920,25 @@ void BSDetectionWidget::writeDetectionStatus () } -void BSDetectionWidget::extract (bool updateAll) +void BSDetectionWidget::extract () { - exam = -1; - if (p1.equals (p2)) + if (! udef) { - displayBackground (); - return; + detector.detectAll (); + cout << detector.getBlurredSegments().size () + << " blurred segments detected" << endl; } - - detector.detectSelection (p1, p2); - displayDetectionResult (updateAll); -} - - -void BSDetectionWidget::extractAll () -{ - udef = false; - exam = -1; - bool formerMultiMode = detector.isMultiSelection (); - if (! formerMultiMode) detector.switchMultiSelection (); - - detector.detectAll (); - vector<BlurredSegment *> mbs = detector.getBlurredSegments (); - cout << mbs.size () << " blurred segments detected" << endl; - displayDetectionResult (true); - - if (! formerMultiMode) detector.switchMultiSelection (); + else + { + exam = -1; + if (p1.equals (p2)) + { + displayBackground (); + return; + } + detector.detectSelection (p1, p2); + } + displayDetectionResult (); } diff --git a/Code/Seg/BSTools/bsdetectionwidget.h b/Code/Seg/BSTools/bsdetectionwidget.h index fd3d10d071c6d42bddbd8886d3a3e0a972a31554..0618b9cb43e381c92c32dcba035eccd0017cdd75 100755 --- a/Code/Seg/BSTools/bsdetectionwidget.h +++ b/Code/Seg/BSTools/bsdetectionwidget.h @@ -189,6 +189,8 @@ private: /** Initial scan end points */ Pt2i p1, p2; + /** Flag indicating if the mouse is not dragging. */ + bool nodrag; /** Flag indicating if the detection is user defined. */ bool udef; /** Index of the examined blurred segment in a multi-selection. */ @@ -310,10 +312,9 @@ private: /** * \brief Displays the result of a detection. - * @param aux Indicates if auxiliary views should be displayed. * @param hnum Highlighted segment index (-1 if none). */ - void displayDetectionResult (bool aux, int hnum = -1); + void displayDetectionResult (int hnum = -1); /** * \brief Highlights the next blurred segment in multi-selection mode. @@ -343,14 +344,8 @@ private: /** * \brief Detects and displays a blurred segment under the selected stroke. - * @param updateAll Indicates if the extraction result should be displayed. */ - void extract (bool updateAll = true); - - /** - * \brief Detects and displays all the blurred segment in the picture. - */ - void extractAll (); + void extract (); }; #endif diff --git a/Code/Seg/ImageTools/vmap.cpp b/Code/Seg/ImageTools/vmap.cpp index c2597b78a27a09f9598c0ff01f4f6fd8a7011799..0796fb43b383379ec644dde55dd98a3b63d736ff 100755 --- a/Code/Seg/ImageTools/vmap.cpp +++ b/Code/Seg/ImageTools/vmap.cpp @@ -22,8 +22,10 @@ const int VMap::DEFAULT_GRADIENT_THRESHOLD = 30; VMap::VMap (int width, int height, int *data, int type) { gradientThreshold = DEFAULT_GRADIENT_THRESHOLD; + gmagThreshold = gradientThreshold; this->width = width; this->height = height; + this->gtype = type; imap = new int[width * height]; if (type == TYPE_TOP_HAT) { @@ -102,12 +104,14 @@ VMap::VMap (int width, int height, int *data, int type) buildSobel5x5Map (data); for (int i = 0; i < width * height; i++) imap[i] = (int) sqrt (map[i].norm2 ()); + gmagThreshold *= gradientThreshold; } else // type == TYPE_SOBEL_3X3 { buildGradientMap (data); for (int i = 0; i < width * height; i++) imap[i] = (int) sqrt (map[i].norm2 ()); + gmagThreshold *= gradientThreshold; } mask = new bool[width * height]; @@ -122,8 +126,10 @@ VMap::VMap (int width, int height, int *data, int type) VMap::VMap (int width, int height, int **data, int type) { gradientThreshold = DEFAULT_GRADIENT_THRESHOLD; + gmagThreshold = gradientThreshold; this->width = width; this->height = height; + this->gtype = type; imap = new int[width * height]; if (type == TYPE_TOP_HAT) { @@ -202,12 +208,14 @@ VMap::VMap (int width, int height, int **data, int type) buildSobel5x5Map (data); for (int i = 0; i < width * height; i++) imap[i] = (int) sqrt (map[i].norm2 ()); + gmagThreshold *= gradientThreshold; } else // type == TYPE_SOBEL_3X3 { buildGradientMap (data); for (int i = 0; i < width * height; i++) imap[i] = (int) sqrt (map[i].norm2 ()); + gmagThreshold *= gradientThreshold; } mask = new bool[width * height]; @@ -443,7 +451,7 @@ int VMap::largestIn (const vector<Pt2i> &pix) const int imax = -1; vector<Pt2i>::const_iterator pt = pix.begin (); int gmax = imap[pt->y() * width + pt->x()]; - if (gmax < gradientThreshold) gmax = gradientThreshold; + if (gmax < gmagThreshold) gmax = gmagThreshold; int i = 0; while (pt != pix.end ()) diff --git a/Code/Seg/ImageTools/vmap.h b/Code/Seg/ImageTools/vmap.h index d7c277bdc6ab5b205a9b600bbf2ffde38d806380..ed6d09dd51e61c1e8c02c0c8ca1f75cbaaaa5cfd 100755 --- a/Code/Seg/ImageTools/vmap.h +++ b/Code/Seg/ImageTools/vmap.h @@ -200,6 +200,8 @@ public: gradientThreshold += inc; if (gradientThreshold < 0) gradientThreshold = 0; if (gradientThreshold > 255) gradientThreshold = 255; + gmagThreshold = gradientThreshold; + if (gtype <= TYPE_SOBEL_5X5) gmagThreshold *= gradientThreshold; } /** @@ -258,6 +260,8 @@ private: int width; /** Image height. */ int height; + /** Gradient type. */ + int gtype; /** Vector map. */ Vr2i *map; /** Magnitude map (squarred norm or morphologicalgradient). */ @@ -267,8 +271,10 @@ private: bool *mask; /** Flag indicating whether the occupancy mask is in use. */ bool masking; - /** Gradient threshold for highest value detection. */ + /** Standardized gradient threshold for highest value detection. */ int gradientThreshold; + /** Gradient magnitude threshold for highest value detection. */ + int gmagThreshold; /** Direction constraint for local gradient maxima. */ bool orientedGradient; /** Registred direction constraint for local gradient maxima. */