22 template <
typename TPixelType>
28 const auto DEPTH =
static_cast<itk::IndexValueType
>(outputImage->GetDimension(2));
29 const auto HEIGHT =
static_cast<itk::IndexValueType
>(outputImage->GetDimension(1));
30 const auto WIDTH =
static_cast<itk::IndexValueType
>(outputImage->GetDimension(0));
32 auto geometry = outputImage->GetGeometry();
36 for (index[2] = 0; index[2] < DEPTH; ++index[2])
38 for (index[1] = 0; index[1] < HEIGHT; ++index[1])
40 for (index[0] = 0; index[0] < WIDTH; ++index[0])
42 geometry->IndexToWorld(index, worldCoords);
49 int main(
int argc,
char* argv[])
55 parser.
setDescription(
"Resample image based on standard world to index transform");
64 if (2 != parsedArgs.size() || 0 == parsedArgs.count(
"input") || 0 == parsedArgs.count(
"output"))
79 if (3 != inputImage->GetDimension())
81 MITK_ERROR <<
"Only 3-d images are supported.";
85 auto inputGeometry = inputImage->GetGeometry();
91 inputGeometry->IndexToWorld(minInputIndex, minInputIndexInWorld);
94 for (
int i = 0; i < 3; ++i)
95 maxInputIndex[i] = inputGeometry->GetExtent(i) - 1;
98 inputGeometry->IndexToWorld(maxInputIndex, maxInputIndexInWorld);
101 for (
int i = 0; i < 3; ++i)
102 minOutputIndexInWorld[i] =
std::min(minInputIndexInWorld[i], maxInputIndexInWorld[i]);
105 for (
int i = 0; i < 3; ++i)
106 maxOutputIndexInWorld[i] =
std::max(minInputIndexInWorld[i], maxInputIndexInWorld[i]);
109 auto transform = inputGeometry->GetIndexToWorldTransform()->Clone();
110 auto matrix = transform->GetMatrix();
112 for (
int i = 0; i < 3; ++i)
114 for (
int j = 0; j < 3; ++j)
116 matrix[i][j] = std::abs(matrix[i][j]) / spacing[j];
120 transform->SetMatrix(matrix);
121 spacing = transform->TransformVector(spacing);
123 mitk::Vector3D outputExtent = (maxOutputIndexInWorld - minOutputIndexInWorld + spacing);
124 for (
int i = 0; i < 3; ++i)
125 outputExtent[i] /= spacing[i];
136 planeGeometry->InitializeStandardPlane(right, down, &spacing);
137 planeGeometry->SetOrigin(origin);
138 planeGeometry->SetImageGeometry(
true);
141 slicedGeometry->InitializeEvenlySpaced(planeGeometry, static_cast<unsigned int>(outputExtent[2]));
144 outputGeometry->SetTimeStepGeometry(slicedGeometry, 0);
146 auto pixelType = inputImage->GetPixelType();
149 outputImage->Initialize(pixelType, *outputGeometry);
153 switch (pixelType.GetComponentType())
155 case itk::ImageIOBase::CHAR:
156 RectifyImage<char>(inputImage, outputImage);
159 case itk::ImageIOBase::UCHAR:
160 RectifyImage<unsigned char>(inputImage, outputImage);
163 case itk::ImageIOBase::SHORT:
164 RectifyImage<short>(inputImage, outputImage);
167 case itk::ImageIOBase::USHORT:
168 RectifyImage<unsigned short>(inputImage, outputImage);
US_Core_EXPORT std::string any_value_to_string(const Any &any)
Gives locked and index-based write access for a particular image part. The class provides several set...
Gives locked and index-based read access for a particular image part. The class provides several set-...
void setContributor(std::string contributor)
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)
std::map< std::string, us::Any > parseArguments(const StringContainerType &arguments, bool *ok=nullptr)
void FillVector3D(Tout &out, mitk::ScalarType x, mitk::ScalarType y, mitk::ScalarType z)
int main(int argc, char *argv[])
An object of this class represents an exception of MITK. Please don't instantiate exceptions manually...
Image class for storing images.
void RectifyImage(mitk::Image::Pointer inputImage, mitk::Image::Pointer outputImage)
void setCategory(std::string category)
void SetPixelByIndex(const itk::Index< VDimension > &idx, const TPixel &value)
Sets a pixel value at given index.
void setArgumentPrefix(const std::string &longPrefix, const std::string &shortPrefix)
static void Save(const mitk::BaseData *data, const std::string &path, bool setPathProperty=false)
Save a mitk::BaseData instance.
void setTitle(std::string title)
void setDescription(std::string description)
static DataStorage::SetOfObjects::Pointer Load(const std::string &path, DataStorage &storage, const ReaderOptionsFunctorBase *optionsCallback=nullptr)
Load a file into the given DataStorage.
const TPixel & GetPixelByWorldCoordinates(mitk::Point3D position)