SimpleITK  
ImageGridManipulation/ImageGridManipulation.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.
*
*=========================================================================*/
// This one header will include all SimpleITK filters and external
// objects.
#include <SimpleITK.h>
#include <iostream>
#include <stdlib.h>
namespace sitk = itk::simple;
int
main(int argc, char * argv[])
{
if (argc < 3)
{
std::cerr << "Usage: " << argv[0] << " <input-1> <input-2>" << std::endl;
return 1;
}
// Two vector images of same pixel type and dimension expected
sitk::Image image1 = sitk::ReadImage(argv[1]);
sitk::Image image2 = sitk::ReadImage(argv[2]);
// Join two N-D Vector images to form an (N+1)-D image
sitk::Image joinedImage = join.Execute(image1, image2);
// Extract first three channels of joined image (assuming RGB)
select.SetOutputPixelType(sitk::sitkUInt8);
select.SetIndex(0);
sitk::Image channel1Image = select.Execute(joinedImage);
select.SetIndex(1);
sitk::Image channel2Image = select.Execute(joinedImage);
select.SetIndex(2);
sitk::Image channel3Image = select.Execute(joinedImage);
// Recompose image (should be same as joined_image)
sitk::Image composedImage = compose.Execute(channel1Image, channel2Image, channel3Image);
// Select same subregion using ExtractImageFilter
extract.SetSize({ 30, 30, 0 });
extract.SetIndex({ 10, 10, 0 });
sitk::Image extractedImage = extract.Execute(composedImage);
// Select same sub-region using CropImageFilter (NOTE: CropImageFilter cannot
// reduce dimensions unlike ExtractImageFilter, so cropped_image is a three
// dimensional image with depth of 1)
crop.SetLowerBoundaryCropSize({ 10, 10, 0 });
crop.SetUpperBoundaryCropSize({ composedImage.GetWidth() - 40, composedImage.GetHeight() - 40, 1 });
sitk::Image croppedImage = crop.Execute(composedImage);
// Print image information to demonstrate variable usage
std::cout << "Extracted image size: " << extractedImage.GetWidth() << "x" << extractedImage.GetHeight() << "x"
<< extractedImage.GetDepth() << std::endl;
std::cout << "Cropped image size: " << croppedImage.GetWidth() << "x" << croppedImage.GetHeight() << "x"
<< croppedImage.GetDepth() << std::endl;
return 0;
}
ComposeImageFilter combine several scalar images into a multicomponent image.
Image Execute(const std::vector< Image > &images)
Decrease the image size by cropping the image by an itk::Size at both the upper and lower bounds of t...
Image Execute(Image &&image1)
void SetUpperBoundaryCropSize(std::vector< unsigned int > UpperBoundaryCropSize)
void SetLowerBoundaryCropSize(std::vector< unsigned int > LowerBoundaryCropSize)
Decrease the image size by cropping the image to the selected region bounds.
Image Execute(Image &&image1)
void SetSize(std::vector< unsigned int > Size)
Set the size of the region to extract.
void SetIndex(std::vector< int > Index)
Set the starting index of the input image to extract.
The Image class for SimpleITK.
Definition sitkImage.h:77
unsigned int GetDepth() const
unsigned int GetHeight() const
unsigned int GetWidth() const
Join N-D images into an (N+1)-D image.
Image Execute(const std::vector< Image > &images)
Extracts the selected index of the vector that is the input pixel type.
void SetOutputPixelType(PixelIDValueEnum OutputPixelType)
Set the output pixel type of the scalar component to extract.
SITKIO_EXPORT Image ReadImage(const PathType &filename, PixelIDValueEnum outputPixelType=sitkUnknown, const std::string &imageIO="")
ReadImage is a procedural interface to the ImageFileReader class which is convenient for most image r...