33 #include <visp/vpMath.h>
34 #include <visp3/ustk_core/usPreScanToPostScan2DConverter.h>
48 const int BModeSampleNumber,
const int scanLineNumber)
52 throw(vpException(vpException::notInitialized,
"Please fill the post-scan resolution before init the conversion."));
55 m_scanLineNumber = scanLineNumber;
56 m_BModeSampleNumber = BModeSampleNumber;
59 m_settings = inputSettings;
61 double APitch = inputSettings.
getDepth() / (double)(BModeSampleNumber);
66 double t_min = -((double)(scanLineNumber - 1) * LPitch) / (2.0 * inputSettings.
getTransducerRadius());
67 double t_max = -t_min;
68 double x_min = r_min * cos(t_min);
70 double y_min = r_max * sin(t_min);
71 double y_max = r_max * sin(t_max);
73 m_height = vpMath::round((x_max - x_min) / m_yResolution);
74 m_width = vpMath::round((y_max - y_min) / m_xResolution);
76 m_rMap.resize(m_height, m_width);
77 m_tMap.resize(m_height, m_width);
80 for (
unsigned int i = 0; i < m_height; ++i) {
81 for (
unsigned int j = 0; j < m_width; ++j) {
82 x = x_min + i * m_yResolution;
83 y = y_min + j * m_xResolution;
85 m_tMap[i][j] = atan2(y, x) * inputSettings.
getTransducerRadius() / LPitch + (scanLineNumber - 1) / 2.0;
89 m_scanLineNumber = scanLineNumber;
90 m_BModeSampleNumber = BModeSampleNumber;
93 m_settings = inputSettings;
95 double APitch = inputSettings.
getDepth() / (double)(BModeSampleNumber);
96 m_height = vpMath::round((APitch * BModeSampleNumber) / m_yResolution);
97 m_width = vpMath::round(inputSettings.
getScanLinePitch() * (scanLineNumber - 1) / m_xResolution);
99 m_rMap.resize(m_height, m_width);
100 m_tMap.resize(m_height, m_width);
102 for (
unsigned int i = 0; i < m_height; ++i) {
103 for (
unsigned int j = 0; j < m_width; ++j) {
123 const int scanLineNumber,
const double xResolution,
const double yResolution)
126 m_scanLineNumber = scanLineNumber;
127 m_BModeSampleNumber = BModeSampleNumber;
128 m_xResolution = xResolution;
129 m_yResolution = yResolution;
130 m_settings = inputSettings;
132 double APitch = inputSettings.
getDepth() / (double)(BModeSampleNumber);
137 double t_min = -((double)(scanLineNumber - 1) * LPitch) / (2.0 * inputSettings.
getTransducerRadius());
138 double t_max = -t_min;
139 double x_min = r_min * cos(t_min);
140 double x_max = r_max;
141 double y_min = r_max * sin(t_min);
142 double y_max = r_max * sin(t_max);
144 m_height = vpMath::round((x_max - x_min) / m_yResolution);
145 m_width = vpMath::round((y_max - y_min) / m_xResolution);
147 m_rMap.resize(m_height, m_width);
148 m_tMap.resize(m_height, m_width);
151 for (
unsigned int i = 0; i < m_height; ++i) {
152 for (
unsigned int j = 0; j < m_width; ++j) {
153 x = x_min + i * m_yResolution;
154 y = y_min + j * m_xResolution;
156 m_tMap[i][j] = atan2(y, x) * inputSettings.
getTransducerRadius() / LPitch + (scanLineNumber - 1) / 2.0;
160 m_scanLineNumber = scanLineNumber;
161 m_BModeSampleNumber = BModeSampleNumber;
162 m_xResolution = xResolution;
163 m_yResolution = yResolution;
164 m_settings = inputSettings;
166 double APitch = inputSettings.
getDepth() / (double)(BModeSampleNumber);
167 m_height = vpMath::round(inputSettings.
getDepth() / m_yResolution);
168 m_width = vpMath::round(inputSettings.
getScanLinePitch() * (scanLineNumber - 1) / m_xResolution);
170 m_rMap.resize(m_height, m_width);
171 m_tMap.resize(m_height, m_width);
174 double ratio2 = m_yResolution / APitch;
176 for (
unsigned int i = 0; i < m_height; ++i) {
177 for (
unsigned int j = 0; j < m_width; ++j) {
178 m_rMap[i][j] = i * ratio2;
179 m_tMap[i][j] = j * ratio1;
199 if (xResolution != 0. && yResolution != 0.) {
214 postScanImage.resize(m_height, m_width);
215 for (
unsigned int i = 0; i < m_height; ++i)
216 for (
unsigned int j = 0; j < m_width; ++j) {
217 double u = m_rMap[i][j];
218 double v = m_tMap[i][j];
219 postScanImage(i, j, (
unsigned char)interpolateLinear(preScanImage, u, v));
231 double usPreScanToPostScan2DConverter::interpolateLinear(
const vpImage<unsigned char> &I,
double x,
double y)
233 int x1 = (int)floor(x);
234 int x2 = (int)ceil(x);
235 int y1 = (int)floor(y);
236 int y2 = (int)ceil(y);
238 if ((0 <= x) && (x < I.getHeight()) && (0 <= y) && (y < I.getWidth())) {
245 if (x2 >=
static_cast<int>(I.getHeight()))
247 if (y2 >=
static_cast<int>(I.getWidth()))
255 val1 = (x2 - x) * I(x1, y1) + (x - x1) * I(x2, y1);
256 val2 = (x2 - x) * I(x1, y2) + (x - x1) * I(x2, y2);
261 return (y2 - y) * val1 + (y - y1) * val2;
void setHeightResolution(double heightResolution)
double getHeightResolution() const
void setWidthResolution(double widthResolution)
double getWidthResolution() const
unsigned int getBModeSampleNumber() const
double getAxialResolution() const
~usPreScanToPostScan2DConverter()
void convert(const usImagePreScan2D< unsigned char > &preScanImage, usImagePostScan2D< unsigned char > &postScanImage, double xResolution=0., double yResolution=0.)
void init(const usImagePostScan2D< unsigned char > &inputSettings, const int BModeSampleNumber, const int scanLineNumber)
usPreScanToPostScan2DConverter()
Generic class for 2D ultrasound data common settings associated to the type of probe transducer used ...
void setTransducerConvexity(const bool isTransducerConvex)
double getFieldOfView() const
void setDepth(double depth)
void setScanLinePitch(const double scanLinePitch)
double getScanLinePitch() const
void setTransducerRadius(const double transducerRadius)
bool isTransducerConvex() const
double getTransducerRadius() const
unsigned int getScanLineNumber() const
void setScanLineNumber(unsigned int scanLineNumber)