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>
40 using namespace DGtal;
112 void missingParam ( std::string param )
114 trace.error() <<
" Parameter: "<<param<<
" is required..";
115 trace.info() <<std::endl;
119 template<
typename Val,
typename Image,
typename Po
int,
typename Domain>
120 Val maxVal(Image
const& image, Point
const& p, Domain
const& domain)
122 typename Image::Domain dom( p*2, p*2 + Point::diagonal(1));
124 for(
typename Image::Domain::ConstIterator it=dom.begin(), itend=dom.end();
127 if ( domain.isInside(*it) && image( *it) > v) v=image(*it);
131 template<
typename Val,
typename Image,
typename Po
int,
typename Domain>
132 Val minVal(Image
const& image, Point
const& p, Domain
const& domain)
134 typename Image::Domain dom( p*2, p*2 + Point::diagonal(1));
136 for(
typename Image::Domain::ConstIterator it=dom.begin(), itend=dom.end();
139 if ( domain.isInside(*it)&& image( *it) < v) v=image(*it);
143 template<
typename Val,
typename Image,
typename Po
int,
typename Domain>
144 Val meanVal(Image
const& image, Point
const& p, Domain
const& domain)
146 typename Image::Domain dom( p*2, p*2 + Point::diagonal(1));
149 for(
typename Image::Domain::ConstIterator it=dom.begin(), itend=dom.end();
152 if ( domain.isInside(*it) )
157 return static_cast<unsigned char>( v/nb );
161 int main(
int argc,
char**argv)
167 std::string inputFileName;
168 std::string outputFileName {
"result.vol"};
169 std::string
function {
"mean"};
171 app.description(
"Brutally sub sample a vol file (division by 2 in each direction).\n Basic usage: \n \tvolSubSample <volFileName> <volOutputFileName> ");
174 app.add_option(
"-i,--input,1", inputFileName,
"Input vol file." )
176 ->check(CLI::ExistingFile);
177 app.add_option(
"-o,--output,2", outputFileName,
"Output filename.",
true);
178 app.add_option(
"-f,--function",
function,
"Function used to the down-sampling: {none,max, min, mean}",
true)
179 -> check(CLI::IsMember({
"mean",
"none",
"max",
"min",
"mean"}));
181 app.get_formatter()->column_width(40);
182 CLI11_PARSE(app, argc, argv);
186 trace.beginBlock(
"Loading file");
187 typedef ImageContainerBySTLVector<Z3i::Domain, unsigned char> MyImageC;
189 MyImageC imageC = VolReader< MyImageC >::importVol ( inputFileName );
190 MyImageC outputImage( Z3i::Domain( imageC.domain().lowerBound(),
191 (imageC.domain().upperBound()-imageC.domain().lowerBound())/Vector().
diagonal(2)));
194 Point subvector = Vector().diagonal(2);
197 trace.beginBlock(
"Down-scaling the volume...");
198 trace.info()<<
"Function= "<<
function<<std::endl;
199 trace.info() << outputImage.domain() << std::endl;
201 if (
function ==
"none")
202 for(MyImageC::Domain::ConstIterator it = outputImage.domain().begin(),
203 itend = outputImage.domain().end(); it != itend; ++it)
206 outputImage.setValue( *it , imageC( p ));
209 if (
function ==
"max")
210 for(MyImageC::Domain::ConstIterator it = outputImage.domain().begin(),
211 itend = outputImage.domain().end(); it != itend; ++it)
213 val = maxVal<unsigned char, MyImageC, Point>(imageC, *it, imageC.domain());
214 outputImage.setValue( *it , val );
217 if (
function ==
"min")
218 for(MyImageC::Domain::ConstIterator it = outputImage.domain().begin(),
219 itend = outputImage.domain().end(); it != itend; ++it)
221 val = minVal<unsigned char, MyImageC, Point>(imageC, *it, imageC.domain());
222 outputImage.setValue( *it , val);
226 if (
function ==
"mean")
227 for(MyImageC::Domain::ConstIterator it = outputImage.domain().begin(),
228 itend = outputImage.domain().end(); it != itend; ++it)
230 val = meanVal<unsigned char, MyImageC, Point>(imageC, *it, imageC.domain());
231 outputImage.setValue( *it , val );
234 trace.error() <<
"Bad function !"<<std::endl;
239 trace.beginBlock(
"Exporting...");
240 bool res = VolWriter< MyImageC>::exportVol(outputFileName, outputImage);
242 if (res)
return 0;
else return 1;
DGtal::LinearOperator< Calculus, dim, duality, dim, duality > diagonal(const DGtal::KForm< Calculus, dim, duality > &kform)