32 #include "DGtal/base/Common.h"
33 #include "DGtal/helpers/StdDefs.h"
34 #include "DGtal/images/ImageContainerBySTLVector.h"
35 #include "DGtal/io/readers/GenericReader.h"
37 #include <boost/program_options/options_description.hpp>
38 #include <boost/program_options/parsers.hpp>
39 #include <boost/program_options/variables_map.hpp>
42 using namespace DGtal;
46 namespace po = boost::program_options;
95 int main(
int argc,
char** argv )
100 po::options_description general_opt(
"Allowed options are: ");
101 general_opt.add_options()
102 (
"help,h",
"display this message")
103 (
"input,i", po::value<std::string>(),
"vol file (.vol, .longvol .p3d, .pgm3d and if WITH_ITK is selected: dicom, dcm, mha, mhd) or sdp (sequence of discrete points). For longvol, dicom, dcm, mha or mhd formats, the input values are linearly scaled between 0 and 255." )
104 (
"output,o", po::value<std::string>(),
"sequence of discrete point file (.sdp) " )
105 (
"exportImageValues,e",
"option to export also the image value of the voxel in a fourth field.")
106 (
"thresholdMin,m", po::value<int>()->default_value(128),
"min threshold (default 128)" )
107 (
"thresholdMax,M", po::value<int>()->default_value(255),
"max threshold (default 255)" )
108 (
"rescaleInputMin", po::value<DGtal::int64_t>()->default_value(0),
"min value used to rescale the input intensity (to avoid basic cast into 8 bits image).")
109 (
"rescaleInputMax", po::value<DGtal::int64_t>()->default_value(255),
"max value used to rescale the input intensity (to avoid basic cast into 8 bits image).");
113 po::variables_map vm;
115 po::store(po::parse_command_line(argc, argv, general_opt), vm);
116 }
catch(
const std::exception& ex){
118 trace.
info()<<
"Error checking program options: "<< ex.what()<< endl;
121 if( !parseOK || vm.count(
"help")||argc<=1)
123 std::cout <<
"Usage: " << argv[0] <<
" [input] [output]\n"
124 <<
"Convert volumetric file into a digital set of points from a given threshold."
125 << general_opt <<
"\n";
126 std::cout <<
"Example:\n"
127 <<
"vol2sdp -i ${DGtal}/examples/samples/lobster.vol -o volumeList.sdp \n";
131 if(! vm.count(
"input") ||! vm.count(
"output"))
133 trace.
error() <<
" Input and output filename are needed to be defined" << endl;
138 string inputFilename = vm[
"input"].as<std::string>();
139 string outputFilename = vm[
"output"].as<std::string>();
141 trace.
info() <<
"Reading input file " << inputFilename ;
149 trace.
info() <<
" [done] " << std::endl ;
150 std::ofstream outStream;
151 outStream.open(outputFilename.c_str());
152 int minTh = vm[
"thresholdMin"].as<
int>();
153 int maxTh = vm[
"thresholdMax"].as<
int>();
155 trace.
info() <<
"Processing image to output file " << outputFilename ;
157 outStream <<
"# sdp file generate by vol2sdp with source vol:" << inputFilename <<
" and threshold min: " << minTh <<
" max:" << maxTh << std::endl;
158 outStream <<
"# format: x y z ";
159 if(vm.count(
"exportImageValues")){
160 outStream <<
" image_value";
162 outStream << std::endl;
166 if(inputImage(*it) >= minTh && inputImage(*it) <= maxTh ){
167 outStream << (*it)[0] <<
" " << (*it)[1] <<
" " << (*it)[2];
168 if(vm.count(
"exportImageValues")){
169 outStream <<
" " << (
unsigned int) inputImage(*it);
172 outStream << std::endl;
177 trace.
info() <<
" [done] " << std::endl ;
Trace trace(traceWriterTerm)
const Domain & domain() const
std::vector< Value >::const_iterator ConstIterator