21 #include <metaCommand.h>
25 #include <itkImageFileWriter.h>
27 #include <boost/lexical_cast.hpp>
31 #define _USE_MATH_DEFINES
39 int main(
int argc,
char* argv[])
51 parser.
setTitle(
"Peaks Angular Error");
52 parser.
setDescription(
"Calculate angular error between two sets of directions stored in multiple 3D vector images where each pixel corresponds to a vector (itk::Image< itk::Vector< float, 3>, 3 >)");
55 map<string, us::Any> parsedArgs = parser.
parseArguments(argc, argv);
56 if (parsedArgs.size()==0)
63 if (parsedArgs.count(
"mask"))
64 maskImage = us::any_cast<string>(parsedArgs[
"mask"]);
66 string outRoot =
us::any_cast<
string>(parsedArgs[
"out"]);
69 if (parsedArgs.count(
"verbose"))
70 verbose = us::any_cast<bool>(parsedArgs[
"verbose"]);
73 if (parsedArgs.count(
"ignore"))
74 ignore = us::any_cast<bool>(parsedArgs[
"ignore"]);
78 typedef itk::Image<unsigned char, 3> ItkUcharImgType;
79 typedef itk::Image< itk::Vector< float, 3>, 3 > ItkDirectionImage3DType;
80 typedef itk::VectorContainer< unsigned int, ItkDirectionImage3DType::Pointer > ItkDirectionImageContainerType;
84 for (
unsigned int i=0; i<testImages.size(); i++)
91 caster->SetInput(img);
94 directionImageContainer->InsertElement(directionImageContainer->Size(),itkImg);
96 catch(...){ std::cout <<
"could not load: " << referenceImages.at(i); }
101 for (
unsigned int i=0; i<referenceImages.size(); i++)
108 caster->SetInput(img);
111 referenceImageContainer->InsertElement(referenceImageContainer->Size(),itkImg);
113 catch(...){ std::cout <<
"could not load: " << referenceImages.at(i); }
118 if (maskImage.compare(
"")==0)
121 itkMaskImage->SetSpacing( dirImg->GetSpacing() );
122 itkMaskImage->SetOrigin( dirImg->GetOrigin() );
123 itkMaskImage->SetDirection( dirImg->GetDirection() );
124 itkMaskImage->SetLargestPossibleRegion( dirImg->GetLargestPossibleRegion() );
125 itkMaskImage->SetBufferedRegion( dirImg->GetLargestPossibleRegion() );
126 itkMaskImage->SetRequestedRegion( dirImg->GetLargestPossibleRegion() );
127 itkMaskImage->Allocate();
128 itkMaskImage->FillBuffer(1);
138 evaluationFilter->SetImageSet(directionImageContainer);
139 evaluationFilter->SetReferenceImageSet(referenceImageContainer);
140 evaluationFilter->SetMaskImage(itkMaskImage);
141 evaluationFilter->SetIgnoreMissingDirections(ignore);
142 evaluationFilter->Update();
147 typedef itk::ImageFileWriter< EvaluationFilterType::OutputImageType > WriterType;
150 string outfilename = outRoot;
151 outfilename.append(
"_ERROR_IMAGE.nrrd");
153 writer->SetFileName(outfilename.c_str());
154 writer->SetInput(angularErrorImage);
159 logFile.append(
"_ANGULAR_ERROR.csv");
162 file.open (logFile.c_str());
164 string sens =
"Mean:";
166 sens.append(boost::lexical_cast<string>(evaluationFilter->GetMeanAngularError()));
169 sens.append(
"Median:");
171 sens.append(boost::lexical_cast<string>(evaluationFilter->GetMedianAngularError()));
174 sens.append(
"Maximum:");
176 sens.append(boost::lexical_cast<string>(evaluationFilter->GetMaxAngularError()));
179 sens.append(
"Minimum:");
181 sens.append(boost::lexical_cast<string>(evaluationFilter->GetMinAngularError()));
184 sens.append(
"STDEV:");
186 sens.append(boost::lexical_cast<string>(std::sqrt(evaluationFilter->GetVarAngularError())));
193 catch (itk::ExceptionObject e)
198 catch (std::exception e)
200 std::cout << e.what();
205 std::cout <<
"ERROR!?!";
itk::SmartPointer< Self > Pointer
void setContributor(std::string contributor)
ValueType * any_cast(Any *operand)
std::map< std::string, us::Any > parseArguments(const StringContainerType &arguments, bool *ok=nullptr)
T::Pointer GetData(const std::string &name)
void addArgument(const std::string &longarg, const std::string &shortarg, Type type, const std::string &argLabel, const std::string &argHelp=std::string(), const us::Any &defaultValue=us::Any(), bool optional=true, bool ignoreRest=false, bool deprecated=false)
Evaluates the voxel-wise angular error between two sets of directions.
Image class for storing images.
static std::ofstream * logFile
void setCategory(std::string category)
static mitk::DataNode::Pointer LoadDataNode(const std::string &path)
LoadDataNode Method to load an arbitrary DataNode.
void setArgumentPrefix(const std::string &longPrefix, const std::string &shortPrefix)
void MITKCORE_EXPORT CastToItkImage(const mitk::Image *mitkImage, itk::SmartPointer< ItkOutputImageType > &itkOutputImage)
Cast an mitk::Image to an itk::Image with a specific type.
std::vector< std::string > StringContainerType
void setTitle(std::string title)
void setDescription(std::string description)
int main(int argc, char *argv[])
Calculate angular error between two sets of directions stored in multiple 3D vector images where each...
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.