Skip to content
Snippets Groups Projects
Commit 7146f1e6 authored by even's avatar even
Browse files

Adjustable gradient threshold

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