Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uniform IO options in tools #406

Merged
merged 10 commits into from
May 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
(Bertrand Kerautret [#393](https://github.com/DGtal-team/DGtalTools/pull/393))
- Travis: Fix old default osx_image with xcode12.2 and remove non used boost
cmake references. (Bertrand Kerautret [#394](https://github.com/DGtal-team/DGtalTools/pull/394))
- Uniform input/output option with previous use of CLI11 (issue #405).
(Bertrand Kerautret [#406](https://github.com/DGtal-team/DGtalTools/pull/406))
- Comply with cmake Policy CMP0115 "Source file extensions must be
explicit". (Bertrand Kerautret and David Coeurjolly, [#407](https://github.com/DGtal-team/DGtal/pull/407))

Expand Down
8 changes: 2 additions & 6 deletions converters/convertVol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ using namespace DGtal;

@b Examples:
@code
$ convertVol -i ${DGtal}/examples/samples/lobster.vol -o convertedVol.p3d
$ convertVol ${DGtal}/examples/samples/lobster.vol convertedVol.p3d
@endcode

To upgrade a "Version-2" vol file to a "Version-3" (default Vol writer):
@code
$ convertVol -i ${DGtal}/examples/samples/lobster.vol -o ${DGtal}/examples/samples/lobster.vol
$ convertVol ${DGtal}/examples/samples/lobster.vol ${DGtal}/examples/samples/lobster.vol
@endcode


Expand Down Expand Up @@ -102,7 +102,3 @@ int main( int argc, char** argv )

return EXIT_SUCCESS;
}




3 changes: 2 additions & 1 deletion converters/dicom2vol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ using namespace DGtal;
@code
Positionals:
1 TEXT:FILE REQUIRED dicom image (.dcm).
2 TEXT:FILE volumetric file (.vol, .longvol .pgm3d, .raw).

Options:
-h,--help Print this help message and exit
Expand Down Expand Up @@ -86,7 +87,7 @@ int main( int argc, char** argv )
DGtal::int64_t dicomMin {-1000};
DGtal::int64_t dicomMax {3000};

app.description("Convert dicom file into a volumetric file (.vol, .longvol .pgm3d).\n Example:\n dicom2vol -i ${DGtal}/tests/samples/dicomSample/1629.dcm --dicomMin 0 --dicomMax 300 -o sample.vol.");
app.description("Convert dicom file into a volumetric file (.vol, .longvol .pgm3d).\n Example:\n dicom2vol ${DGtal}/tests/samples/dicomSample/1629.dcm sample.vol --dicomMin 0 --dicomMax 300.");
app.add_option("-i,--input,1", inputFileName, "dicom image (.dcm)." )
->required()
->check(CLI::ExistingFile);
Expand Down
14 changes: 5 additions & 9 deletions converters/freeman2img.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,23 +65,20 @@ using namespace DGtal;

Positionals:
1 TEXT:FILE REQUIRED Input freeman chain file name.
2 TEXT:FILE the output file name.

Options:

Positionals:
1 TEXT:FILE REQUIRED Input freeman chain file name.

Options:
-h,--help Print this help message and exit
-i,--input TEXT:FILE REQUIRED Input freeman chain file name.
-b,--border UINT add a border in the resulting image (used only in the automatic mode i.e when --space is not used.
-o,--output TEXT=result.pgm the output fileName
-o,--output TEXT=result.pgm the output file name
-s,--space INT x 4 Define the space from its bounding box (lower and upper coordinates) else the space is automatically defined from the freemanchain bounding boxes.
@endcode

@b Example:
@code
$freeman2img -i ${DGtal}/tests/samples/contourS.fc -o sample.pgm
$freeman2img ${DGtal}/tests/samples/contourS.fc sample.pgm
@endcode
You will obtain such image:
@image html resFreeman2img.png "Resulting image"
Expand All @@ -92,7 +89,7 @@ You will obtain such image:
The file located in $DGtal/examples/samples/contourS2.fc contains different contours with some ones corresponds to hole. We can apply the same conversion as the previous example:

@code
$ freeman2img -i $DGtal/examples/samples/contourS2.fc -o sample2.pgm
$ freeman2img $DGtal/examples/samples/contourS2.fc sample2.pgm
@endcode

You will obtain such image:
Expand Down Expand Up @@ -121,7 +118,7 @@ int main( int argc, char** argv )
->required()
->check(CLI::ExistingFile);
app.add_option("-b,--border",border, "add a border in the resulting image (used only in the automatic mode i.e when --space is not used.");
app.add_option("-o,--output", outputFileName, "the output fileName", true);
app.add_option("-o,--output,2", outputFileName, "the output fileName", true);
app.add_option("-s,--space", space, "Define the space from its bounding box (lower and upper coordinates) else the space is automatically defined from the freemanchain bounding boxes." )
->expected(4);

Expand Down Expand Up @@ -177,7 +174,6 @@ int main( int argc, char** argv )
Image2D imageResult (Z2i::Domain(Z2i::Point(minx, miny), Z2i::Point(maxx, maxy)));
Surfaces<KSpace>::uFillInterior(aKSpace, functors::SurfelSetPredicate<std::set<SCell>,SCell>(boundarySCell), imageResult, 255, false, false );
imageResult >> outputFileName;


}

2 changes: 1 addition & 1 deletion converters/freeman2sdp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ int main( int argc, char** argv )
bool oneline {false};
bool info {false};

app.description("Transform freeman chain into a Sequence of Discrete Points. Result is given to std output.\n Example:\n freeman2sdp -i ${DGtal}/tests/samples/contourS.fc > contourS.sdp \n");
app.description("Transform freeman chain into a Sequence of Discrete Points. Result is given to std output.\n Example:\n freeman2sdp ${DGtal}/tests/samples/contourS.fc > contourS.sdp \n");
app.add_option("-i,--input,1", inputFileName, "Input freeman chain file name." )
->required()
->check(CLI::ExistingFile);
Expand Down
6 changes: 3 additions & 3 deletions converters/heightfield2vol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
*
* @date 2015/03/18
*
*
*
* This file is part of the DGtalTools.
*/
Expand Down Expand Up @@ -70,7 +69,7 @@ using namespace DGtal;

@b Example:
@code
$ heightfield2vol -i ${DGtal}/examples/samples/church.pgm -o volResu.vol -s 0.3 -z 50
$ heightfield2vol ${DGtal}/examples/samples/church.pgm volResu.vol -s 0.3 -z 50

@endcode
You will obtain such image:
Expand Down Expand Up @@ -134,8 +133,9 @@ int main( int argc, char** argv )
unsigned int maxZ {255};


app.description("Convert a 2D heightfield image into a volumetric file.\n Example: \n heightfield2vol -i ${DGtal}/examples/samples/church.pgm -o volResu.vol -s 0.3 -z 50 \n");
app.description("Convert a 2D heightfield image into a volumetric file.\n Example: \n heightfield2vol ${DGtal}/examples/samples/church.pgm volResu.vol -s 0.3 -z 50 \n");
app.add_option("-i,--input,1", inputFileName, "input heightfield file (2D image).")
->check(CLI::ExistingFile)
->required();
app.add_option("-o,--output,2", outputFileName,"output volumetric file.", true);
app.add_option("-s,--scale", scale, "set the scale factor on height values (default 1.0)");
Expand Down
21 changes: 7 additions & 14 deletions converters/img2freeman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ using namespace DGtal;

@b Example:
@code
$ img2freeman -i ${DGtal}/examples/samples/church.pgm > contours.fc
$ img2freeman ${DGtal}/examples/samples/church.pgm > contours.fc

@endcode
You will obtain such results:
Expand Down Expand Up @@ -74,13 +74,9 @@ more contours.fc
*/





typedef ImageSelector < Z2i::Domain, unsigned char>::Type Image;



std::vector<unsigned int> getHistoFromImage(const Image &image){
const Image::Domain &imgDom = image.domain();
std::vector<unsigned int> vectHisto(UCHAR_MAX);
Expand All @@ -90,8 +86,6 @@ std::vector<unsigned int> getHistoFromImage(const Image &image){
return vectHisto;
}



unsigned int
getOtsuThreshold(const Image &image){
std::vector<unsigned int> histo = getHistoFromImage(image);
Expand Down Expand Up @@ -272,10 +266,10 @@ int main( int argc, char** argv )
}else{
for(int i=0; minThreshold+i*increment< maxThreshold; i++){
if(vectRangeMin.size()==3){
min = (int)(minThreshold+(i)*increment);
min = (int)(minThreshold+(i)*increment);
}
if(vectRangeMax.size()==3){
max = (int)(maxThreshold-(i)*increment);
max = (int)(maxThreshold-(i)*increment);
}
Binarizer b(min, max);
functors::PointFunctorPredicate<Image,Binarizer> predicate(image, b);
Expand All @@ -286,15 +280,14 @@ int main( int argc, char** argv )
Surfaces<Z2i::KSpace>::extractAllPointContours4C( vectContoursBdryPointels,
ks, predicate, sAdj );
if(select){
saveSelContoursAsFC(vectContoursBdryPointels, minSize, selectCenter, selectDistanceMax, sortCnt);
saveSelContoursAsFC(vectContoursBdryPointels, minSize,
selectCenter, selectDistanceMax, sortCnt);
}else{
saveAllContoursAsFc(vectContoursBdryPointels, minSize, sortCnt);
saveAllContoursAsFc(vectContoursBdryPointels,
minSize, sortCnt);
}
trace.info() << " [done]" << std::endl;
}
}



}

4 changes: 2 additions & 2 deletions converters/imgAddNoise.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ using namespace DGtal;

@b Example:
@code
$ imgAddNoise -i ${DGtal}/examples/samples/klokan.pgm -o noise.pgm
$ imgAddNoise ${DGtal}/examples/samples/klokan.pgm noise.pgm

@endcode
You will obtain such image:
Expand Down Expand Up @@ -100,7 +100,7 @@ int main( int argc, char** argv )
std::string outputFileName {"result.png"};
double noise {0.5};

app.description("Add Kanungo noise to a binary object with 0 values as background points and values >0 for the foreground ones.\n Example: \n imgAddNoise -i ${DGtal}/examples/samples/klokan.pgm -o noise.pgm ");
app.description("Add Kanungo noise to a binary object with 0 values as background points and values >0 for the foreground ones.\n Example: \n imgAddNoise ${DGtal}/examples/samples/klokan.pgm noise.pgm ");
app.add_option("-i,--input,1", inputFileName, "input image file name (any 2D image format accepted by DGtal::GenericReader)." )
->required()
->check(CLI::ExistingFile);
Expand Down
4 changes: 2 additions & 2 deletions converters/itk2vol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ using namespace DGtal;

@b Example:
@code
$itk2vol -i image.mhd --dicomMin -500 --dicomMax -100 -o sample.vol
$itk2vol image.mhd sample.vol --dicomMin -500 --dicomMax -100
@endcode

@see itk2vol.cpp
Expand Down Expand Up @@ -121,7 +121,7 @@ int main( int argc, char** argv )
string inputMask {""};
string inputType {""};

app.description("Converts itk file into a volumetric file (.vol, .pgm3d). \n Example:\n itk2vol -i image.mhd --inputMin -500 --inputMax -100 -o sample.vol \n");
app.description("Converts itk file into a volumetric file (.vol, .pgm3d). \n Example:\n itk2vol image.mhd sample.vol --inputMin -500 --inputMax -100 \n");
app.add_option("-i,--input,1", inputFileName, "Any file format in the ITK library (mhd, mha, ...)." )
->required()
->check(CLI::ExistingFile);
Expand Down
2 changes: 1 addition & 1 deletion converters/longvol2vol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ using namespace Z3i;

@b Example:
@code
$ longvol2vol -i ${DGtal}/tests/samples/test.longvol -o out.vol
$ longvol2vol ${DGtal}/tests/samples/test.longvol out.vol
@endcode

@see longvol2vol.cpp
Expand Down
2 changes: 1 addition & 1 deletion converters/mesh2heightfield.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ int main( int argc, char** argv )
double nz{1};


app.description("Convert a mesh file into a projected 2D image given from a normal direction N and from a starting point P. The 3D mesh discretized and scanned in the normal direction N, starting from P with a step 1.\n Example:\n mesh2heightfield -i ${DGtal}/examples/samples/tref.off --orientAutoFrontZ --width 25 --height 25 -o heighMap.pgm -s 10 \n");
app.description("Convert a mesh file into a projected 2D image given from a normal direction N and from a starting point P. The 3D mesh discretized and scanned in the normal direction N, starting from P with a step 1.\n Example:\n mesh2heightfield ${DGtal}/examples/samples/tref.off heighMap.pgm --orientAutoFrontZ --width 25 --height 25 -s 10 \n");
app.add_option("-i,--input,1", inputFileName, "mesh file (.off)" )
->required()
->check(CLI::ExistingFile);
Expand Down
2 changes: 1 addition & 1 deletion converters/mesh2vol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ int main( int argc, char** argv )
unsigned int separation {6};
unsigned int resolution {128};

app.description("Convert a mesh file into a 26-separated or 6-separated volumetric voxelization in a given resolution grid. \n Example:\n mesh2vol -i ${DGtal}/examples/samples/tref.off -o output.vol --separation 26 --resolution 256 ");
app.description("Convert a mesh file into a 26-separated or 6-separated volumetric voxelization in a given resolution grid. \n Example:\n mesh2vol ${DGtal}/examples/samples/tref.off output.vol --separation 26 --resolution 256 ");

app.add_option("-i,--input,1", inputFileName, "mesh file (.off)." )
->required()
Expand Down
3 changes: 2 additions & 1 deletion converters/ofs2off.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ using namespace DGtal;
@code
Positionals:
1 TEXT:FILE REQUIRED ofs file (.ofs).
2 TEXT:FILE ofs file (.ofs).

Options:
-h,--help Print this help message and exit
Expand All @@ -61,7 +62,7 @@ using namespace DGtal;

@b Example:
@code
$ ofs2off -i input.ofs -o output.off
$ ofs2off input.ofs output.off
@endcode

@see ofs2off.cpp
Expand Down
3 changes: 2 additions & 1 deletion converters/raw2vol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ Allowed options are: :

Positionals:
1 TEXT:FILE REQUIRED Input raw file.
2 TEXT:FILE REQUIRED Input raw file.

Options:
-h,--help Print this help message and exit
Expand Down Expand Up @@ -99,7 +100,7 @@ int main(int argc, char**argv)
std::string inputFileName;
std::string outputFileName {"result.vol"};
unsigned int x, y, z;
app.description("Converts a 8-bit raw file to vol.\n Basic example:\n \t raw2vol -x 128 -y 128 -z 128 --input <RawFileName> --output <VolOutputFileName>");
app.description("Converts a 8-bit raw file to vol.\n Basic example:\n \t raw2vol <RawFileName> <VolOutputFileName> -x 128 -y 128 -z 128");
app.add_option("-i,--input,1", inputFileName, "Input raw file." )
->required()
->check(CLI::ExistingFile);
Expand Down
4 changes: 2 additions & 2 deletions converters/sdp2vol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ using namespace DGtal;

@b Example:
@code
$ sdp2vol -i volumePoints.sdp -o volume.vol -d 0 0 0 10 10 10
$ sdp2vol volumePoints.sdp volume.vol -d 0 0 0 10 10 10
@endcode

@see sdp2vol.cpp
Expand All @@ -92,7 +92,7 @@ int main( int argc, char** argv )
bool invertY {false};
std::vector<int> domainCoords;

app.description("Convert digital set of points into a volumic file.\n Example:\n sdp2vol -i volumePoints.sdp -o volume.vol -d 0 0 0 10 10 10 \n");
app.description("Convert digital set of points into a volumic file.\n Example:\n sdp2vol volumePoints.sdp volume.vol -d 0 0 0 10 10 10 \n");
app.add_option("-i,--input,1", inputSDP, "Sequence of 3d Discrete points (.sdp)." )
->required()
->check(CLI::ExistingFile);
Expand Down
14 changes: 6 additions & 8 deletions converters/vol2heightfield.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,13 @@ using namespace DGtal;

Positionals:
1 TEXT:FILE REQUIRED vol file (.vol, .longvol .p3d, .pgm3d and if WITH_ITK is selected: dicom, dcm, mha, mhd). For longvol, dicom, dcm, mha or mhd formats, the input values are linearly scaled between 0 and 255.
2 TEXT=result.pgm resulting image filename (in pgm or other).


Options:
-h,--help Print this help message and exit
-i,--input TEXT:FILE REQUIRED vol file (.vol, .longvol .p3d, .pgm3d and if WITH_ITK is selected: dicom, dcm, mha, mhd). For longvol, dicom, dcm, mha or mhd formats, the input values are linearly scaled between 0 and 255.
-o,--output TEXT sequence of discrete point file (.sdp)
-o,--output TEXT resulting image filename (in pgm or other)
-m,--thresholdMin INT=128 threshold min (excluded) to define binary shape.
-M,--thresholdMax INT=255 threshold max (included) to define binary shape.
--rescaleInputMin INT=0 min value used to rescale the input intensity (to avoid basic cast into 8 bits image).
Expand All @@ -83,7 +85,7 @@ using namespace DGtal;

@b Example:
@code
$ vol2heightfield -i ${DGtal}/examples/samples/lobster.vol -m 60 -M 500 --nx 0 --ny 0.7 --nz -1 -x 150 -y 0 -z 150 --width 300 --height 300 --heightFieldMaxScan 350 -o resultingHeightMap.pgm
$ vol2heightfield ${DGtal}/examples/samples/lobster.vol resultingHeightMap.pgm -m 60 -M 500 --nx 0 --ny 0.7 --nz -1 -x 150 -y 0 -z 150 --width 300 --height 300 --heightFieldMaxScan 350 resultingHeightMap.pgm
@endcode

You should obtain such a resulting image:
Expand All @@ -104,7 +106,7 @@ int main( int argc, char** argv )
// parse command line using CLI ----------------------------------------------
CLI::App app;
std::string inputFileName;
std::string outputFileName {"result.raw"};
std::string outputFileName {"result.pgm"};
int thresholdMin {128};
int thresholdMax {255};
DGtal::int64_t rescaleInputMin {0};
Expand All @@ -125,7 +127,7 @@ int main( int argc, char** argv )
app.add_option("-i,--input,1", inputFileName, "vol file (.vol, .longvol .p3d, .pgm3d and if WITH_ITK is selected: dicom, dcm, mha, mhd). For longvol, dicom, dcm, mha or mhd formats, the input values are linearly scaled between 0 and 255." )
->required()
->check(CLI::ExistingFile);
app.add_option("-o,--output", outputFileName, "sequence of discrete point file (.sdp)");
app.add_option("-o,--output,2", outputFileName, "resulting image filename (in pgm or other).");
app.add_option("--thresholdMin,-m", thresholdMin, "threshold min (excluded) to define binary shape.", true);
app.add_option("--thresholdMax,-M", thresholdMax, "threshold max (included) to define binary shape.", true);
app.add_option("--rescaleInputMin", rescaleInputMin, "min value used to rescale the input intensity (to avoid basic cast into 8 bits image).", true);
Expand Down Expand Up @@ -208,7 +210,3 @@ int main( int argc, char** argv )
trace.info() << " [done] " << std::endl ;
return EXIT_SUCCESS;
}




Loading