16 #ifndef mitkCLVoxeFeatures_cpp
17 #define mitkCLVoxeFeatures_cpp
31 #include "itkDiscreteGaussianImageFilter.h"
32 #include <itkLaplacianRecursiveGaussianImageFilter.h>
33 #include "itkHessianRecursiveGaussianImageFilter.h"
34 #include "itkUnaryFunctorImageFilter.h"
36 #include "vnl/algo/vnl_symmetric_eigensystem.h"
37 #include <itkSubtractImageFilter.h>
39 static std::vector<double>
splitDouble(std::string str,
char delimiter) {
40 std::vector<double>
internal;
41 std::stringstream ss(str);
44 while (std::getline(ss, tok, delimiter)) {
45 std::stringstream s2(tok);
47 internal.push_back(val);
55 template <
class TInput,
class TOutput>
56 class MatrixFirstEigenvalue
59 MatrixFirstEigenvalue() {}
60 virtual ~MatrixFirstEigenvalue() {}
64 inline TOutput operator ()(
const TInput& input)
67 if (input[0] < 0.01 && input[1] < 0.01 &&input[2] < 0.01 &&input[3] < 0.01 &&input[4] < 0.01 &&input[5] < 0.01)
69 vnl_symmetric_eigensystem_compute_eigenvals(input[0], input[1],input[2],input[3],input[4],input[5],a,b,c);
82 bool operator ==(
const MatrixFirstEigenvalue& other)
const
84 return !(*
this != other);
89 template<
typename TPixel,
unsigned int VImageDimension>
93 typedef itk::Image<TPixel, VImageDimension>
ImageType;
94 typedef itk::DiscreteGaussianImageFilter< ImageType, ImageType > GaussFilterType;
97 gaussianFilter->SetInput( itkImage );
98 gaussianFilter->SetVariance(variance);
99 gaussianFilter->Update();
103 template<
typename TPixel,
unsigned int VImageDimension>
107 typedef itk::Image<TPixel, VImageDimension>
ImageType;
108 typedef itk::DiscreteGaussianImageFilter< ImageType, ImageType > GaussFilterType;
109 typedef itk::SubtractImageFilter<ImageType, ImageType, ImageType> SubFilterType;
112 gaussianFilter1->SetInput( itkImage );
113 gaussianFilter1->SetVariance(variance);
114 gaussianFilter1->Update();
116 gaussianFilter2->SetInput( itkImage );
117 gaussianFilter2->SetVariance(variance*0.66*0.66);
118 gaussianFilter2->Update();
120 subFilter->SetInput1(gaussianFilter1->GetOutput());
121 subFilter->SetInput2(gaussianFilter2->GetOutput());
126 template<
typename TPixel,
unsigned int VImageDimension>
130 typedef itk::Image<TPixel, VImageDimension>
ImageType;
131 typedef itk::DiscreteGaussianImageFilter< ImageType, ImageType > GaussFilterType;
132 typedef itk::LaplacianRecursiveGaussianImageFilter<ImageType, ImageType> LaplacianFilter;
135 gaussianFilter->SetInput( itkImage );
136 gaussianFilter->SetVariance(variance);
137 gaussianFilter->Update();
139 laplaceFilter->SetInput(gaussianFilter->GetOutput());
140 laplaceFilter->Update();
144 template<
typename TPixel,
unsigned int VImageDimension>
146 HessianOfGaussianFilter(itk::Image<TPixel, VImageDimension>* itkImage,
double variance, std::vector<mitk::Image::Pointer> &out)
148 typedef itk::Image<TPixel, VImageDimension>
ImageType;
150 typedef itk::HessianRecursiveGaussianImageFilter <ImageType> HessianFilterType;
152 typedef Functor::MatrixFirstEigenvalue<typename VectorImageType::PixelType, double> DeterminantFunctorType;
153 typedef itk::UnaryFunctorImageFilter<VectorImageType, FloatImageType, DeterminantFunctorType> DetFilterType;
156 hessianFilter->SetInput(itkImage);
157 hessianFilter->SetSigma(std::sqrt(variance));
158 for (
int i = 0; i < VImageDimension; ++i)
161 detFilter->SetInput(hessianFilter->GetOutput());
162 detFilter->GetFunctor().order = i;
168 template<
typename TPixel,
unsigned int VImageDimension>
170 LocalHistograms(itk::Image<TPixel, VImageDimension>* itkImage, std::vector<mitk::Image::Pointer> &out,
double offset,
double delta)
172 typedef itk::Image<TPixel, VImageDimension>
ImageType;
177 filter->SetInput(itkImage);
178 filter->SetOffset(offset);
179 filter->SetDelta(delta);
181 for (
int i = 0; i < VImageDimension; ++i)
189 int main(
int argc,
char* argv[])
204 parser.
setTitle(
"Global Image Feature calculator");
205 parser.
setDescription(
"Calculates different global statistics for a given segmentation / image combination");
208 std::map<std::string, us::Any> parsedArgs = parser.
parseArguments(argc, argv);
210 if (parsedArgs.size()==0)
214 if ( parsedArgs.count(
"help") || parsedArgs.count(
"h"))
218 bool useCooc = parsedArgs.count(
"cooccurence");
221 std::string
filename=parsedArgs[
"output"].ToString();
226 MITK_INFO <<
"Check for Local Histogram...";
227 if (parsedArgs.count(
"local-histogram"))
229 std::vector<mitk::Image::Pointer> outs;
230 auto ranges =
splitDouble(parsedArgs[
"local-histogram"].ToString(),
';');
231 if (ranges.size() < 2)
233 MITK_INFO <<
"Missing Delta and Offset for Local Histogram";
238 for (
int i = 0; i < outs.size(); ++i)
240 std::string name = filename +
"-lh" + us::any_value_to_string<int>(i)+
".nii.gz";
250 if (parsedArgs.count(
"gaussian"))
252 MITK_INFO <<
"Calculate Gaussian... " << parsedArgs[
"gaussian"].ToString();
253 auto ranges =
splitDouble(parsedArgs[
"gaussian"].ToString(),
';');
255 for (
int i = 0; i < ranges.size(); ++i)
268 if (parsedArgs.count(
"difference-of-gaussian"))
270 MITK_INFO <<
"Calculate Difference of Gaussian... " << parsedArgs[
"difference-of-gaussian"].ToString();
271 auto ranges =
splitDouble(parsedArgs[
"difference-of-gaussian"].ToString(),
';');
273 for (
int i = 0; i < ranges.size(); ++i)
286 if (parsedArgs.count(
"laplace-of-gauss"))
288 MITK_INFO <<
"Calculate LoG... " << parsedArgs[
"laplace-of-gauss"].ToString();
289 auto ranges =
splitDouble(parsedArgs[
"laplace-of-gauss"].ToString(),
';');
291 for (
int i = 0; i < ranges.size(); ++i)
304 if (parsedArgs.count(
"hessian-of-gauss"))
306 MITK_INFO <<
"Calculate HoG... " << parsedArgs[
"hessian-of-gauss"].ToString();
307 auto ranges =
splitDouble(parsedArgs[
"hessian-of-gauss"].ToString(),
';');
309 for (
int i = 0; i < ranges.size(); ++i)
311 std::vector<mitk::Image::Pointer> outs;
US_Core_EXPORT std::string any_value_to_string(const Any &any)
void LaplacianOfGaussianFilter(itk::Image< TPixel, VImageDimension > *itkImage, double variance, mitk::Image::Pointer &output)
#define AccessByItk_3(mitkImage, itkImageTypeFunction, arg1, arg2, arg3)
itk::SmartPointer< Self > Pointer
MITKCORE_EXPORT bool operator!=(const InteractionEvent &a, const InteractionEvent &b)
int main(int argc, char *argv[])
itk::Image< unsigned char, 3 > ImageType
void setContributor(std::string contributor)
itk::Image< double, 3 > FloatImageType
void HessianOfGaussianFilter(itk::Image< TPixel, VImageDimension > *itkImage, double variance, std::vector< mitk::Image::Pointer > &out)
std::map< std::string, us::Any > parseArguments(const StringContainerType &arguments, bool *ok=nullptr)
MITKCORE_EXPORT bool operator==(const InteractionEvent &a, const InteractionEvent &b)
void GaussianFilter(itk::Image< TPixel, VImageDimension > *itkImage, double variance, mitk::Image::Pointer &output)
static bool SaveImage(mitk::Image::Pointer image, const std::string &path)
SaveImage Convenience method to save an arbitrary mitkImage.
void DifferenceOfGaussFilter(itk::Image< TPixel, VImageDimension > *itkImage, double variance, mitk::Image::Pointer &output)
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)
static const std::string filename
void LocalHistograms(itk::Image< TPixel, VImageDimension > *itkImage, std::vector< mitk::Image::Pointer > &out, double offset, double delta)
static std::vector< double > splitDouble(std::string str, char delimiter)
void setCategory(std::string category)
void setArgumentPrefix(const std::string &longPrefix, const std::string &shortPrefix)
void CastToMitkImage(const itk::SmartPointer< ItkOutputImageType > &itkimage, itk::SmartPointer< mitk::Image > &mitkoutputimage)
Cast an itk::Image (with a specific type) to an mitk::Image.
#define AccessByItk_2(mitkImage, itkImageTypeFunction, arg1, arg2)
void setTitle(std::string title)
void setDescription(std::string description)
static mitk::Image::Pointer LoadImage(const std::string &path)
LoadImage Convenience method to load an arbitrary mitkImage.
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.