Last active
September 1, 2015 11:36
-
-
Save lesolorzanov/6640519d409e35f00811 to your computer and use it in GitHub Desktop.
My ITK tips
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Create a float image the size of a short image | |
* This is an example of how to create an image of | |
* a different type but same size as a given image | |
*/ | |
FloatImageType::Pointer ppRecruitImage = FloatImageType::New(); | |
//define origin and size the same as the input | |
//get the biggest region (which usually is the whole image) | |
ImageType::RegionType imageregion=expImage->GetLargestPossibleRegion(); | |
//get the image origin | |
ImageType::IndexType imageIndex=imageregion.GetIndex(); | |
//get the image size | |
ImageType::SizeType imagesize= imageregion.GetSize(); | |
//get the image spacing | |
ImageType::SpacingType spacing=expImage->GetSpacing(); | |
ImageType::PointType imageorigin=expImage->GetOrigin(); | |
//create region size and spacing for the output image type | |
FloatImageType::IndexType floatIndex; | |
FloatImageType::SizeType floatSize; | |
FloatImageType::SpacingType floatSpacing; | |
FloatImageType::PointType floatorigin; | |
//this will be the number of voxels in the image | |
//we can use it as a stopping condition | |
int cvoxels=1; | |
//set the new images' index, size and spacing | |
for(int i=0; i <dims; i++){ | |
floatIndex[i]=imageIndex[i]; | |
floatSize[i]=imagesize[i]; | |
floatSpacing[i]=spacing[i]; | |
floatorigin[i]=imageorigin[i]; | |
cvoxels*=imagesize[i]; | |
} | |
//create region | |
FloatImageType::RegionType region; | |
//set their sizes, index | |
region.SetSize( floatSize ); | |
region.SetIndex( floatIndex ); | |
//create the image | |
ppRecruitImage->SetRegions( region ); | |
ppRecruitImage->SetSpacing( floatSpacing ); | |
ppRecruitImage->Allocate(); | |
ppRecruitImage->FillBuffer(0.0); | |
ppRecruitImage->SetOrigin(floatorigin); | |
/* | |
* How to use image duplicator | |
*/ | |
typedef itk::ImageDuplicator< ImageType > DuplicatorType; | |
DuplicatorType::Pointer duplicator = DuplicatorType::New(); | |
duplicator->SetInputImage(expImage); | |
duplicator->Update(); | |
ImageType::Pointer outImage = duplicator->GetOutput(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment