29 #include <DGtal/base/Common.h>
30 #include <DGtal/io/readers/VolReader.h>
31 #include <DGtal/io/writers/VolWriter.h>
32 #include <DGtal/helpers/StdDefs.h>
33 #include <DGtal/images/Image.h>
34 #include <DGtal/images/ImageContainerBySTLVector.h>
36 #include <boost/program_options/options_description.hpp>
37 #include <boost/program_options/parsers.hpp>
38 #include <boost/program_options/variables_map.hpp>
41 using namespace DGtal;
44 namespace po = boost::program_options;
98 void missingParam ( std::string param )
100 trace.
error() <<
" Parameter: "<<param<<
" is required..";
105 template<
typename Val,
typename Image,
typename Po
int,
typename Domain>
113 if ( domain.isInside(*it) && image( *it) > v) v=image(*it);
117 template<
typename Val,
typename Image,
typename Po
int,
typename Domain>
125 if ( domain.isInside(*it)&& image( *it) < v) v=image(*it);
129 template<
typename Val,
typename Image,
typename Po
int,
typename Domain>
138 if ( domain.isInside(*it) )
143 return static_cast<unsigned char>( v/nb );
147 int main(
int argc,
char**argv)
151 po::options_description general_opt (
"Allowed options are: " );
152 general_opt.add_options()
153 (
"help,h",
"display this message." )
154 (
"input,i", po::value<std::string>(),
"Input vol file." )
155 (
"output,o", po::value<string>(),
"Output filename." )
156 (
"function,f", po::value<string>()->default_value(
"mean"),
"Function used to the down-sampling: {none,max, min, mean}" );
159 po::variables_map vm;
160 po::store ( po::parse_command_line ( argc, argv, general_opt ), vm );
162 if ( vm.count (
"help" ) ||argc<=1 )
164 trace.
info() <<
"Brutally sub sample a vol file (division by 2 in each direction)."<<std::endl
165 << std::endl <<
"Basic usage: "<<std::endl
166 <<
"\tvolSubSample --input <volFileName> --o <volOutputFileName> "<<std::endl
167 << general_opt <<
"\n";
172 if ( ! ( vm.count (
"input" ) ) ) missingParam (
"--input" );
173 std::string filename = vm[
"input"].as<std::string>();
174 std::string
function = vm[
"function"].as<std::string>();
175 if ( ! ( vm.count (
"output" ) ) ) missingParam (
"--output" );
176 std::string outputFileName = vm[
"output"].as<std::string>();
183 MyImageC outputImage(
Z3i::Domain( imageC.domain().lowerBound(),
184 (imageC.domain().upperBound()-imageC.domain().lowerBound())/
Vector().
diagonal(2)));
191 trace.
info()<<
"Function= "<<
function<<std::endl;
192 trace.
info() << outputImage.domain() << std::endl;
194 if (
function ==
"none")
195 for(MyImageC::Domain::ConstIterator it = outputImage.domain().begin(),
196 itend = outputImage.domain().end(); it != itend; ++it)
199 outputImage.setValue( *it , imageC( p ));
202 if (
function ==
"max")
203 for(MyImageC::Domain::ConstIterator it = outputImage.domain().begin(),
204 itend = outputImage.domain().end(); it != itend; ++it)
206 val = maxVal<unsigned char, MyImageC, Point>(imageC, *it, imageC.domain());
207 outputImage.setValue( *it , val );
210 if (
function ==
"min")
211 for(MyImageC::Domain::ConstIterator it = outputImage.domain().begin(),
212 itend = outputImage.domain().end(); it != itend; ++it)
214 val = minVal<unsigned char, MyImageC, Point>(imageC, *it, imageC.domain());
215 outputImage.setValue( *it , val);
219 if (
function ==
"mean")
220 for(MyImageC::Domain::ConstIterator it = outputImage.domain().begin(),
221 itend = outputImage.domain().end(); it != itend; ++it)
223 val = meanVal<unsigned char, MyImageC, Point>(imageC, *it, imageC.domain());
224 outputImage.setValue( *it , val );
235 if (res)
return 0;
else return 1;
void beginBlock(const std::string &keyword="")
static Self diagonal(Component val=1)
Trace trace(traceWriterTerm)
typename Self::Point Point
std::vector< Value >::const_iterator ConstIterator
typename Self::Domain Domain