UsTK : Ultrasound ToolKit  version 2.0.1 under development (2025-02-01)
tutorial-fullConversion2D.cpp
1 #include <visp3/ustk_core/usConfig.h>
2 
3 #ifdef USTK_HAVE_FFTW
4 
5 #include <visp3/core/vpTime.h>
6 #include <visp3/ustk_core/usImageIo.h>
7 #include <visp3/ustk_core/usRFToPostScan2DConverter.h>
8 
9 int main(int argc, char **argv)
10 {
11  std::string filename;
12 
13  for (int i = 0; i < argc; i++) {
14  if (std::string(argv[i]) == "--input")
15  filename = std::string(argv[i + 1]);
16  else if (std::string(argv[i]) == "--help") {
17  std::cout << "\nUsage: " << argv[0] << " [--input <RF2D.rf>] [--help]\n" << std::endl;
18  return 0;
19  }
20  }
21 
22  // Get the ustk-dataset package path or USTK_DATASET_PATH environment variable value
23  if (filename.empty()) {
24  std::string env_ipath = us::getDataSetPath();
25  if (!env_ipath.empty())
26  filename = env_ipath + "/RFElasto/image00010.mhd";
27  else {
28  std::cout << "You should set USTK_DATASET_PATH environment var to access to ustk dataset" << std::endl;
29  return 0;
30  }
31  }
32 
33  usImageRF2D<short int> rfImage;
34 
36  postscanImage.setHeightResolution(0.0005);
37  postscanImage.setWidthResolution(0.0005);
38 
39  usImageIo::read(rfImage, filename);
40 
41  postscanImage.setTransducerSettings(rfImage);
42 
43  std::cout << "end reading" << std::endl;
44 
45  // scan-conversion
46  usRFToPostScan2DConverter converter;
47 
48  double startTime = vpTime::measureTimeMs();
49  std::cout << "init converter..." << std::endl;
50 
51  converter.setConversionParameters(postscanImage, rfImage.getRFSampleNumber() / 10, rfImage.getScanLineNumber(), 10);
52 
53  double endInitTime = vpTime::measureTimeMs();
54  std::cout << "init time (sec) = " << (endInitTime - startTime) / 1000.0 << std::endl;
55 
56  std::cout << "converting..." << std::endl;
57  converter.convert(rfImage, postscanImage);
58 
59  std::cout << postscanImage;
60 
61  double endConvertTime = vpTime::measureTimeMs();
62  std::cout << "convert time (sec) = " << (endConvertTime - endInitTime) / 1000.0 << std::endl;
63 
64  std::cout << "writing post-scan..." << std::endl;
65  std::string outFileName = "postscan.xml";
66  usImageIo::write(postscanImage, outFileName);
67 
68  return 0;
69 }
70 
71 #else
72 #include <iostream>
73 int main()
74 {
75  std::cout << "You should install FFTW library to run this tutorial" << std::endl;
76  return 0;
77 }
78 
79 #endif
static void read(usImageRF2D< short int > &imageRf2D, const std::string &headerFileName)
Definition: usImageIo.cpp:153
static void write(const usImageRF2D< short > &rfImage, const std::string &headerFileName, const std::string &imageExtension2D)
Definition: usImageIo.cpp:104
void setHeightResolution(double heightResolution)
void setWidthResolution(double widthResolution)
unsigned int getRFSampleNumber() const
Definition: usImageRF2D.h:305
2D conversion from RF signal to post-scan image
void convert(const usImageRF2D< short int > &rfImage, usImagePostScan2D< unsigned char > &postScanImage)
void setConversionParameters(const usImagePostScan2D< unsigned char > &inputSettings, const int BModeSampleNumber, const int scanLineNumber, const int decimationFactor)
void setTransducerSettings(const usTransducerSettings &other)
unsigned int getScanLineNumber() const
VISP_EXPORT std::string getDataSetPath()
Definition: us.cpp:54