UsTK : Ultrasound ToolKit  version 2.0.1 under development (2023-12-07)
usScanlineConfidence2D.cpp
1 /****************************************************************************
2  *
3  * This file is part of the ustk software.
4  * Copyright (C) 2016 - 2017 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * ("GPL") version 2 as published by the Free Software Foundation.
9  * See the file LICENSE.txt at the root directory of this source
10  * distribution for additional information about the GNU GPL.
11  *
12  * For using ustk with software that can not be combined with the GNU
13  * GPL, please contact Inria about acquiring a ViSP Professional
14  * Edition License.
15  *
16  * This software was developed at:
17  * Inria Rennes - Bretagne Atlantique
18  * Campus Universitaire de Beaulieu
19  * 35042 Rennes Cedex
20  * France
21  *
22  * If you have questions regarding the use of this file, please contact
23  * Inria at ustk@inria.fr
24  *
25  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
26  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27  *
28  * Authors:
29  * Pierre Chatelain
30  * Alexandre Krupa
31  *
32  *****************************************************************************/
33 
34 #include <visp3/ustk_confidence_map/usScanlineConfidence2D.h>
35 
40 
45 
52  const usImagePreScan2D<unsigned char> &preScanImage)
53 {
54  preScanConfidence.setImagePreScanSettings(preScanImage);
55  unsigned int AN = preScanImage.getHeight();
56  unsigned int LN = preScanImage.getWidth();
57  if (AN == 0 || LN == 0)
58  throw(vpException(vpException::notInitialized, "pre-scan image dimension is 0"));
59 
60  preScanConfidence.resize(AN, LN);
61 
62  // Find min and max
63  double min = 255.0;
64  double max = 0.0;
65  for (unsigned int i = 0; i < AN; ++i)
66  for (unsigned int j = 0; j < LN; ++j) {
67  if (static_cast<double>(preScanImage(i, j)) < min)
68  min = static_cast<double>(preScanImage(i, j));
69  if (static_cast<double>(preScanImage(i, j)) > max)
70  max = static_cast<double>(preScanImage(i, j));
71  }
72 
73  // Integrate scan lines
74  for (unsigned int j = 0; j < LN; ++j) {
75  double sum = 0.0;
76  for (unsigned int i = 0; i < AN; ++i)
77  sum += vpMath::sqr((preScanImage(i, j) - min) / (max - min));
78 
79  double val = sum;
80  preScanConfidence(0, j, 255);
81  for (unsigned int i = 1; i < AN; ++i) {
82  val -= vpMath::sqr((preScanImage(i - 1, j) - min) / (max - min));
83  preScanConfidence(i, j, (unsigned char)(val / sum * 255));
84  }
85  }
86 }
void resize(const unsigned int h, const unsigned int w)
void setImagePreScanSettings(const usImagePreScanSettings &preScanSettings)
void run(usImagePreScan2D< unsigned char > &preScanConfidence, const usImagePreScan2D< unsigned char > &preScanImage)