19 #include <boost/lexical_cast.hpp>
20 #include <vnl/vnl_random.h>
23 #include <itksys/SystemTools.hxx>
29 #include <itkImageRegionIterator.h>
40 #include <QStringList>
42 #include <itkLabelOverlapMeasuresImageFilter.h>
43 #include <itkImageRegionIteratorWithIndex.h>
46 #include <itkNeighborhood.h>
57 typedef itk::Image<double,3> DoubleImageType;
58 typedef itk::Image<short,3> ShortImageType;
59 typedef itk::ConstNeighborhoodIterator<DoubleImageType> NeighborhoodType;
64 m_FeatureImageVector.clear();
67 m_FeatureImageVector.push_back(raw_image);
72 m_FeatureImageVector.push_back(smoothed);
78 m_FeatureImageVector.push_back(csf_prob);
84 m_FeatureImageVector.push_back(les_prob);
90 m_FeatureImageVector.push_back(brain_prob);
92 std::vector<unsigned int> FOS_sizes;
93 FOS_sizes.push_back(1);
100 for(
unsigned int i = 0 ; i < FOS_sizes.size(); i++)
103 filter->SetNeighborhoodSize(FOS_sizes[i]);
104 filter->SetInput(input);
105 filter->SetMask(mask);
108 FOSFilerType::DataObjectPointerArray array = filter->GetOutputs();
110 for(
unsigned int i = 0; i < FunctorType::OutputCount; i++)
114 m_FeatureImageVector.push_back(featureimage);
121 filter->SetInput(input);
122 filter->SetImageMask(mask);
131 m_FeatureImageVector.push_back(o1);
132 m_FeatureImageVector.push_back(o2);
133 m_FeatureImageVector.push_back(o3);
138 filter->SetInput(input);
139 filter->SetImageMask(mask);
140 filter->SetInnerScale(1.5);
141 filter->SetOuterScale(3);
149 m_FeatureImageVector.push_back(o1);
150 m_FeatureImageVector.push_back(o2);
151 m_FeatureImageVector.push_back(o3);
156 filter->SetInput(input);
157 filter->SetImageMask(mask);
163 m_FeatureImageVector.push_back(o1);
169 std::vector<mitk::Point3D> result;
170 for(
int i = 0 ; i < mps->GetSize(); i++)
171 result.push_back(mps->GetPoint(i));
175 int main(
int argc,
char* argv[])
191 parser.
setTitle(
"Evaluationtool for Manual-Segmentation");
192 parser.
setDescription(
"Uses Datacollection to calculate DICE scores for CSF LES BRA");
196 std::map<std::string, us::Any> parsedArgs = parser.
parseArguments(argc, argv);
197 if (parsedArgs.size()==0)
200 std::string inputdir =
us::any_cast<std::string>(parsedArgs[
"inputdir"]);
201 std::string outputdir =
us::any_cast<std::string>(parsedArgs[
"outputdir"]);
202 std::string mitkprojectdata =
us::any_cast<std::string>(parsedArgs[
"mitkprojectdata"]);
203 std::string csf_mps_name =
us::any_cast<std::string>(parsedArgs[
"csfmps"]);
204 std::string les_mps_name =
us::any_cast<std::string>(parsedArgs[
"lesmps"]);
205 std::string bra_mps_name =
us::any_cast<std::string>(parsedArgs[
"bramps"]);
212 std::map<unsigned int, unsigned int>
map;
214 raw_image = map.size() <= 7 ?
dynamic_cast<mitk::Image *
>(so[0].GetPointer()) : dynamic_cast<mitk::Image *>(so[1].GetPointer());
215 class_mask = map.size() <= 7 ?
dynamic_cast<mitk::Image *
>(so[1].GetPointer()) : dynamic_cast<mitk::Image *>(so[0].GetPointer());
221 unsigned int num_points = CSF_mps->GetSize() + LES_mps->GetSize() + BRA_mps->GetSize();
222 MITK_INFO <<
"Found #" << num_points <<
" points over all classes.";
226 std::map<unsigned int, unsigned int> tmpMap;
235 class_mask_sampled = class_mask->Clone();
238 itk::ImageRegionIteratorWithIndex<itk::Image<short,3> >::IndexType index;
239 itk::ImageRegionIteratorWithIndex<itk::Image<short,3> > iit(itk_classmask_sampled,itk_classmask_sampled->GetLargestPossibleRegion());
241 std::ofstream myfile;
242 myfile.open (inputdir +
"/results_3.csv");
244 Eigen::MatrixXd X_test;
246 unsigned int count_test = 0;
248 X_test = Eigen::MatrixXd(count_test, m_FeatureImageVector.size());
250 unsigned int pos = 0;
251 for(
const auto & image : m_FeatureImageVector)
253 X_test.col(pos) = mitk::CLUtil::Transform<double>(image,class_mask);
257 unsigned int runs = 20;
258 for(
unsigned int k = 0 ; k < runs; k++)
264 itk_classmask_sampled->FillBuffer(0);
267 std::random_shuffle(CSF_vec.begin(), CSF_vec.end());
268 class_mask->GetGeometry()->WorldToIndex(CSF_vec.back(),index);
273 std::random_shuffle(LES_vec.begin(), LES_vec.end());
274 class_mask->GetGeometry()->WorldToIndex(LES_vec.back(),index);
279 std::random_shuffle(BRA_vec.begin(), BRA_vec.end());
280 class_mask->GetGeometry()->WorldToIndex(BRA_vec.back(),index);
285 std::stringstream ss;
287 while(!(CSF_vec.empty() && LES_vec.empty() && BRA_vec.empty()))
293 classifier->SetTreeCount(40);
294 classifier->SetSamplesPerTree(0.66);
296 Eigen::MatrixXd X_train;
298 unsigned int count_train = 0;
300 X_train = Eigen::MatrixXd(count_train, m_FeatureImageVector.size() );
302 unsigned int pos = 0;
303 for(
const auto & image : m_FeatureImageVector)
305 X_train.col(pos) = mitk::CLUtil::Transform<double>(image,class_mask_sampled);
309 Eigen::MatrixXi Y = mitk::CLUtil::Transform<int>(class_mask_sampled,class_mask_sampled);
310 classifier->Train(X_train,Y);
312 Eigen::MatrixXi Y_test = classifier->Predict(X_test);
320 itk::LabelOverlapMeasuresImageFilter<itk::Image<short,3> >
::Pointer overlap_filter = itk::LabelOverlapMeasuresImageFilter<itk::Image<short,3> >
::New();
321 overlap_filter->SetInput(0,itk_result_mask);
322 overlap_filter->SetInput(1,itk_class_mask);
323 overlap_filter->Update();
325 MITK_INFO <<
"DICE (" << num_points - (CSF_vec.size() + LES_vec.size() + BRA_vec.size()) <<
"): " << overlap_filter->GetDiceCoefficient();
326 ss << overlap_filter->GetDiceCoefficient() <<
",";
332 std::random_shuffle(CSF_vec.begin(), CSF_vec.end());
333 class_mask->GetGeometry()->WorldToIndex(CSF_vec.back(),index);
341 std::random_shuffle(LES_vec.begin(), LES_vec.end());
342 class_mask->GetGeometry()->WorldToIndex(LES_vec.back(),index);
350 std::random_shuffle(BRA_vec.begin(), BRA_vec.end());
351 class_mask->GetGeometry()->WorldToIndex(BRA_vec.back(),index);
358 myfile << ss.str() <<
"\n";
itk::SmartPointer< Self > Pointer
int main(int argc, char *argv[])
std::vector< mitk::Image::Pointer > m_FeatureImageVector
std::vector< mitk::Point3D > PointSetToVector(const mitk::PointSet::Pointer &mps)
void setContributor(std::string contributor)
DataCollection - Class to facilitate loading/accessing structured data.
ValueType * any_cast(Any *operand)
static void GaussianFilter(mitk::Image::Pointer image, mitk::Image::Pointer &smoothed, double sigma)
GaussianFilter.
std::map< std::string, us::Any > parseArguments(const StringContainerType &arguments, bool *ok=nullptr)
void ProcessFeatureImages(const mitk::Image::Pointer &raw_image, const mitk::Image::Pointer &brain_mask)
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)
Image class for storing images.
itk::Image< unsigned char, 3 > MaskImageType
static mitk::PointSet::Pointer LoadPointSet(const std::string &path)
LoadPointSet Convenience method to load an arbitrary mitkPointSet.
static void ProbabilityMap(const mitk::Image::Pointer &sourceImage, double mean, double std_dev, mitk::Image::Pointer &resultImage)
ProbabilityMap.
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.
void MITKCORE_EXPORT CastToItkImage(const mitk::Image *mitkImage, itk::SmartPointer< ItkOutputImageType > &itkOutputImage)
Cast an mitk::Image to an itk::Image with a specific type.
static void MergeLabels(mitk::Image::Pointer &img, const std::map< unsigned int, unsigned int > &map)
MergeLabels.
MITKMATCHPOINTREGISTRATION_EXPORT ResultImageType::Pointer map(const InputImageType *input, const RegistrationType *registration, bool throwOnOutOfInputAreaError=false, const double &paddingValue=0, const ResultImageGeometryType *resultGeometry=NULL, bool throwOnMappingError=true, const double &errorValue=0, mitk::ImageMappingInterpolator::Type interpolatorType=mitk::ImageMappingInterpolator::Linear)
static DataStorage::SetOfObjects::Pointer Load(const std::string &path, DataStorage &storage)
Load a file into the given DataStorage.
void setTitle(std::string title)
static void CountVoxel(mitk::Image::Pointer image, std::map< unsigned int, unsigned int > &map)
CountVoxel.
void setDescription(std::string description)
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.