Skip to content

Commit 6f16368

Browse files
committed
Merge remote-tracking branch 'origin/master' into ShapeToDensityFeature
This merge to put image_to_mask feature inside ShapeToDensityFeature branch, to avoid conflicts later on.
2 parents 8cb68d0 + 9625d03 commit 6f16368

File tree

5 files changed

+194
-1
lines changed

5 files changed

+194
-1
lines changed

Anima/diffusion/odf/tod_estimator/animaTODEstimatorImageFilter.hxx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,20 @@ namespace anima
8484
for (int i = 0; i < nbPoints; i++)
8585
{
8686
DirType dir = GetFiberDirection(i, fiber);
87+
if(output->GetDirection()[0][0] > 0)
88+
{
89+
dir[0] *= -1;
90+
}
91+
if(output->GetDirection()[1][1] < 0)
92+
{
93+
dir[1] *= -1;
94+
}
95+
if(output->GetDirection()[2][2] < 0)
96+
{
97+
dir[2] *= -1;
98+
}
99+
100+
87101
PointType point = GetCenterVoxel(i, fiber);
88102
itk::Index<3> index;
89103

Anima/math-tools/common_tools/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ add_subdirectory(convert_shape)
88
add_subdirectory(merge_block_images)
99
add_subdirectory(shapes_to_density)
1010
add_subdirectory(vectorize_images)
11+
add_subdirectory(image_to_mask)
1112

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
if(BUILD_TOOLS)
2+
3+
project(animaImageToMask)
4+
5+
## #############################################################################
6+
## List Sources
7+
## #############################################################################
8+
9+
list_source_files(${PROJECT_NAME}
10+
${CMAKE_CURRENT_SOURCE_DIR}
11+
)
12+
13+
## add executable
14+
## #############################################################################
15+
16+
add_executable(${PROJECT_NAME}
17+
${${PROJECT_NAME}_CFILES}
18+
)
19+
20+
21+
## #############################################################################
22+
## Link
23+
## #############################################################################
24+
25+
target_link_libraries(${PROJECT_NAME}
26+
${ITKIO_LIBRARIES}
27+
)
28+
29+
## #############################################################################
30+
## install
31+
## #############################################################################
32+
33+
set_exe_install_rules(${PROJECT_NAME})
34+
35+
endif()
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
#include <tclap/CmdLine.h>
2+
#include <iostream>
3+
#include <string>
4+
5+
#include <itkImage.h>
6+
#include <itkVectorImage.h>
7+
#include <itkImageRegionIterator.h>
8+
9+
#include <animaReadWriteFunctions.h>
10+
11+
/**
12+
* @brief Converts an input image (either vectorial or not) into a mask
13+
* The output mask will be 0 in the voxels where the input image is 0 (or a null vector) and 1 elsewhere
14+
*/
15+
int main(int argc, char **argv)
16+
{
17+
TCLAP::CmdLine cmd("INRIA / IRISA - VisAGeS/Empenn Team", ' ',ANIMA_VERSION);
18+
19+
//Define arguments
20+
TCLAP::ValueArg<std::string> inArg("i","inputfile","input image",true,"","input image",cmd);
21+
TCLAP::ValueArg<std::string> outArg("o","outputfile","output mask",true,"","output mask",cmd);
22+
23+
//Try to parse
24+
try
25+
{
26+
cmd.parse(argc,argv);
27+
}
28+
catch (TCLAP::ArgException& e)
29+
{
30+
std::cerr << "Error: " << e.error() << "for argument " << e.argId() << std::endl;
31+
return(1);
32+
}
33+
34+
//Define types
35+
typedef itk::Image <double,3> ImageType;
36+
typedef itk::Image <double,4> Image4DType;
37+
typedef itk::VectorImage <double,3> VectorImageType;
38+
39+
//Read input image
40+
itk::ImageIOBase::Pointer imageIO = itk::ImageIOFactory::CreateImageIO(inArg.getValue().c_str(),
41+
itk::IOFileModeEnum::ReadMode);
42+
43+
imageIO->SetFileName(inArg.getValue());
44+
imageIO->ReadImageInformation();
45+
46+
//Initialize the output image (which is a mask) and allocate memory
47+
ImageType::Pointer outImage = ImageType::New();
48+
49+
//Determine if the input image is a vector image (each voxel value is a vector) or not
50+
bool vectorImage = (imageIO->GetNumberOfComponents() > 1);
51+
52+
if (vectorImage)
53+
{
54+
//Case of a vector image
55+
56+
//Read input image and store in the correct format
57+
VectorImageType::Pointer image = anima::readImage <VectorImageType> (inArg.getValue());
58+
59+
//Set the output image with the same properties as the input image
60+
outImage->Initialize();
61+
outImage->SetDirection(image->GetDirection());
62+
outImage->SetSpacing(image->GetSpacing());
63+
outImage->SetOrigin(image->GetOrigin());
64+
65+
//Allocate the correct size for output image. region (image->GetLargestPossibleRegion()) is the whole image
66+
VectorImageType::RegionType region = image->GetLargestPossibleRegion();
67+
outImage->SetRegions(region);
68+
outImage->Allocate();
69+
70+
//Create a vector with as many components as there are for each voxel, and with each component equal to 0
71+
VectorImageType::PixelType zeroVec(image->GetNumberOfComponentsPerPixel());
72+
zeroVec.Fill(0);
73+
74+
//Create iterators on input and output images
75+
itk::ImageRegionIterator <VectorImageType> inItr(image,region);
76+
itk::ImageRegionIterator <ImageType> outItr(outImage,outImage->GetLargestPossibleRegion());
77+
78+
//Main algorithm
79+
while (!outItr.IsAtEnd())
80+
{
81+
if(inItr.Get() == zeroVec)
82+
{
83+
//The voxel in the input image is a constant vector equal to 0, so this voxel in the output mask will be 0.
84+
outItr.Set(0);
85+
}
86+
else
87+
{
88+
//The voxel in the input image is not a constant vector equal to 0, so this voxel in the output mask will be 1.
89+
outItr.Set(1);
90+
}
91+
92+
//Move to following voxel
93+
++inItr;
94+
++outItr;
95+
}
96+
}
97+
else
98+
{
99+
//Case of a non-vector image
100+
101+
//Read input image and store in the correct format
102+
ImageType::Pointer image = anima::readImage <ImageType> (inArg.getValue());
103+
104+
//Set the output image with the same properties as the input image
105+
outImage->Initialize();
106+
outImage->SetDirection(image->GetDirection());
107+
outImage->SetSpacing(image->GetSpacing());
108+
outImage->SetOrigin(image->GetOrigin());
109+
110+
//Allocate the correct size for output image. largestRegion (image->GetLargestPossibleRegion()) is the whole image
111+
ImageType::RegionType largestRegion = image->GetLargestPossibleRegion();
112+
outImage->SetRegions(largestRegion);
113+
outImage->Allocate();
114+
outImage->FillBuffer(0.0);
115+
116+
//Create iterators on input and output images
117+
itk::ImageRegionIterator <ImageType> inItr(image,image->GetLargestPossibleRegion());
118+
itk::ImageRegionIterator <ImageType> outItr(outImage,outImage->GetLargestPossibleRegion());
119+
120+
//Main algorithm
121+
while (!outItr.IsAtEnd())
122+
{
123+
if(inItr.Get() == 0.0)
124+
{
125+
//The voxel in the input image is 0, so this voxel in the output mask will be 0.
126+
outItr.Set(0);
127+
}
128+
else
129+
{
130+
//The voxel in the input image is not 0, so this voxel in the output mask will be 1.
131+
outItr.Set(1);
132+
}
133+
134+
//Move to following voxel
135+
++inItr;
136+
++outItr;
137+
}
138+
}
139+
140+
//Write output image and exit
141+
anima::writeImage <ImageType> (outArg.getValue(),outImage);
142+
return EXIT_SUCCESS;
143+
}

superbuild/TCLAP.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ set (proj TCLAP)
22

33
set (location "")
44
if (NOT DEFINED ${proj}_SRC_DIR)
5-
set(location URL https://netix.dl.sourceforge.net/project/tclap/tclap-1.2.1.tar.gz)
5+
set(location URL https://sourceforge.net/projects/tclap/files/tclap-1.2.1.tar.gz/download)
66
endif()
77

88
ExternalProject_Add(${proj}

0 commit comments

Comments
 (0)