30 #include <DGtal/base/Common.h>
31 #include <DGtal/helpers/StdDefs.h>
32 #include "DGtal/io/readers/GenericReader.h"
33 #include "DGtal/io/writers/GenericWriter.h"
35 #include <DGtal/images/ImageContainerBySTLVector.h>
36 #include <DGtal/images/ConstImageAdapter.h>
37 #include <boost/program_options/options_description.hpp>
38 #include <boost/program_options/parsers.hpp>
39 #include <boost/program_options/variables_map.hpp>
43 using namespace DGtal;
46 namespace po = boost::program_options;
93 void missingParam ( std::string param )
95 trace.
error() <<
" Parameter: "<<param<<
" is required..";
101 int main(
int argc,
char**argv)
105 po::options_description general_opt (
"Allowed options are: " );
106 general_opt.add_options()
107 (
"help,h",
"display this message." )
108 (
"input,i", po::value<std::string>(),
"Input vol file." )
109 (
"imagePlane",po::value<std::vector <unsigned int> >()->multitoken(),
110 "arg= {0,1,2} x {0,1,2} defines the axis of the slice image which will be transformed (by default arg= 0 1 i.e. the slice image defined in the X,Y plane (Z=cst)" )
111 (
"flipDimension", po::value<unsigned int>(),
"specify which axis will be used to apply the flip." )
112 (
"output,o", po::value<string>()->default_value(
"output.vol"),
"Output filename." );
115 po::variables_map vm;
119 po::store ( po::parse_command_line ( argc, argv, general_opt ), vm );
120 }
catch(
const std::exception& ex){
122 trace.
info()<<
"Error checking program options: "<< ex.what()<< endl;
125 if (!parseOK || ! ( vm.count (
"input" ) ) || ! ( vm.count (
"output" ) ) || ! ( vm.count (
"imagePlane" ) )
126 || ! ( vm.count (
"flipDimension" ) ) || vm.count (
"help" ))
128 trace.
info() <<
"Flip 2D slice image of an 3D vol image (mirror transformation)"<<std::endl
129 << std::endl <<
"Basic usage: "<<std::endl
130 <<
"\t volFlip --input <volFileName> --imagePlane 0 1 --flipDimension 0 --o <volOutputFileName> (vol, longvol, p3d format)"<<std::endl
131 << general_opt <<
"\n";
132 std::cout <<
"Example:\n"
133 <<
"volFlip --imagePlane 0 1 --flipDimension 0 -i ${DGtal}/examples/samples/lobster.vol -o flippedXxyLobster.p3d \n The resulting Z slice images (Z= cst) of flippedXxyLobster.p3d will appears flipped according the x axis. ";
139 if ( ! ( vm.count (
"input" ) ) ) missingParam (
"--input" );
140 if ( ! ( vm.count (
"output" ) ) ) missingParam (
"--output" );
141 if ( ! ( vm.count (
"imagePlane" ) ) || vm[
"imagePlane"].as<std::vector<unsigned int > >().size()!=2 ) missingParam (
"--imagePlane" );
142 if ( ! ( vm.count (
"flipDimension" ) ) ) missingParam (
"--flipDimension" );
145 std::string inputFilename = vm[
"input"].as<std::string>();
146 std::string outputFileName = vm[
"output"].as<std::string>();
148 unsigned int dimFirstImg = vm[
"imagePlane"].as<std::vector<unsigned int > >().at(0);
149 unsigned int dimSecondImg = vm[
"imagePlane"].as<std::vector<unsigned int > >().at(1);
150 unsigned int dimFlip = vm[
"flipDimension"].as<
unsigned int>();
152 unsigned int normalImgDim = (dimFirstImg!=2 && dimSecondImg!=2)? 2 :( (dimFirstImg!=1 && dimSecondImg!=1)? 1: 0 );
159 Image3D imageRes(imageSRC.
domain());
160 for(
int i=0; i <= imageSRC.
domain().upperBound()[normalImgDim]; i++){
161 Point startPoint(0,0, 0);
162 startPoint[normalImgDim]=i;
164 it = imageSRC.
domain().subRange(dimFirstImg, dimSecondImg,
166 itend = imageSRC.
domain().subRange(dimFirstImg, dimSecondImg, startPoint).end();
169 pt[dimFlip]= imageSRC.
domain().upperBound()[dimFlip] - pt[dimFlip] ;
170 imageRes.setValue(*it, imageSRC(pt));
178 if (res)
return 0;
else return 1;
void beginBlock(const std::string &keyword="")
Trace trace(traceWriterTerm)
const Domain & domain() const
typename Self::Point Point