diff --git a/Code/Seg/BSTools/bsdetectionwidget.cpp b/Code/Seg/BSTools/bsdetectionwidget.cpp index 246fafa8a4490cbf9af5b11fcfe75569e40e849e..513df2ca5d2e5c82adc612c163e71b42d65aa6d3 100755 --- a/Code/Seg/BSTools/bsdetectionwidget.cpp +++ b/Code/Seg/BSTools/bsdetectionwidget.cpp @@ -1,5 +1,6 @@ #include <QtGui> #include <iostream> +#include <fstream> #include <cstdlib> #include <ctime> #include "bsdetectionwidget.h" @@ -383,7 +384,12 @@ void BSDetectionWidget::keyPressEvent (QKeyEvent *event) break; case Qt::Key_P : - if (event->modifiers () & Qt::ShiftModifier) + if (event->modifiers () & Qt::ControlModifier) + { + writeDetectionResult (); + cout << "Detection result output" << endl; + } + else if (event->modifiers () & Qt::ShiftModifier) { augmentedImage.save ("capture.png"); cout << "Main window shot in capture.png" << endl; @@ -566,6 +572,28 @@ void BSDetectionWidget::displayBackground () } +void BSDetectionWidget::writeDetectionResult () +{ + BlurredSegment *bs = detector.getBlurredSegment (1); + if (bs != NULL) + { + ofstream outf ("seg.txt", ios::out); + outf << "(" << bs->antipodalEdgeStart().x () + << ", " << bs->antipodalEdgeStart().y () + << ") (" << bs->antipodalEdgeEnd().x () + << ", " << bs->antipodalEdgeEnd().y () + << ") (" << bs->antipodalVertex().x () + << ", " << bs->antipodalVertex().y () + << ") (" << bs->getLastLeft().x () + << ", " << bs->getLastLeft().y () + << ") (" << bs->getLastRight().x () + << ", " << bs->getLastRight().y () + << ")" << endl; + outf.close (); + } +} + + void BSDetectionWidget::displayDetectionResult (bool aux, int hnum) { augmentedImage = loadedImage; @@ -599,7 +627,7 @@ void BSDetectionWidget::displayDetectionResult (bool aux, int hnum) strucview->setExamined (-1); strucview->scene()->update (); } - if (verbose) writeDetectionResult (); + if (verbose) writeDetectionStatus (); } } @@ -675,7 +703,7 @@ void BSDetectionWidget::clearSavedSegments () } -void BSDetectionWidget::writeDetectionResult () +void BSDetectionWidget::writeDetectionStatus () { int res = detector.result (); if (res == BSDetector::RESULT_UNDETERMINED) diff --git a/Code/Seg/BSTools/bsdetectionwidget.h b/Code/Seg/BSTools/bsdetectionwidget.h index c29d359601c56b5208b1caeb88d23a4da51eb6da..37f4ecd0a4182a2aca140e5a34530edbda7b7c18 100755 --- a/Code/Seg/BSTools/bsdetectionwidget.h +++ b/Code/Seg/BSTools/bsdetectionwidget.h @@ -263,6 +263,11 @@ private: */ void displayBackground (); + /** + * \brief Writes the result of the last detection in a file. + */ + void writeDetectionResult (); + /** * \brief Displays the result of a detection. * @param aux Indicates if auxiliary views should be displayed. @@ -292,9 +297,9 @@ private: void clearSavedSegments (); /** - * \brief Outputs the last detection result. + * \brief Outputs the last detection result status. */ - void writeDetectionResult (); + void writeDetectionStatus (); /** * \brief Detects and displays a blurred segment under the selected stroke. diff --git a/Code/Seg/BlurredSegment/blurredsegment.cpp b/Code/Seg/BlurredSegment/blurredsegment.cpp index 7dcc136d266d9a8bf825f83f55b91e3b9744c284..dd5717aadf9a5dff54043b4eadb1f761cf2b6338 100755 --- a/Code/Seg/BlurredSegment/blurredsegment.cpp +++ b/Code/Seg/BlurredSegment/blurredsegment.cpp @@ -8,10 +8,15 @@ BlurredSegment::BlurredSegment () } -BlurredSegment::BlurredSegment (BiPtList *ptlist, DigitalStraightSegment *seg) +BlurredSegment::BlurredSegment (BiPtList *ptlist, DigitalStraightSegment *seg, + const Pt2i &aps, const Pt2i &ape, + const Pt2i &apv) { plist = ptlist; dss = seg; + laps.set (aps); + lape.set (ape); + lapv.set (apv); } diff --git a/Code/Seg/BlurredSegment/blurredsegment.h b/Code/Seg/BlurredSegment/blurredsegment.h index ca2ce752b471e4b511382268ec7058823b71340e..495cd6a39596e161928f3638e48efdf31ab7c3a8 100755 --- a/Code/Seg/BlurredSegment/blurredsegment.h +++ b/Code/Seg/BlurredSegment/blurredsegment.h @@ -28,8 +28,12 @@ public: * Creates a blurred segment from a list of points. * @param ptlist List of points of the blurred segment to build. * @param seg Bounding digital straight segment. + * @param aps Start point of the antipodal edge. + * @param ape End point of the antipodal edge. + * @param apv Antipodal vertex. */ - BlurredSegment (BiPtList *ptlist, DigitalStraightSegment *seg); + BlurredSegment (BiPtList *ptlist, DigitalStraightSegment *seg, + const Pt2i &aps, const Pt2i &ape, const Pt2i &apv); /** * \brief Deletes the blurred segment. @@ -116,6 +120,21 @@ public: */ const Pt2i getLastLeft () const; + /** + * \brief Returns the start point of the last antipodal edge. + */ + inline const Pt2i antipodalEdgeStart () const { return laps; } + + /** + * \brief Returns the end point of the last antipodal edge. + */ + inline const Pt2i antipodalEdgeEnd () const { return lape; } + + /** + * \brief Returns the last antipodal vertex. + */ + inline const Pt2i antipodalVertex () const { return lapv; } + /** * \brief Returns the support vector of the blurred segment. */ @@ -167,5 +186,12 @@ protected: /** Bi-directional list of points. */ BiPtList *plist; + /** Start point of the last known antipodal edge. */ + Pt2i laps; + /** End point of the last known antipodal edge. */ + Pt2i lape; + /** Last known antipodal vertex. */ + Pt2i lapv; + }; #endif diff --git a/Code/Seg/BlurredSegment/blurredsegmentproto.cpp b/Code/Seg/BlurredSegment/blurredsegmentproto.cpp index 8903390d09307e869330944fa68eccdeb5ab474b..87824830c1d0ca2c80c8c837c8c6fc3399b7b765 100755 --- a/Code/Seg/BlurredSegment/blurredsegmentproto.cpp +++ b/Code/Seg/BlurredSegment/blurredsegmentproto.cpp @@ -271,7 +271,10 @@ BlurredSegment *BlurredSegmentProto::endOfBirth () DigitalStraightLine::DSL_THIN, xmin, ymin, xmax, ymax); } - BlurredSegment *bbs = new BlurredSegment (plist, seg); + Pt2i aps (-1, -1), ape (-1, -1), apv (-1, -1); + if (convexhull != NULL) + convexhull->antipodalEdgeAndVertex (aps, ape, apv); + BlurredSegment *bbs = new BlurredSegment (plist, seg, aps, ape, apv); plist = NULL; // NECESSARY TO AVOID CONTENTS CLEARANCE !!! return (bbs); } diff --git a/Code/Seg/ImageTools/pt2i.h b/Code/Seg/ImageTools/pt2i.h index a48b5b1d3bef9b3cbcab390b85c67e635eb514af..fefb8ca1f8183a98ca93490862e56afcd27d0fc0 100755 --- a/Code/Seg/ImageTools/pt2i.h +++ b/Code/Seg/ImageTools/pt2i.h @@ -87,7 +87,7 @@ public: } /** - * @fn void set (int x, int y) + * @fn void set (const Pt2i &p y) * \brief Sets the point coordinates. * @param point to recopy. */ diff --git a/Code/Seg/ImageTools/strucel.cpp b/Code/Seg/ImageTools/strucel.cpp index caade0b8f74bedd28f482e6ffffd913e17b41fb1..6e11051e98b30f8d128a95268a947e33acb53d95 100755 --- a/Code/Seg/ImageTools/strucel.cpp +++ b/Code/Seg/ImageTools/strucel.cpp @@ -1,10 +1,12 @@ -#include <iostream> +// #include <iostream> #include "strucel.h" using namespace std; const int Strucel::TYPE_PLUS_3X3 = 0; +const int Strucel::TYPE_HOR = 1; +const int Strucel::TYPE_VER = 2; Strucel::Strucel (int type) @@ -21,6 +23,26 @@ Strucel::Strucel (int type) pattern[3] = Vr2i (1, 0); pattern[4] = Vr2i (0, -1); } + else if (type == TYPE_HOR) + { + width = 3; + height = 1; + size = 3; + pattern = new Vr2i[3]; + pattern[0] = Vr2i (0, 0); + pattern[1] = Vr2i (0, 1); + pattern[2] = Vr2i (0, -1); + } + else if (type == TYPE_VER) + { + width = 1; + height = 3; + size = 3; + pattern = new Vr2i[3]; + pattern[0] = Vr2i (0, 0); + pattern[1] = Vr2i (1, 0); + pattern[2] = Vr2i (-1, 0); + } else { width = 1; @@ -40,7 +62,7 @@ Strucel::~Strucel () void Strucel::tophatGradient (int *out, int **in, int width, int height) { -cout << "TH IN" << endl; +// cout << "TH IN" << endl; for (int j = 0; j < height; j++) for (int i = 0; i < width; i++) { @@ -54,7 +76,7 @@ cout << "TH IN" << endl; } out[j * width + i] = in[j][i] - min; } -cout << "TH OUT" << endl; +// cout << "TH OUT" << endl; } @@ -78,7 +100,7 @@ void Strucel::tophatGradient (int *out, int *in, int width, int height) void Strucel::blackhatGradient (int *out, int **in, int width, int height) { -cout << "BH IN" << endl; +// cout << "BH IN" << endl; for (int j = 0; j < height; j++) for (int i = 0; i < width; i++) { @@ -92,7 +114,7 @@ cout << "BH IN" << endl; } out[j * width + i] = max - in[j][i]; } -cout << "BH OUT" << endl; +// cout << "BH OUT" << endl; } diff --git a/Code/Seg/ImageTools/strucel.h b/Code/Seg/ImageTools/strucel.h index 9503cd28d8e1242eb70ad9fb7c28b59a79374025..9b90927ab5606723cbf3b9f9d3676eb442dc5b49 100755 --- a/Code/Seg/ImageTools/strucel.h +++ b/Code/Seg/ImageTools/strucel.h @@ -17,6 +17,10 @@ public: /** 3x3 cross structuring element type. */ static const int TYPE_PLUS_3X3; + /** 1x3 horizontal structuring element type. */ + static const int TYPE_HOR; + /** 3x1 vertical structuring element type. */ + static const int TYPE_VER; /** diff --git a/Code/Seg/ImageTools/vmap.cpp b/Code/Seg/ImageTools/vmap.cpp index 3cd61824e5cf80663da62d8c3211fc2efc3e3a64..e25e80570d754e39b32ec0837b94cd6f18fef512 100755 --- a/Code/Seg/ImageTools/vmap.cpp +++ b/Code/Seg/ImageTools/vmap.cpp @@ -1,4 +1,4 @@ -// #include <iostream> +#include <iostream> #include "vmap.h" #include "math.h" @@ -10,6 +10,9 @@ const int VMap::TYPE_SOBEL_5X5 = 1; const int VMap::TYPE_TOP_HAT = 2; const int VMap::TYPE_BLACK_HAT = 3; const int VMap::TYPE_MORPHO = 4; +const int VMap::TYPE_FULL_TOP_HAT = 5; +const int VMap::TYPE_FULL_BLACK_HAT = 6; +const int VMap::TYPE_FULL_MORPHO = 7; const int VMap::NEAR_SQ_ANGLE = 80; // 80% (roughly 25 degrees) const int VMap::LARGE_SQ_ANGLE = 25; // 25% (60 degrees) @@ -20,27 +23,92 @@ VMap::VMap (int width, int height, int *data, int type) { this->width = width; this->height = height; - if (type == TYPE_SOBEL_5X5) buildSobel5x5Map (data); - else buildGradientMap (data); imap = new int[width * height]; if (type == TYPE_TOP_HAT) { Strucel se (Strucel::TYPE_PLUS_3X3); se.tophatGradient (imap, data, width, height); + buildSobel5x5Map (data); + } + else if (type == TYPE_FULL_TOP_HAT) + { + Strucel se (Strucel::TYPE_PLUS_3X3); + se.tophatGradient (imap, data, width, height); + int *jmap = new int[width * height]; + Strucel seh (Strucel::TYPE_HOR); + seh.tophatGradient (jmap, data, width, height); + int *kmap = new int[width * height]; + Strucel sev (Strucel::TYPE_VER); + sev.tophatGradient (kmap, data, width, height); + map = new Vr2i[width * height]; + Vr2i *tmpmap = map; + for (int i = 0; i < width * height; i ++) + { + tmpmap->set (jmap[i], kmap[i]); + tmpmap ++; + } } else if (type == TYPE_BLACK_HAT) { Strucel se (Strucel::TYPE_PLUS_3X3); se.blackhatGradient (imap, data, width, height); + buildSobel5x5Map (data); + } + else if (type == TYPE_FULL_BLACK_HAT) + { + Strucel se (Strucel::TYPE_PLUS_3X3); + se.blackhatGradient (imap, data, width, height); + int *jmap = new int[width * height]; + Strucel seh (Strucel::TYPE_HOR); + seh.blackhatGradient (jmap, data, width, height); + int *kmap = new int[width * height]; + Strucel sev (Strucel::TYPE_VER); + sev.blackhatGradient (kmap, data, width, height); + map = new Vr2i[width * height]; + Vr2i *tmpmap = map; + for (int i = 0; i < width * height; i ++) + { + tmpmap->set (jmap[i], kmap[i]); + tmpmap ++; + } } else if (type == TYPE_MORPHO) { Strucel se (Strucel::TYPE_PLUS_3X3); se.morphoGradient (imap, data, width, height); + buildSobel5x5Map (data); + } + else if (type == TYPE_FULL_MORPHO) + { + Strucel se (Strucel::TYPE_PLUS_3X3); + se.morphoGradient (imap, data, width, height); + int *jmap = new int[width * height]; + Strucel seh (Strucel::TYPE_HOR); + seh.morphoGradient (jmap, data, width, height); + int *kmap = new int[width * height]; + Strucel sev (Strucel::TYPE_VER); + sev.morphoGradient (kmap, data, width, height); + map = new Vr2i[width * height]; + Vr2i *tmpmap = map; + for (int i = 0; i < width * height; i ++) + { + tmpmap->set (jmap[i], kmap[i]); + tmpmap ++; + } } - else + else if (type == TYPE_SOBEL_5X5) + { + buildSobel5x5Map (data); for (int i = 0; i < width * height; i++) imap[i] = (int) sqrt (map[i].norm2 ()); + } + else // type == TYPE_SOBEL_3X3 + { + buildGradientMap (data); + for (int i = 0; i < width * height; i++) + imap[i] = (int) sqrt (map[i].norm2 ()); + } + mask = new bool[width * height]; for (int i = 0; i < width * height; i++) mask[i] = false; masking = false; @@ -54,27 +122,93 @@ VMap::VMap (int width, int height, int **data, int type) { this->width = width; this->height = height; - if (type == TYPE_SOBEL_5X5) buildSobel5x5Map (data); - else buildGradientMap (data); imap = new int[width * height]; if (type == TYPE_TOP_HAT) { Strucel se (Strucel::TYPE_PLUS_3X3); se.tophatGradient (imap, data, width, height); + buildSobel5x5Map (data); + } + else if (type == TYPE_FULL_TOP_HAT) + { + Strucel se (Strucel::TYPE_PLUS_3X3); + se.tophatGradient (imap, data, width, height); + int *jmap = new int[width * height]; + Strucel seh (Strucel::TYPE_HOR); + seh.tophatGradient (jmap, data, width, height); + int *kmap = new int[width * height]; + Strucel sev (Strucel::TYPE_VER); + sev.tophatGradient (kmap, data, width, height); + map = new Vr2i[width * height]; + Vr2i *tmpmap = map; + for (int i = 0; i < width * height; i ++) + { + tmpmap->set (jmap[i], kmap[i]); + tmpmap ++; + } } else if (type == TYPE_BLACK_HAT) { Strucel se (Strucel::TYPE_PLUS_3X3); se.blackhatGradient (imap, data, width, height); + buildSobel5x5Map (data); + } + else if (type == TYPE_FULL_BLACK_HAT) + { + Strucel se (Strucel::TYPE_PLUS_3X3); + se.blackhatGradient (imap, data, width, height); + int *jmap = new int[width * height]; + Strucel seh (Strucel::TYPE_HOR); + seh.blackhatGradient (jmap, data, width, height); + int *kmap = new int[width * height]; + Strucel sev (Strucel::TYPE_VER); + sev.blackhatGradient (kmap, data, width, height); + map = new Vr2i[width * height]; + Vr2i *tmpmap = map; + for (int i = 0; i < width * height; i ++) + { + tmpmap->set (jmap[i], kmap[i]); + tmpmap ++; + } } else if (type == TYPE_MORPHO) { Strucel se (Strucel::TYPE_PLUS_3X3); se.morphoGradient (imap, data, width, height); + buildSobel5x5Map (data); } - else + else if (type == TYPE_FULL_MORPHO) + { +cout << "FULL MORPHO" << endl; + Strucel se (Strucel::TYPE_PLUS_3X3); + se.morphoGradient (imap, data, width, height); + int *jmap = new int[width * height]; + Strucel seh (Strucel::TYPE_HOR); + seh.morphoGradient (jmap, data, width, height); + int *kmap = new int[width * height]; + Strucel sev (Strucel::TYPE_VER); + sev.morphoGradient (kmap, data, width, height); + map = new Vr2i[width * height]; + Vr2i *tmpmap = map; + for (int i = 0; i < width * height; i ++) + { + tmpmap->set (jmap[i], kmap[i]); + tmpmap ++; + } + } + else if (type == TYPE_SOBEL_5X5) + { + buildSobel5x5Map (data); + for (int i = 0; i < width * height; i++) + imap[i] = (int) sqrt (map[i].norm2 ()); + } + else // type == TYPE_SOBEL_3X3 + { + buildGradientMap (data); for (int i = 0; i < width * height; i++) - imap[i] = sqrt (map[i].norm2 ()); + imap[i] = (int) sqrt (map[i].norm2 ()); + } + mask = new bool[width * height]; for (int i = 0; i < width * height; i++) mask[i] = false; masking = false; diff --git a/Code/Seg/ImageTools/vmap.h b/Code/Seg/ImageTools/vmap.h index c846596367e068dedca685425f4f079f94017b69..bb3f6e75b7f08b81373222094b50ef18e296729e 100755 --- a/Code/Seg/ImageTools/vmap.h +++ b/Code/Seg/ImageTools/vmap.h @@ -27,6 +27,12 @@ public: static const int TYPE_BLACK_HAT; /** Gradient extraction method : Morphological gradient (D(I) - E(I)). */ static const int TYPE_MORPHO; + /** Gradient extraction method : Morphological directional top hat. */ + static const int TYPE_FULL_TOP_HAT; + /** Gradient extraction method : Morphological directional black hat. */ + static const int TYPE_FULL_BLACK_HAT; + /** Gradient extraction method : Morphological directional gradient. */ + static const int TYPE_FULL_MORPHO; /** diff --git a/Code/Seg/main.cpp b/Code/Seg/main.cpp index ada2ffd8113b16bf7c14cf79b22587f5efcd1f1d..db9e83dd10e48b5bbf37b4fe9db70591db167eea 100755 --- a/Code/Seg/main.cpp +++ b/Code/Seg/main.cpp @@ -41,6 +41,12 @@ int main (int argc, char *argv[]) window.useGradient (VMap::TYPE_BLACK_HAT); else if (string(argv[i]) == string ("-morpho")) window.useGradient (VMap::TYPE_MORPHO); + else if (string(argv[i]) == string ("-fulltophat")) + window.useGradient (VMap::TYPE_FULL_TOP_HAT); + else if (string(argv[i]) == string ("-fullblackhat")) + window.useGradient (VMap::TYPE_FULL_BLACK_HAT); + else if (string(argv[i]) == string ("-fullmorpho")) + window.useGradient (VMap::TYPE_FULL_MORPHO); else { int l = string (argv[i]).length (); diff --git a/Methode/ctrl.tex b/Methode/ctrl.tex index 6a0721fd214cd1bf1626c1faaabc638c99293e87..51f8c442a86ac92cc9253f41ceebe6f44847270a 100755 --- a/Methode/ctrl.tex +++ b/Methode/ctrl.tex @@ -53,6 +53,7 @@ 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 \\ +Ctrl-p && Edite la derni\`ere d\'etection dans un fichier seg.txt \\ 1 && Commute la visu des segments (pixels) \\ 2 && Commute la visu de l'accumulateur \\ 3 && Commute la visu des profils \\