Skip to content

Commit

Permalink
Merge pull request #393 from kerautret/FixITK2vol
Browse files Browse the repository at this point in the history
Fix itk2vol (issue #390)
  • Loading branch information
kerautret authored Apr 7, 2021
2 parents 33480a8 + 8ee04a6 commit dda16f1
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 22 deletions.
3 changes: 3 additions & 0 deletions .travis/install_deps_macos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
#
# Note: gmp and boost already installed
#
brew install ccache
export PATH="/usr/local/opt/ccache/libexec:$PATH"

brew update > brew.log
#brew install qt5 doxygen homebrew/science/hdf5 graphviz graphicsmagick fftw eigen
brew install qt5 graphicsmagick fftw eigen
Expand Down
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ SET(VERSION ${DGtalTools_VERSION_MAJOR}.${DGtalTools_VERSION_MINOR}.${DGtalTools



#-----------------------------------------------------------------------------
# ITK setting
#-----------------------------------------------------------------------------
if ( WITH_ITK )
include(${ITK_USE_FILE})
ENDIF( WITH_ITK )


# -----------------------------------------------------------------------------
# Documentation
Expand Down
9 changes: 8 additions & 1 deletion ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
# DGtalTools 1.2
- *global*
- Fix itk2vol and fix ITK cmake configuaration that was making wrong the ITK image read.
(Bertrand Kerautret [#393](https://github.com/DGtal-team/DGtalTools/pull/393))
<<<<<<< HEAD




=======
- 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))
>>>>>>> bf6f26204de31698d991a81f19627f225426d146
# DGtalTools 1.1

Expand Down
41 changes: 20 additions & 21 deletions converters/itk2vol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ using namespace DGtal;
*/

typedef ImageContainerBySTLVector < Z3i::Domain, unsigned char > Image3DChar;


template<typename TImage, typename TImageMask>
Expand All @@ -90,12 +91,22 @@ applyMaskImage( TImage &imageInput, const TImageMask &maskImage,

}

template<typename TImage, typename TRescale>
void
exportImageUCHAR(TImage img, const std::string resName, TRescale rScale)
{
Image3DChar res ( img.domain() );

for (const auto p: img.domain() ) {
res.setValue(p, rScale(img(p)));
}
DGtal::GenericWriter<Image3DChar, 3, unsigned char>::exportFile(resName, res);
}



int main( int argc, char** argv )
{
typedef ImageContainerBySTLVector < Z3i::Domain, unsigned char > Image3DChar;
typedef ImageContainerBySTLVector < Z3i::Domain, double > Image3D_D;
typedef ImageContainerBySTLVector < Z3i::Domain, int > Image3D_I;

Expand All @@ -119,7 +130,7 @@ int main( int argc, char** argv )
app.add_option("-r,--maskRemoveLabel", maskRemoveLabel,"Change the label value that defines the part of input image to be removed by the option --maskImage." );
app.add_option("--inputMin", inputMin, "set minimum density threshold on Hounsfield scale.");
app.add_option("--inputMax", inputMax, "set maximum density threshold on Hounsfield scale.");
app.add_option("-t,--inputType", inputType, "to sepcify the input image type (int or double).")
app.add_option("-t,--inputType", inputType, "to specify the input image type (int or double).")
-> check(CLI::IsMember({"int", "double"}));

app.get_formatter()->column_width(40);
Expand All @@ -129,39 +140,27 @@ int main( int argc, char** argv )

if (inputType == "double") {
typedef DGtal::functors::Rescaling<double ,unsigned char > RescalFCT;
trace.info() << "Reading input input file " << inputFileName ;
Image3D_D inputImage = ITKReader< Image3D_D >::importITK(inputFileName);
trace.info() << "Reading input file (of type double)" << inputFileName ;
Image3D_D inputImage = ITKReader< Image3D_D >::importITK(inputFileName, true);
trace.info() << " [done] " << std::endl ;
trace.info() << " converting into vol file... " ;
if ( inputMask != "")
{
Image3D_I maskImage = ITKReader< Image3D_I >::importITK(inputMask);
applyMaskImage(inputImage, maskImage, maskRemoveLabel);
}

RescalFCT rescaleCustom(inputMin, inputMax, 0, 255);
DGtal::GenericWriter<Image3D_D, 3, unsigned char, RescalFCT>::exportFile(outputFileName,
inputImage,
"UInt8Array3D",
rescaleCustom);
exportImageUCHAR(inputImage,outputFileName, rescaleCustom );
}else {
typedef DGtal::functors::Rescaling<int ,unsigned char > RescalFCT;
trace.info() << "Reading input input file " << inputFileName ;
Image3D_I inputImage = ITKReader< Image3D_I >::importITK(inputFileName);
trace.info() << "Reading input file (of type int) " << inputFileName ;
Image3D_I inputImage = ITKReader< Image3D_I >::importITK(inputFileName, true);
trace.info() << " [done] " << std::endl ;
trace.info() << " converting into vol file... " ;
RescalFCT rescaleCustom(inputMin, inputMax, 0, 255);
if (inputMask != "")
{
Image3D_I maskImage = ITKReader< Image3D_I >::importITK(inputMask);
applyMaskImage(inputImage, maskImage, maskRemoveLabel);
exportImageUCHAR(inputImage,outputFileName, rescaleCustom );

}

DGtal::GenericWriter<Image3D_I, 3, unsigned char, RescalFCT>::exportFile(outputFileName,
inputImage,
"UInt8Array3D",
rescaleCustom);
}
trace.info() << " [done] " << std::endl ;
return EXIT_SUCCESS;
}

0 comments on commit dda16f1

Please sign in to comment.