UsTK : Ultrasound ToolKit  version 2.0.1 under development (2023-12-07)
Tutorials: UsTK core and io tutorials (image read/write and conversions)

Introduction

The core module contains all ultrasound tool kit data structures such as 2D or 3D images, for RF, pre-scan or post-scan modalities, and conversion algorithms between those different image types. The io module code contains a set of read/write methods to save and load ultrasound images.

The following turials are good examples to :

  • Load and convert a 2D RF image in a pre-scan image.
  • Load and convert a 2D pre-scan image and convert it to a post-scan image.

Note that the source code used in this tutorial can be downloaded using the following command :

$ svn export https://github.com/lagadic/ustk.git/trunk/tutorial/ustk/imageConversion

2D Rf Conversion

The following code shows how to read a rf frame, include it in a volume, and finally convert the volume to pre-scan iamge. To read a RF frame, you can use the usImageIo::read() method. Then, to convert it, the usRFToPreScan2DConverter does the job. Note that using rf files, you have to manually set the transducer settings of the probe used (those informations aren't present in rf format from ultrasonix).

#include <visp3/ustk_core/usConfig.h>
#ifdef USTK_HAVE_FFTW
#include <visp3/core/vpTime.h>
#include <visp3/ustk_core/usImageIo.h>
#include <visp3/ustk_core/usImageRF3D.h>
#include <visp3/ustk_core/usRFToPreScan3DConverter.h>
int main()
{
std::string filename;
// Get the ustk-dataset package path or USTK_DATASET_PATH environment variable value
std::string env_ipath = us::getDataSetPath();
if (!env_ipath.empty())
filename = env_ipath + "/rf/signal.rf";
else {
std::cout << "You should set USTK_DATASET_PATH environment var to access to ustk dataset" << std::endl;
return 0;
}
std::cout << filename << std::endl;
usImageIo::read(rfImage, filename);
// settings used for rf file in ustk-dataset
rfImage.setScanLinePitch(0.010625);
rfImage.setTransducerRadius(0.0398);
rfImage.setDepth(0.15);
std::cout << "end reading" << std::endl;
// scan-conversion
double startTime = vpTime::measureTimeMs();
std::cout << "converting..." << std::endl;
converter.convert(rfImage, prescanImage);
std::cout << prescanImage;
double endConvertTime = vpTime::measureTimeMs();
std::cout << "convert time (sec) = " << (endConvertTime - startTime) / 1000.0 << std::endl;
std::cout << "writing pre-scan..." << std::endl;
std::string outFileName = "preScan.png";
usImageIo::write(prescanImage, outFileName);
return 0;
}
#else
#include <iostream>
int main()
{
std::cout << "You should install FFTW library to run this tutorial" << std::endl;
return 0;
}
#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
2D conversion from RF signal to pre-scan image
void convert(const usImageRF2D< short int > &rfImage, usImagePreScan2D< unsigned char > &preScanImage)
void setDepth(double depth)
void setScanLinePitch(const double scanLinePitch)
void setTransducerRadius(const double transducerRadius)
VISP_EXPORT std::string getDataSetPath()
Definition: us.cpp:54

Scan conversion of a pre-scan ultrasound frame

The following code shows how to read a pre-scan frame, and convert it to a post-scan iamge. To read a pre-scan frame, you can use the usImageIo::read() method. Then to convert it, use usPreScanToPostScan2DConverter class.

#include <visp3/core/vpTime.h>
#include <visp3/ustk_core/usImageIo.h>
#include <visp3/ustk_core/usPreScanToPostScan2DConverter.h>
#include <visp3/ustk_core/usSequenceReader.h>
int main(int argc, char **argv)
{
std::string filename;
for (int i = 0; i < argc; i++) {
if (std::string(argv[i]) == "--input")
filename = std::string(argv[i + 1]);
else if (std::string(argv[i]) == "--help") {
std::cout << "\nUsage: " << argv[0] << " [--input <preScan3D.xml>] [--help]\n" << std::endl;
return 0;
}
}
// Get the ustk-dataset package path or USTK_DATASET_PATH environment variable value
if (filename.empty()) {
std::string env_ipath = us::getDataSetPath();
if (!env_ipath.empty())
filename = env_ipath + "/pre-scan/2D_xml/prescan2d.xml";
else {
std::cout << "You should set USTK_DATASET_PATH environment var to access to ustk dataset" << std::endl;
return 0;
}
}
prescanImage.resize(128, 480, 16);
usImageIo::read(prescanImage, filename);
// scan-conversion
converter.convert(prescanImage, postscanImage);
std::cout << "converted image : " << std::endl;
std::cout << postscanImage;
std::cout << "writing post-scan..." << std::endl;
std::string outFileName = "postscan.xml";
usImageIo::write(postscanImage, outFileName);
return 0;
}
void resize(const unsigned int h, const unsigned int w)
void convert(const usImagePreScan2D< unsigned char > &preScanImage, usImagePostScan2D< unsigned char > &postScanImage, double xResolution=0., double yResolution=0.)