23 #include <itkImageRegionIteratorWithIndex.h> 24 #include <itkNeighborhoodIterator.h> 28 struct GIFNeighbourhoodGreyToneDifferenceParameter
35 template<
typename TPixel,
unsigned int VImageDimension>
39 typedef itk::Image<TPixel, VImageDimension>
ImageType;
40 typedef itk::Image<unsigned short, VImageDimension> MaskType;
42 typename MaskType::Pointer itkMask = MaskType::New();
45 typename ImageType::SizeType regionSize;
46 regionSize.Fill(params.Range);
48 itk::NeighborhoodIterator<ImageType> iter(regionSize, itkImage, itkImage->GetLargestPossibleRegion());
49 itk::NeighborhoodIterator<MaskType> iterMask(regionSize, itkMask, itkMask->GetLargestPossibleRegion());
51 std::vector<double> pVector;
52 std::vector<double> sVector;
53 pVector.resize(params.quantifier->GetBins(), 0);
54 sVector.resize(params.quantifier->GetBins(), 0);
57 while (!iter.IsAtEnd())
59 if (iterMask.GetCenterPixel() > 0)
63 unsigned int localIndex = params.quantifier->IntensityToIndex(iter.GetCenterPixel());
64 for (itk::SizeValueType i = 0; i < iter.Size(); ++i)
66 if (i == (iter.Size() / 2))
68 if (iterMask.GetPixel(i) > 0)
71 localMean += params.quantifier->IntensityToIndex(iter.GetPixel(i)) + 1;
76 localMean /= localCount;
78 localMean = std::abs<double>(localIndex + 1 - localMean);
80 pVector[localIndex] += 1;
81 sVector[localIndex] += localMean;
91 for (
unsigned int i = 0; i < params.quantifier->GetBins(); ++i)
101 double sumStimesP = 0;
103 double contrastA = 0;
104 double busynessA = 0;
105 double complexity = 0;
106 double strengthA = 0;
107 for (
unsigned int i = 0; i < params.quantifier->GetBins(); ++i)
110 sumStimesP += pVector[i] * sVector[i];
111 for (
unsigned int j = 0; j < params.quantifier->GetBins(); ++j)
113 double iMinusj = 1.0*i - 1.0*j;
114 contrastA += pVector[i] * pVector[j] * iMinusj*iMinusj;
115 if ((pVector[i] > 0) && (pVector[j] > 0))
117 busynessA += std::abs<double>((i + 1.0)*pVector[i] - (j + 1.0)*pVector[j]);
118 complexity += std::abs<double>(iMinusj)*(pVector[i] * sVector[i] + pVector[j] * sVector[j]) / (pVector[i] + pVector[j]);
119 strengthA += (pVector[i] + pVector[j])*iMinusj*iMinusj;
123 double coarsness = 1.0 / std::min<double>(sumStimesP, 1000000);
128 contrast = contrastA / Ngp / (Ngp - 1) / count * sumS;
129 busyness = sumStimesP / busynessA;
135 strength = strengthA / sumS;
138 std::string prefix = params.prefix;
139 featureList.push_back(std::make_pair(prefix +
"Coarsness", coarsness));
140 featureList.push_back(std::make_pair(prefix +
"Contrast", contrast));
141 featureList.push_back(std::make_pair(prefix +
"Busyness", busyness));
142 featureList.push_back(std::make_pair(prefix +
"Complexity", complexity));
143 featureList.push_back(std::make_pair(prefix +
"Strength", strength));
161 GIFNeighbourhoodGreyToneDifferenceParameter params;
196 MITK_INFO <<
"Start calculating Neighbourhood Grey Tone Difference features ....";
197 if (parsedArgs.count(name +
"::range"))
199 int range =
us::any_cast<
int>(parsedArgs[name +
"::range"]);
203 featureList.insert(featureList.end(), localResults.begin(), localResults.end());
204 MITK_INFO <<
"Finished calculating Neighbourhood Grey Tone Difference features....";
210 std::ostringstream ss;
212 std::string strRange = ss.str();
#define AccessByItk_3(mitkImage, itkImageTypeFunction, arg1, arg2, arg3)
GIFNeighbourhoodGreyToneDifferenceFeatures()
void CalculateFeaturesUsingParameters(const Image::Pointer &feature, const Image::Pointer &mask, const Image::Pointer &maskNoNAN, FeatureListType &featureList) override
Calculates the feature of this abstact interface. Does not necessarily considers the parameter settin...
std::vector< std::string > FeatureNameListType
itk::Image< unsigned char, 3 > ImageType
virtual void SetLongName(std::string _arg)
ValueType * any_cast(Any *operand)
FeatureListType CalculateFeatures(const Image::Pointer &image, const Image::Pointer &feature) override
Calculates the Cooccurence-Matrix based features for this class.
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, mitkCommandLineParser::Channel channel=mitkCommandLineParser::Channel::None)
virtual void SetShortName(std::string _arg)
std::vector< std::pair< std::string, double > > FeatureListType
std::string QuantifierParameterString()
std::string FeatureDescriptionPrefix()
Returns a string that encodes the feature class name.
virtual void SetRange(int _arg)
virtual std::string GetLongName() const
std::string GetOptionPrefix() const
virtual int GetRange() const
FeatureNameListType GetFeatureNames() override
Returns a list of the names of all features that are calculated from this class.
mitk::Image::Pointer image
std::string GetCurrentFeatureEncoding() override
Adds an additional Separator to the name of the feature, which encodes the used parameters.
void AddQuantifierArguments(mitkCommandLineParser &parser)
static void CalculateIntensityPeak(itk::Image< TPixel, VImageDimension > *itkImage, mitk::Image::Pointer mask, GIFNeighbourhoodGreyToneDifferenceParameter params, mitk::GIFNeighbourhoodGreyToneDifferenceFeatures::FeatureListType &featureList)
virtual void SetFeatureClassName(std::string _arg)
void MITKCORE_EXPORT CastToItkImage(const mitk::Image *mitkImage, itk::SmartPointer< ItkOutputImageType > &itkOutputImage)
Cast an mitk::Image to an itk::Image with a specific type.
mitk::Image::Pointer mask
virtual IntensityQuantifier::Pointer GetQuantifier()
void InitializeQuantifierFromParameters(const Image::Pointer &feature, const Image::Pointer &mask, unsigned int defaultBins=256)
void AddArguments(mitkCommandLineParser &parser) override
virtual ParameterTypes GetParameter() const