17 #include "itkImageRegionIterator.h"
24 #include <itkOtsuMultipleThresholdsImageFilter.h>
34 int main(
int argc,
char *argv[])
37 parser.
setTitle(
"Mri Normalization");
39 parser.
setDescription(
"Normalizes an MRI volume based on regions determined by Otsu.");
54 map<string, us::Any> parsedArgs = parser.
parseArguments(argc, argv);
57 if (parsedArgs.size() == 0 || parsedArgs.count(
"help") || parsedArgs.count(
"h"))
63 std::string outFile =
us::any_cast<
string>(parsedArgs[
"output"]);
65 int numberOfThresholds =
us::any_cast<
int>(parsedArgs[
"bins"]);
72 typedef itk::OtsuMultipleThresholdsImageFilter<FeatureImage, FeatureImage> FilterType;
74 otsuFilter->SetInput(itkInputImage);
75 otsuFilter->SetNumberOfThresholds(numberOfThresholds - 1);
80 std::vector<mitk::ScalarType> medianMin;
81 std::vector<mitk::ScalarType> medianMax;
83 itk::ImageRegionIterator<FeatureImage> inputIt(itkInputImage, itkInputImage->GetLargestPossibleRegion());
84 itk::ImageRegionIterator<FeatureImage> labelIt(itkLabelImage, itkLabelImage->GetLargestPossibleRegion());
86 while (!inputIt.IsAtEnd())
88 if (labelIt.Get() == minBin)
90 medianMin.push_back(inputIt.Get());
92 else if (labelIt.Get() == maxBin)
94 medianMax.push_back(inputIt.Get());
100 std::sort(medianMax.begin(), medianMax.end());
101 std::sort(medianMin.begin(), medianMin.end());
109 while (!inputIt.IsAtEnd())
111 inputIt.Set(1.0 * (inputIt.Get() - minVal) / (maxVal - minVal));
static void Save(const mitk::BaseData *data, const std::string &path)
Save a mitk::BaseData instance.
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)
itk::ImageRegionIterator< FeatureImage > FeatureIteratorType
Image::Pointer GrabItkImageMemory(itk::SmartPointer< ItkOutputImageType > &itkimage, mitk::Image *mitkImage=nullptr, const BaseGeometry *geometry=nullptr, bool update=true)
Grabs the memory of an itk::Image (with a specific type) and puts it into an mitk::Image.The memory is managed by the mitk::Image after calling this function. The itk::Image remains valid until the mitk::Image decides to free the memory.
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)
void setCategory(std::string category)
itk::Image< unsigned char, 3 > SeedImage
itk::Image< mitk::ScalarType, 3 > FeatureImage
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::string helpText() const
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.
itk::ImageRegionIterator< SeedImage > SeedIteratorType
int main(int argc, char *argv[])
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.