31 #include "DGtal/base/Common.h"
32 #include "DGtal/helpers/StdDefs.h"
33 #include <boost/format.hpp>
35 #include "DGtal/io/readers/GenericReader.h"
36 #include "DGtal/io/writers/GenericWriter.h"
37 #include "DGtal/images/ConstImageAdapter.h"
38 #include "DGtal/kernel/BasicPointFunctors.h"
43 using namespace DGtal;
95 int main(
int argc,
char** argv )
105 std::string inputFileName;
106 std::string outputFileName =
"result.pgm";
109 int userStartSlice {0};
110 int userEndSlice {0};
111 unsigned int sliceOrientation {2};
114 app.description(
"Convert a volumetric file (.vol, .longvol, .pgm3d) into a set of 2D slice images. \n Typical use: to extract all slices defined in Y plane (y=cst): \n vol2slice image3d.vol slice.pgm -s 1 \n");
116 app.add_option(
"-i,--input,1", inputFileName,
"vol file (.vol, .longvol .p3d, .pgm3d and if WITH_ITK is selected: dicom, dcm, mha, mhd). For longvol, dicom, dcm, mha or mhd formats, the input values are linearly scaled between 0 and 255.")
118 ->check(CLI::ExistingFile);
120 app.add_option(
"--output,-o,2",outputFileName ,
"base_name.extension: extracted 2D slice volumetric files (will result n files base_name_xxx.extension)",
true);
121 app.add_option(
"--setFirstSlice,-f", userStartSlice,
"Set the first slice index to be extracted.",
true)
122 -> check(CLI::Number);
123 app.add_option(
"--setLastSlice,-l", userEndSlice,
"Set the last slice index to be extracted (by default set to maximal value according to the given volume).")
124 -> check(CLI::Number);
125 app.add_option(
"--sliceOrientation,-s", sliceOrientation,
"specify the slice orientation for which the slice are defined (by default =2 (Z direction))",
true)
126 -> check(CLI::IsMember({0, 1, 2}));
127 app.add_option(
"--rescaleInputMin", rescaleInputMin,
"min value used to rescale the input intensity (to avoid basic cast into 8 bits image).",
true);
128 app.add_option(
"--rescaleInputMax", rescaleInputMax,
"max value used to rescale the input intensity (to avoid basic cast into 8 bits image).",
true);
129 app.get_formatter()->column_width(40);
131 CLI11_PARSE(app, argc, argv);
133 std::string outputExt = outputFileName.substr(outputFileName.find_last_of(
".")+1);
134 std::string outputBasename = outputFileName.substr(0, outputFileName.find_last_of(
"."));
137 trace.
info()<<
"Importing volume file base name: " << outputBasename <<
" extension: " << outputExt <<
" ..." ;
145 unsigned int startSlice=0;
146 unsigned int endSlice=input3dImage.
domain().upperBound()[sliceOrientation];
148 if(userStartSlice !=0){
149 startSlice = userStartSlice;
151 if(userEndSlice != 0){
152 endSlice = userEndSlice;
156 #pragma omp parallel for schedule(dynamic)
157 for(
unsigned int i=startSlice; i <= endSlice; i++){
158 trace.
info() <<
"Exporting slice image "<< i ;
161 invFunctor(input3dImage.
domain().upperBound()));
164 SliceImageAdapter sliceImage( input3dImage, domain2D, aSliceFunctor, identityFunctor );
165 stringstream outName; outName << outputBasename <<
"_" << boost::format(
"%|05|")% i <<
"."<< outputExt ;
int main(int argc, char **argv)
const Domain & domain() const
Trace trace(traceWriterTerm)
void initRemoveOneDim(const Dimension &dimRemoved)