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>
41 using namespace DGtal;
92 void missingParam ( std::string param )
94 trace.error() <<
" Parameter: "<<param<<
" is required..";
95 trace.info() <<std::endl;
100 int main(
int argc,
char**argv)
105 std::string inputFileName;
106 std::string outputFileName {
"result.vol"};
108 std::vector <unsigned int> vectImgPlane {0,1};
109 unsigned int dimFlip {0};
111 app.description(
"Flip 2D slice image of an 3D vol image (mirror transformation)\nBasic usage:\n \t volFlip --input <volFileName> --imagePlane 0 1 --flipDimension 0 --o <volOutputFileName> (vol, longvol, p3d format)\n Example:\n volFlip --imagePlane 0 1 --flipDimension 0 -i ${DGtal}/examples/samples/lobster.vol -o flippedXxyLobster.vol \n The resulting Z slice images (Z= cst) of flippedXxyLobster.p3d will appears flipped according the x axis. \n");
112 app.add_option(
"-i,--input,1", inputFileName,
"Input vol file." )
114 ->check(CLI::ExistingFile);
116 app.add_option(
"--imagePlane", vectImgPlane,
"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)",
true)
118 app.add_option(
"--flipDimension",dimFlip,
"specify which axis will be used to apply the flip.",
true);
119 app.add_option(
"-o,--output, 2",outputFileName,
"Output filename.",
true );
122 app.get_formatter()->column_width(40);
123 CLI11_PARSE(app, argc, argv);
127 unsigned int dimFirstImg = vectImgPlane.at(0);
128 unsigned int dimSecondImg = vectImgPlane.at(1);
130 unsigned int normalImgDim = (dimFirstImg!=2 && dimSecondImg!=2)? 2 :( (dimFirstImg!=1 && dimSecondImg!=1)? 1: 0 );
133 trace.beginBlock(
"Loading file");
134 typedef ImageContainerBySTLVector<Z3i::Domain, unsigned char> Image3D;
135 Image3D imageSRC = GenericReader<Image3D>::import ( inputFileName );
137 Image3D imageRes(imageSRC.domain());
138 for(
int i=0; i <= imageSRC.domain().upperBound()[normalImgDim]; i++){
139 Point startPoint(0,0, 0);
140 startPoint[normalImgDim]=i;
141 for( Domain::ConstSubRange::ConstIterator
142 it = imageSRC.domain().subRange(dimFirstImg, dimSecondImg,
144 itend = imageSRC.domain().subRange(dimFirstImg, dimSecondImg, startPoint).end();
147 pt[dimFlip]= imageSRC.domain().upperBound()[dimFlip] - pt[dimFlip] ;
148 imageRes.setValue(*it, imageSRC(pt));
152 trace.beginBlock(
"Exporting...");
153 bool res = VolWriter<Image3D>::exportVol(outputFileName, imageRes);
155 if (res)
return 0;
else return 1;