UsTK : Ultrasound ToolKit  version 2.0.1 under development (2025-01-22)
tutorial-MHD-sequence-reader.cpp
1 #include <visp3/ustk_core/usMHDSequenceReader.h>
3 #include <visp3/ustk_core/usMHDSequenceWriter.h>
4 int main(int argc, char **argv)
5 {
6  std::string sequenceDirectory;
7  if (argc == 1) {
8  std::cout << "\nUsage: " << argv[0] << " [--input /path/to/mhd/sequence ] \n" << std::endl;
9  return 0;
10  }
11 
12  for (unsigned int i = 1; i < (unsigned int)argc; i++) {
13  if (std::string(argv[i]) == "--input") {
14  sequenceDirectory = std::string(argv[i + 1]);
15  i = argc;
16  } else {
17  std::cout << "\nUsage: " << argv[0] << " [--input /path/to/mhd/sequence ] \n" << std::endl;
18  return 0;
19  }
20  }
21 
23  std::vector<uint64_t> timestamp;
24 
25  usMHDSequenceReader reader;
26  reader.setSequenceDirectory(sequenceDirectory);
27 
28  usMHDSequenceWriter writer;
29  writer.setSequenceDirectory("/tmp"); // set here your outpur directory
30 
31  uint64_t newTimestamp = 0;
32  int inc = 0;
33  // reading loop
34  while (!reader.end()) {
35  reader.acquire(image, timestamp);
36 
37  // print your image informations
38  std::cout << image;
39 
40  // add a timestamp of 100ms between each frame
41  for (unsigned int i = 0; i < timestamp.size(); i++) {
42  timestamp.at(i) = newTimestamp;
43  newTimestamp += 100;
44  }
45  if (inc % 2 ==
46  1) // to fit a virtual probe motor sweeping along Z axis (at every volume, frame order is inverted along Z axis)
47  std::reverse(timestamp.begin(), timestamp.end());
48 
49  writer.write(image, timestamp);
50  inc++;
51  }
52 
53  return 0;
54 }
Reader for a sequence of images stored as mhd/raw files in a directory Image sequence files order hav...
void acquire(usImageRF2D< short int > &image, uint64_t &timestamp)
void setSequenceDirectory(const std::string sequenceDirectory)
Writer for a sequence of images stored as mhd/raw files in a directory Image filenames are set based ...
void setSequenceDirectory(const std::string sequenceDirectory)
void write(const usImageRF2D< short int > &image, const uint64_t timestamp)