39 #include <visp3/ustk_core/usRFToPreScan2DConverter.h>
41 #if defined(USTK_HAVE_FFTW)
48 : m_logCompressor(), m_decimationFactor(decimationFactor), m_isInit(false)
60 fftw_free(m_fft_conv);
61 fftw_free(m_fft_out_inv);
62 fftw_destroy_plan(m_p);
63 fftw_destroy_plan(m_pinv);
74 void usRFToPreScan2DConverter::init(
int widthRF,
int heigthRF)
76 if (m_isInit && (m_signalSize != heigthRF || m_scanLineNumber != widthRF)) {
79 fftw_free(m_fft_conv);
80 fftw_free(m_fft_out_inv);
81 fftw_destroy_plan(m_p);
82 fftw_destroy_plan(m_pinv);
85 }
else if (m_signalSize == heigthRF && m_scanLineNumber == heigthRF)
89 m_fft_in = (fftw_complex *)fftw_malloc(
sizeof(fftw_complex) * heigthRF);
90 m_fft_out = (fftw_complex *)fftw_malloc(
sizeof(fftw_complex) * heigthRF);
91 m_fft_conv = (fftw_complex *)fftw_malloc(
sizeof(fftw_complex) * heigthRF);
92 m_fft_out_inv = (fftw_complex *)fftw_malloc(
sizeof(fftw_complex) * heigthRF);
95 m_env =
new double[heigthRF * widthRF];
96 m_comp =
new unsigned char[heigthRF * widthRF];
98 m_signalSize = heigthRF;
99 m_scanLineNumber = widthRF;
101 m_p = fftw_plan_dft_1d(m_signalSize, m_fft_in, m_fft_out, FFTW_FORWARD, FFTW_ESTIMATE);
102 m_pinv = fftw_plan_dft_1d(m_signalSize, m_fft_out, m_fft_out_inv, FFTW_BACKWARD, FFTW_ESTIMATE);
113 void usRFToPreScan2DConverter::enveloppeDetection(
const short int *s,
double *out)
117 int N = m_signalSize;
120 for (
int i = 0; i < N; i++) {
121 m_fft_in[i][0] = (double)s[i];
122 m_fft_in[i][1] = 0.0;
128 for (
int i = 0; i < N; i++) {
131 m_fft_out[i][1] = -m_fft_out[i][1];
132 else if (i == N / 2) {
135 }
else if (i > N / 2)
136 m_fft_out[i][0] = -m_fft_out[i][0];
142 double z = m_fft_out[i][1];
143 m_fft_out[i][1] = m_fft_out[i][0];
150 fftw_execute(m_pinv);
152 double Ndouble = (double)N;
153 for (
int i = 0; i < N; i++) {
154 out[i] = (
unsigned char)sqrt(abs(std::complex<double>(m_fft_in[i][0], -m_fft_out_inv[i][0] / Ndouble)));
171 if (!m_isInit || ((
int)rfImage.
getWidth()) != m_scanLineNumber || ((
int)rfImage.
getHeight()) != m_signalSize) {
179 unsigned int w = rfImage.
getWidth();
182 unsigned int frameSize = w *
h;
185 std::vector<short *> rfSignals;
186 for (
unsigned int j = 0; j < w; j++) {
187 short *s =
new short[
h];
188 for (
unsigned int i = 0; i <
h; i++) {
189 s[i] = rfImage(i, j);
191 rfSignals.push_back(s);
195 for (
unsigned int i = 0; i < w; ++i) {
196 enveloppeDetection(rfImage.
getSignal(i), m_env + i *
h);
200 m_logCompressor.
run(m_comp, m_env, frameSize);
205 for (
unsigned int i = 0; i < frameSize; ++i) {
212 double maxMinDiff = max - min;
216 for (
unsigned int i = 0; i <
h; i += m_decimationFactor) {
217 for (
unsigned int j = 0; j < w; ++j) {
218 unsigned int vcol = (
unsigned int)(((m_comp[i +
h * j] - min) / maxMinDiff) * 255);
219 preScanImage[k][j] = (vcol > 255) ? 255 : vcol;
222 if (k == preScanImage.getHeight())
void resize(const unsigned int h, const unsigned int w)
void setImagePreScanSettings(const usImagePreScanSettings &preScanSettings)
unsigned int getHeight() const
const Type * getSignal(unsigned int scanlineIndex) const
unsigned int getWidth() const
void run(unsigned char *dst, const double *src, unsigned int size)
~usRFToPreScan2DConverter()
void convert(const usImageRF2D< short int > &rfImage, usImagePreScan2D< unsigned char > &preScanImage)
usRFToPreScan2DConverter(int decimationFactor=10)
void setDecimationFactor(int decimationFactor)
int getDecimationFactor()
Class containing a set of static methods to compute various processes on RF images (gradients,...