From 072e9e293abeb6bde29f14e9df433e544c0f12a2 Mon Sep 17 00:00:00 2001 From: even <philippe.even@loria.fr> Date: Tue, 18 Dec 2018 18:09:46 +0100 Subject: [PATCH] Background contrast control --- Code/Seg/BSTools/bsdetectionwidget.cpp | 34 +++++++++++++++++++++++++- Code/Seg/BSTools/bsdetectionwidget.h | 19 ++++++++++++++ Methode/ctrl.tex | 2 +- 3 files changed, 53 insertions(+), 2 deletions(-) diff --git a/Code/Seg/BSTools/bsdetectionwidget.cpp b/Code/Seg/BSTools/bsdetectionwidget.cpp index 6a6254a..026c152 100755 --- a/Code/Seg/BSTools/bsdetectionwidget.cpp +++ b/Code/Seg/BSTools/bsdetectionwidget.cpp @@ -43,6 +43,7 @@ BSDetectionWidget::BSDetectionWidget (QWidget *parent) verbose = false; background = BACK_IMAGE; bsBoundsVisible = false; + blevel = 0; // Sets display parameters selectionColor = Qt::red; @@ -703,6 +704,13 @@ void BSDetectionWidget::keyPressEvent (QKeyEvent *event) << (bsPointsVisible ? "visible" : "hidden") << endl; displayDetectionResult (); } + else + { + // Tunes the background image black level + incBlackLevel ((event->modifiers () & Qt::ShiftModifier) ? -1 : 1); + displayDetectionResult (); + cout << "Background black level = " << getBlackLevel () << endl; + } break; case Qt::Key_Z : @@ -720,7 +728,7 @@ void BSDetectionWidget::keyPressEvent (QKeyEvent *event) { // Tunes the thickenning limit detector.incThickenningLimit ( - (event->modifiers () & Qt::ShiftModifier ? -1 : 1)); + (event->modifiers () & Qt::ShiftModifier) ? -1 : 1); extract (); cout << "Thickenning limit = " << detector.getThickenningLimit () << " pixels" << endl; @@ -858,6 +866,29 @@ void BSDetectionWidget::drawBlurredSegment (QPainter &painter, } +void BSDetectionWidget::incBlackLevel (int val) +{ + blevel += val * 5; + if (blevel < 0) blevel = 0; + if (blevel > 200) blevel = 200; +} + + +void BSDetectionWidget::lighten (QImage &im) +{ + if (blevel != 0 && background != BACK_BLACK && background != BACK_WHITE) + { + for (int i = 0; i < im.height (); i++) + for(int j = 0; j < im.width (); j++) + { + int col = blevel + (QColor (im.pixel(j,i)).value () + * (255 - blevel)) / 255; + im.setPixel (j, i, col + col * 256 + col * 256 * 256); + } + } +} + + void BSDetectionWidget::displayBackground () { if (background == BACK_BLACK) augmentedImage.fill (qRgb (0, 0, 0)); @@ -897,6 +928,7 @@ void BSDetectionWidget::displayDetectionResult () else if (background == BACK_WHITE) augmentedImage.fill (qRgb (255, 255, 255)); else if (background == BACK_IMAGE) augmentedImage = loadedImage; else augmentedImage = gradImage; + lighten (augmentedImage); QPainter painter (&augmentedImage); vector<BlurredSegment *> bss = detector.getBlurredSegments (); if (! bss.empty ()) diff --git a/Code/Seg/BSTools/bsdetectionwidget.h b/Code/Seg/BSTools/bsdetectionwidget.h index a961972..fe937fd 100755 --- a/Code/Seg/BSTools/bsdetectionwidget.h +++ b/Code/Seg/BSTools/bsdetectionwidget.h @@ -230,6 +230,8 @@ private: /** Background type. * BACK_BLACK, BACK_WHITE, BACK_IMAGE, BACK_GRAD, BACK_GRADX, BACK_GRADY. */ int background; + /** Black level used to lighten background images. */ + int blevel; /** Flag indicating whether detection result should be output. */ bool verbose; @@ -315,6 +317,23 @@ private: void drawBlurredSegment (QPainter &painter, BlurredSegment *bs, bool high = true); + /** + * \brief Returns the background black level. + */ + inline int getBlackLevel () const { return (blevel); } + + /** + * \brief Increments the background black level. + * @param val Increment value; + */ + void incBlackLevel (int val); + + /** + * \brief Lighten the image according to the black level set. + * @param im Image to lighten. + */ + void lighten (QImage &im); + /** * \brief Displays the window background (no detection). */ diff --git a/Methode/ctrl.tex b/Methode/ctrl.tex index 8510a56..86e186c 100755 --- a/Methode/ctrl.tex +++ b/Methode/ctrl.tex @@ -27,7 +27,6 @@ a/q/c &\spa & Enregistre / Affiche / Supprime les segments \\ 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 \\ -n && Allume le segment suivant dans une d\'etection multiple \\ j && Ajuste le seuil de voisinage pour les suivis rapides \\ k && Ajuste la taille minimale des composantes connexes \\ l && Ajuste la taille minimale du segment final \\ @@ -40,6 +39,7 @@ s && 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 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 \\ Ctrl-b && Commute le fond d'\'ecran de la fen\^etre principale \\ Ctrl-d && Commute le test de densit\'e \\ -- GitLab