34 #include <visp3/ustk_elastography/usElastography.h>
36 #if defined(USTK_HAVE_FFTW)
50 m_samplingFrequency = 40e6;
58 #if defined(USTK_HAVE_ARMADILLO) && (ARMA_VERSION_MAJOR > 6) && (ARMA_VERSION_MAJOR > 700)
59 m_ME = usMotionEstimation();
62 m_decimationFactor = 10;
65 for (uint i = 0; i < 6; i++)
81 m_samplingFrequency = 40e6;
86 for (uint i = 0; i < 6; i++)
96 for (uint i = 0; i < 6; i++)
184 uint rnrows = r + nrows;
185 uint cncols = c + ncols;
188 t_Mout.
resize(nrows, ncols);
189 for (
unsigned int i = r; i < rnrows; i++)
190 for (
unsigned int j = c; j < cncols; j++)
191 t_Mout(i - r, j - c, M(i, j));
203 if (m_isloadPre ==
true && m_isloadPost ==
true && m_setROI ==
true) {
204 m_PreROI = usImageRF_ROI(m_Precomp, m_iy, m_ix, m_rh, m_rw);
205 m_PostROI = usImageRF_ROI(m_Postcomp, m_iy, m_ix, m_rh, m_rw);
209 #if defined(USTK_HAVE_ARMADILLO) && (ARMA_VERSION_MAJOR > 6) && (ARMA_VERSION_MAJOR > 700)
211 m_ME.init(m_PreROI, m_PostROI, 2, 20, 2, 120);
214 V = m_ME.getV_vp() * (m_c * (m_FPS / (2.0 * m_samplingFrequency)));
218 throw vpException(vpException::fatalError,
219 "usElastography : cannot use block-matching algorithm, armadillo is missing.");
237 vpMatrix gdx2 = cC[0]->run(dx2, h_gauss);
238 vpMatrix gdy2 = cC[1]->run(dy2, h_gauss);
239 vpMatrix gdxy = cC[2]->run(dxy, h_gauss);
240 vpMatrix gdty = cC[3]->run(dty, h_gauss);
241 vpMatrix gdtx = cC[4]->run(dtx, h_gauss);
245 m_h_m = gdx2.getRows();
246 m_w_m = gdx2.getCols();
247 int Wsizex = vpMath::round(0.1 * m_w_m);
248 int Wsizey = vpMath::round(0.1 * m_h_m);
249 int Wincx = vpMath::round(0.75 * Wsizex);
250 int Wincy = vpMath::round(0.75 * Wsizey);
251 int h_w = vpMath::round((
double)(m_h_m - Wsizey) / (
double)Wincy);
252 int w_w = vpMath::round((
double)(m_w_m - Wsizex) / (
double)Wincx);
263 for (uint n = 0; n < (uint)(m_w_m - Wsizex - Wincx); n += Wincx) {
265 for (uint m = 0; m < (uint)(m_h_m - Wsizey - Wincy); m += Wincy) {
266 double sgdx2_w = 0.0;
267 double sgdy2_w = 0.0;
268 double sgdxy_w = 0.0;
269 double sgdtx_w = 0.0;
270 double sgdty_w = 0.0;
271 for (uint i = m; i < (m + Wsizey); i++) {
272 for (uint j = n; j < (n + Wsizex); j++) {
273 sgdx2_w += gdx2[i][j];
274 sgdy2_w += gdy2[i][j];
275 sgdxy_w += gdxy[i][j];
276 sgdtx_w += gdtx[i][j];
277 sgdty_w += gdty[i][j];
284 b.data[0] = -sgdtx_w;
285 b.data[1] = -sgdty_w;
287 X = M.pseudoInverse() * b;
289 V[l][k] = X.data[1] * (m_c * (m_FPS / (2.0 * m_samplingFrequency)));
296 vpMatrix vV(m_h_m, m_w_m,
true);
300 double kappa = (2.0 * m_samplingFrequency) / (m_c * m_FPS);
301 double d_m = m_Lsqper * m_h_m;
304 vpMatrix
h((uint)n + 1, 1,
true);
305 double xi = kappa * 12.0 / (n * (n * n - 1));
307 for (
int i = (
int)n; i >= 0; i--) {
308 h[j][0] = xi * (i - (n + 1) / 2.0);
313 vpMatrix strainMatrix = cC[5]->run(vV,
h);
315 m_StrainMap.resize((
unsigned int)(strainMatrix.getRows() / (
double)m_decimationFactor), strainMatrix.getCols());
317 m_min_str = std::abs(strainMatrix.getMinValue());
318 m_max_str = std::abs(strainMatrix.getMaxValue());
319 m_max_abs = (m_min_str > m_max_str) ? m_min_str : m_max_str;
320 for (
unsigned int xIndex = 0; xIndex < m_StrainMap.getCols(); ++xIndex) {
321 for (
unsigned int yIndex = 0; yIndex < m_StrainMap.getRows(); ++yIndex) {
322 m_StrainMap[yIndex][xIndex] =
323 std::isnan(strainMatrix[yIndex * m_decimationFactor][xIndex])
325 : 254 * (fabs(strainMatrix[yIndex * m_decimationFactor][xIndex]) / (m_max_abs));
Convolution process for elastography puropse, based on fftw thirdparty library.
vpImage< unsigned char > run()
virtual ~usElastography()
void updateROIPos(int tx, int ty)
void setLSQpercentage(double per)
void setROI(int tx, int ty, int tw, int th)
void setPreCompression(const usImageRF2D< short > &Pre)
void setSamplingFrequency(double samplingFrequency)
void updateRF(const usImageRF2D< short int > &image)
void setPostCompression(const usImageRF2D< short > &Post)
unsigned int getHeight() const
void resize(const unsigned int height, const unsigned int width)
unsigned int getWidth() const
Class containing a set of static methods to compute various processes on RF images (gradients,...
static vpMatrix BilinearInterpolation(vpMatrix In, uint newW, uint newH)
Bilinear Interpolation.
static vpMatrix GaussianFilter(int height, int width, double sigma)
Gaussian Kernel generator.
static vpMatrix Difference(const usImageRF2D< short int > &A, const usImageRF2D< short int > &B)
static vpMatrix HadamardProd(vpMatrix matrix1, vpMatrix matrix2)
Element-wise product.
static vpMatrix getXGradient(const usImageRF2D< short > &image)
Computation of gradients.
static vpMatrix getYGradient(const usImageRF2D< short int > &image)