UsTK : Ultrasound ToolKit  version 2.0.1 under development (2024-12-17)
usImageElastography.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  * Marc Pouliquen
30  *
31  *****************************************************************************/
32 
33 #include <visp3/ustk_elastography/usImageElastography.h>
34 
39  : m_ultrasoundImage(), m_strainMap(), m_elastoImage(), m_heigthPosition(0), m_widthPosition(0)
40 {
41 }
42 
52 usImageElastography::usImageElastography(const vpImage<unsigned char> &ultrasoundImage,
53  const vpImage<unsigned char> &strainMap, unsigned int heightPosition,
54  unsigned int widthPosition)
55  : m_ultrasoundImage(ultrasoundImage), m_strainMap(strainMap), m_elastoImage(), m_heigthPosition(heightPosition),
56  m_widthPosition(widthPosition)
57 {
58  computeElastographyImage();
59 }
60 
65 
70 vpImage<vpRGBa> usImageElastography::getElastoImage() { return m_elastoImage; }
71 
79 void usImageElastography::setStrainMap(const vpImage<unsigned char> &strainMap, unsigned int heightPosition,
80  unsigned int widthPosition)
81 {
82  // image dimension check
83  if (m_ultrasoundImage.getHeight() < strainMap.getHeight() + heightPosition ||
84  m_ultrasoundImage.getWidth() < strainMap.getWidth() + widthPosition) {
85  throw(
86  vpException(vpException::dimensionError,
87  "usImageElastography::setStrainMap : the strainMap position is out of ultrasound image bounds !"));
88  }
89 
90  m_strainMap = strainMap;
91  m_heigthPosition = heightPosition;
92  m_widthPosition = widthPosition;
93  computeElastographyImage();
94 }
95 
100 void usImageElastography::setUltrasoundImage(const vpImage<unsigned char> &ultrasoundImage)
101 {
102  m_ultrasoundImage = ultrasoundImage;
103  m_elastoImage.resize(m_ultrasoundImage.getHeight(), m_ultrasoundImage.getWidth(), vpRGBa(0, 0, 0, 255));
104 }
105 
106 void usImageElastography::computeElastographyImage()
107 {
108 #ifdef VISP_HAVE_OPENMP
109 #pragma omp parallel for
110 #endif
111  for (int i = 0; i < (int)m_elastoImage.getHeight(); i++) {
112  for (unsigned int j = 0; j < m_elastoImage.getWidth(); j++) {
113  vpRGBa newColor;
114  // inside of the strainMap ROI
115  if (i >= (int)m_heigthPosition && i < (int)(m_heigthPosition + m_strainMap.getHeight()) && j >= m_widthPosition &&
116  j < m_widthPosition + m_strainMap.getWidth()) {
117  newColor.R = m_strainMap[i - m_heigthPosition][j - m_widthPosition];
118  } else { // oustide
119  newColor.R = m_ultrasoundImage[i][j];
120  newColor.G = m_ultrasoundImage[i][j];
121  newColor.B = m_ultrasoundImage[i][j];
122  }
123  m_elastoImage[i][j] = newColor;
124  }
125  }
126 }
vpImage< vpRGBa > getElastoImage()
void setUltrasoundImage(const vpImage< unsigned char > &ultrasoundImage)
void setStrainMap(const vpImage< unsigned char > &strainMap, unsigned int heightPosition, unsigned int widthPosition)
usImageElastography()
Constructor.