22 #include <itkImageRegionIterator.h>
27 #include "itkImageFileWriter.h"
84 typedef itk::Image<double , 3> FeatureImageType;
93 std::vector<DataCollectionSingleImageIterator<double, 3> > featureList;
94 for (
unsigned int i = 0; i < m_Modalities.size(); ++i)
97 featureList.push_back(iter);
104 itk::ImageRegionIterator<MaskImageType> trainIter(train.
GetImage(), train.
GetImage()->GetLargestPossibleRegion() );
105 itk::ImageRegionIterator<MaskImageType> testIter(test.
GetImage(), test.
GetImage()->GetLargestPossibleRegion() );
107 int trainElements = 0;
108 int testElements = 0;
109 while (!trainIter.IsAtEnd())
111 if (trainIter.Get() > 0)
115 if (testIter.Get() > 0)
122 trainIter.GoToBegin();
123 testIter.GoToBegin();
125 std::vector<itk::ImageRegionIterator<FeatureImageType> > featureIter;
126 for (
unsigned int i = 0; i < featureList.size(); ++i)
128 itk::ImageRegionIterator<FeatureImageType> iter(featureList[i].GetImage(), featureList[i].GetImage()->GetLargestPossibleRegion() );
129 featureIter.push_back(iter);
132 vnl_vector<double> label(trainElements + testElements);
133 vnl_matrix<double> feature(trainElements + testElements, featureList.size() );
134 vnl_matrix<double> trainFeature(trainElements, featureList.size() );
138 while (!trainIter.IsAtEnd())
140 if (trainIter.Get() > 0)
143 for (
unsigned int i = 0; i < featureIter.size(); ++i)
145 feature(index, i) = featureIter[i].Get();
146 trainFeature(trainIndex, i) = featureIter[i].Get();
151 if (testIter.Get() > 0)
154 for (
unsigned int i = 0; i < featureIter.size(); ++i)
156 feature(index, i) = featureIter[i].Get();
163 for (
unsigned int i = 0; i < featureIter.size(); ++i)
170 vnl_vector<double> weightVector = glm.
ExpMu(trainFeature);
172 itk::ImageRegionIterator<FeatureImageType> weightIter(weight.
GetImage(), weight.
GetImage()->GetLargestPossibleRegion() );
174 trainIter.GoToBegin();
178 while(!trainIter.IsAtEnd())
180 if (trainIter.Get() > 0)
182 weightIter.Set(weightVector(index) );
204 for (
unsigned int i = 0; i < featureList.size(); ++i)
214 m_Modalities = modalities;
217 std::vector<std::string>
241 typedef itk::Image<unsigned char, 3> LabelImage;
249 if (collection->HasElement(origin))
251 LabelImage::Pointer originImage =
dynamic_cast<LabelImage*
>(collection->GetData(origin).GetPointer());
252 if (!collection->HasElement(target) && originImage.IsNotNull())
256 image->SetRegions(originImage->GetLargestPossibleRegion());
257 image->SetSpacing(originImage->GetSpacing());
258 image->SetOrigin(originImage->GetOrigin());
259 image->SetDirection(originImage->GetDirection());
262 collection->AddData(dynamic_cast<itk::DataObject*>(image.GetPointer()),target,
"");
265 for (std::size_t i = 0; i < collection->Size();++i)
285 std::vector<DataCollectionImageIterator<double, 3> > trainFeatureList;
286 std::vector<DataCollectionImageIterator<double, 3> > testFeatureList;
287 for (
unsigned int i = 0; i < m_Modalities.size(); ++i)
290 trainFeatureList.push_back(iter);
292 testFeatureList.push_back(iter2);
295 int trainElements = 0;
296 int testElements = 0;
312 vnl_vector<double> label(trainElements + testElements);
313 vnl_matrix<double> feature(trainElements + testElements, trainFeatureList.size() );
314 vnl_matrix<double> trainFeature(trainElements, trainFeatureList.size() );
322 label(trainIndex) = 1;
323 for (
unsigned int i = 0; i < trainFeatureList.size(); ++i)
325 feature(trainIndex, i) = trainFeatureList[i].GetVoxel();
326 trainFeature(trainIndex, i) = trainFeatureList[i].GetVoxel();
333 for (
unsigned int i = 0; i < trainFeatureList.size(); ++i)
335 ++(trainFeatureList[i]);
343 label(trainIndex) = 1;
344 for (
unsigned int i = 0; i < testFeatureList.size(); ++i)
346 feature(trainIndex+testIndex, i) = testFeatureList[i].GetVoxel();
352 for (
unsigned int i = 0; i < testFeatureList.size(); ++i)
354 ++(testFeatureList[i]);
359 vnl_vector<double> weightVector = glm.
ExpMu(trainFeature);
367 weightIter.
SetVoxel(weightVector(index));
378 typedef itk::Image<double , 3> FeatureImageType;
387 std::vector<DataCollectionSingleImageIterator<double, 3> > featureList;
388 for (
unsigned int i = 0; i < m_Modalities.size(); ++i)
391 featureList.push_back(iter);
396 itk::ImageRegionIterator<MaskImageType> trainIter(train.
GetImage(), train.
GetImage()->GetLargestPossibleRegion() );
397 itk::ImageRegionIterator<MaskImageType> testIter(test.
GetImage(), test.
GetImage()->GetLargestPossibleRegion() );
399 int trainElements = 0;
400 int testElements = 0;
401 while (!trainIter.IsAtEnd())
403 if (trainIter.Get() > 0)
407 if (testIter.Get() > 0)
414 trainIter.GoToBegin();
415 testIter.GoToBegin();
417 std::vector<itk::ImageRegionIterator<FeatureImageType> > featureIter;
418 for (
unsigned int i = 0; i < featureList.size(); ++i)
420 itk::ImageRegionIterator<FeatureImageType> iter(featureList[i].GetImage(), featureList[i].GetImage()->GetLargestPossibleRegion() );
421 featureIter.push_back(iter);
424 vnl_vector<double> label(trainElements + testElements);
425 vnl_matrix<double> feature(trainElements + testElements, featureList.size() );
426 vnl_matrix<double> trainFeature(trainElements, featureList.size() );
430 while (!trainIter.IsAtEnd())
432 if (trainIter.Get() > 0)
435 for (
unsigned int i = 0; i < featureIter.size(); ++i)
437 feature(index, i) = featureIter[i].Get();
438 trainFeature(trainIndex, i) = featureIter[i].Get();
443 if (testIter.Get() > 0)
446 for (
unsigned int i = 0; i < featureIter.size(); ++i)
448 feature(index, i) = featureIter[i].Get();
455 for (
unsigned int i = 0; i < featureIter.size(); ++i)
462 vnl_vector<double> weightVector = glm.
Predict(trainFeature);
464 itk::ImageRegionIterator<FeatureImageType> weightIter(weight.
GetImage(), weight.
GetImage()->GetLargestPossibleRegion() );
466 trainIter.GoToBegin();
469 while(!trainIter.IsAtEnd())
471 if (trainIter.Get() > 0)
473 weightIter.Set(weightVector(index) );
483 for (
unsigned int i = 0; i < featureList.size(); ++i)
void SetWeightName(std::string name)
itk::Image< mitk::ScalarType, 3 > FeatureImage
itk::SmartPointer< Self > Pointer
std::string GetTestMask()
void SetVoxel(TDataType value)
Follow Up Storage - Class to facilitate loading/accessing structured follow-up data.
double Predict(const vnl_vector< double > &c)
Predicts the value corresponding to the given vector.
std::string GetTrainMask()
void SetTrainMask(std::string name)
DataCollection::Pointer GetCollection()
Generalized Linear Model that allows linear models for non-gaussian data.
void SetTestMask(std::string name)
static void EnsureDataImageInCollection(mitk::DataCollection::Pointer collection, std::string origin, std::string target)
std::vector< std::string > GetModalities()
itk::Image< unsigned char, 3 > MaskImageType
std::string GetWeightName()
void SetModalities(std::vector< std::string > modalities)
void SetCollection(DataCollection::Pointer data)
vnl_vector< double > ExpMu(const vnl_matrix< double > &x)
Estimation of the exponential factor for a given function.
itk::SmartPointer< Self > Pointer
void WeightsForAll(mitk::DataCollection::Pointer train, mitk::DataCollection::Pointer test)
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.