UsTK : Ultrasound ToolKit  version 1.0.0 under development (2020-06-26) under development (2020-06-26)
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

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;
}