SimpleITK  
SimpleIO/SimpleIO.cxx
/*=========================================================================
*
* Copyright NumFOCUS
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0.txt
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*=========================================================================*/
// These examples are used in the I/O documentation page. The IO.rst file
// pulls the code examples based their line numbers in this file. So any
// change in the line numbers of the code below will break the I/O page.
// This one header will include all SimpleITK filters and external
// objects.
#include <SimpleITK.h>
#include <iostream>
#include <assert.h>
#include <typeinfo>
void example1(std::string inputImageFileName, std::string outputImageFileName)
{
reader.SetImageIO("PNGImageIO");
reader.SetFileName(inputImageFileName);
image = reader.Execute();
writer.SetFileName(outputImageFileName);
writer.Execute(image);
}
void example2(std::string inputImageFileName, std::string outputImageFileName)
{
image = itk::simple::ReadImage(inputImageFileName, itk::simple::sitkUnknown, "PNGImageIO");
itk::simple::WriteImage(image, outputImageFileName);
}
void example3()
{
basic_transform.SetTranslation(std::vector<double> {2.0, 3.0});
itk::simple::WriteTransform(basic_transform, "euler2D.tfm");
itk::simple::Transform read_result = itk::simple::ReadTransform("euler2D.tfm");
assert(typeid(basic_transform) != typeid(read_result));
}
int main ( int argc, char* argv[] ) {
if ( argc < 3 ) {
std::cerr << "Usage: " << argv[0] << " <input> <output>\n";
return 1;
}
std::cout << "Running first I/O example\n";
example1(argv[1], argv[2]);
std::cout << "Running second I/O example\n";
example2(argv[1], argv[2]);
std::cout << "Running transform I/O example\n";
example3();
return 0;
}
itk::simple::Image
The Image class for SimpleITK.
Definition: sitkImage.h:76
itk::simple::WriteTransform
SITKCommon_EXPORT void WriteTransform(const Transform &transform, const std::string &filename)
itk::simple::Transform
A simplified wrapper around a variety of ITK transforms.
Definition: sitkTransform.h:81
itk::simple::ImageFileWriter::SetFileName
Self & SetFileName(const std::string &fileName)
itk::simple::ImageFileWriter::Execute
Self & Execute(const Image &)
itk::simple::ImageFileReader
Read an image file and return a SimpleITK Image.
Definition: sitkImageFileReader.h:60
SimpleITK.h
itk::simple::ImageFileReader::SetFileName
Self & SetFileName(const std::string &fn)
itk::simple::Euler2DTransform
A rigid 2D transform with rotation in radians around a fixed center with translation.
Definition: sitkEuler2DTransform.h:35
itk::simple::Euler2DTransform::SetTranslation
Self & SetTranslation(const std::vector< double > &translation)
itk::simple::WriteImage
SITKIO_EXPORT void WriteImage(const Image &image, const std::string &fileName, bool useCompression=false, int compressionLevel=-1)
WriteImage is a procedural interface to the ImageFileWriter. class which is convenient for many image...
itk::simple::ReadImage
SITKIO_EXPORT Image ReadImage(const std::string &filename, PixelIDValueEnum outputPixelType=sitkUnknown, const std::string &imageIO="")
ReadImage is a procedural interface to the ImageFileReader class which is convenient for most image r...
itk::simple::ImageFileReader::Execute
Image Execute() override
Set/Get The output PixelType of the image.
itk::simple::ImageReaderBase::SetImageIO
virtual Self & SetImageIO(const std::string &imageio)
Set/Get name of ImageIO to use.
itk::simple::ReadTransform
SITKCommon_EXPORT Transform ReadTransform(const std::string &filename)
itk::simple::sitkUnknown
@ sitkUnknown
Definition: sitkPixelIDValues.h:91
itk::simple::ImageFileWriter
Write out a SimpleITK image to the specified file location.
Definition: sitkImageFileWriter.h:48