32 #include "DGtal/base/Common.h"
33 #include "DGtal/helpers/StdDefs.h"
34 #include "DGtal/base/BasicFunctors.h"
35 #include "DGtal/images/ImageContainerBySTLVector.h"
36 #include "DGtal/io/writers/GenericWriter.h"
37 #include "DGtal/io/readers/ITKReader.h"
42 using namespace DGtal;
79 template<
typename TImage,
typename TImageMask>
81 applyMaskImage( TImage &imageInput,
const TImageMask &maskImage,
82 typename TImageMask::Value valRemove)
84 for(
const auto &p : imageInput.domain())
86 if (maskImage(p) == valRemove)
88 imageInput.setValue(p,0);
94 template<
typename TImage,
typename TRescale>
96 exportImageUCHAR(TImage img,
const std::string resName, TRescale rScale)
100 for (
const auto p: img.domain() ) {
101 res.setValue(p, rScale(img(p)));
108 int main(
int argc,
char** argv )
116 std::string inputFileName;
117 std::string outputFileName {
"result.vol"};
120 int maskRemoveLabel {0};
121 string inputMask {
""};
122 string inputType {
""};
124 app.description(
"Converts itk file into a volumetric file (.vol, .pgm3d). \n Example:\n itk2vol image.mhd sample.vol --inputMin -500 --inputMax -100 \n");
125 app.add_option(
"-i,--input,1", inputFileName,
"Any file format in the ITK library (mhd, mha, ...)." )
127 ->check(CLI::ExistingFile);
128 app.add_option(
"-o,--output,2", outputFileName,
"volumetric file (.vol, .pgm3d).");
129 app.add_option(
"-m,--maskImage", inputMask,
"Use a mask image to remove image part (where mask is 0). The default mask value can be changed using mask default value.");
130 app.add_option(
"-r,--maskRemoveLabel", maskRemoveLabel,
"Change the label value that defines the part of input image to be removed by the option --maskImage." );
131 app.add_option(
"--inputMin", inputMin,
"set minimum density threshold on Hounsfield scale.");
132 app.add_option(
"--inputMax", inputMax,
"set maximum density threshold on Hounsfield scale.");
133 app.add_option(
"-t,--inputType", inputType,
"to specify the input image type (int or double).")
134 -> check(CLI::IsMember({
"int",
"double"}));
136 app.get_formatter()->column_width(40);
137 CLI11_PARSE(app, argc, argv);
141 if (inputType ==
"double") {
143 trace.
info() <<
"Reading input file (of type double)" << inputFileName ;
145 trace.
info() <<
" [done] " << std::endl ;
146 trace.
info() <<
" converting into vol file... " ;
147 if ( inputMask !=
"")
150 applyMaskImage(inputImage, maskImage, maskRemoveLabel);
152 RescalFCT rescaleCustom(inputMin, inputMax, 0, 255);
153 exportImageUCHAR(inputImage,outputFileName, rescaleCustom );
156 trace.
info() <<
"Reading input file (of type int) " << inputFileName ;
158 trace.
info() <<
" [done] " << std::endl ;
159 trace.
info() <<
" converting into vol file... " ;
160 RescalFCT rescaleCustom(inputMin, inputMax, 0, 255);
161 exportImageUCHAR(inputImage,outputFileName, rescaleCustom );
164 trace.
info() <<
" [done] " << std::endl ;
int main(int argc, char **argv)
Trace trace(traceWriterTerm)
static bool exportFile(const std::string &filename, const TContainer &anImage, const TFunctor &aFunctor=TFunctor())