[Insight-users] size of image
john smith
mkitkinsightuser at gmail.com
Sat May 28 10:30:21 EDT 2011
Hello,
I am using ITK for my project and I have wrote the following code.Could
somebody tell me how can I get the size of my image?
Thanks in advance
typedef unsigned char InputPixelType;
typedef unsigned char OutputPixelType;
typedef itk::Image< InputPixelType, 3 > InputImageType;
typedef itk::Image< OutputPixelType, 2 > OutputImageType;
typedef itk::ImageFileReader< InputImageType > ReaderType;
typedef itk::ImageFileWriter< OutputImageType > WriterType;
ReaderType::Pointer reader = ReaderType::New();
WriterType::Pointer writer = WriterType::New();
reader->SetFileName( fileName.toStdString() );
writer->SetFileName( "2D.png" );
typedef itk::ExtractImageFilter< InputImageType, OutputImageType >
FilterType;
FilterType::Pointer filter = FilterType::New();
reader->Update();
InputImageType::RegionType inputRegion =
reader->GetOutput()->GetLargestPossibleRegion();
InputImageType::SizeType size = inputRegion.GetSize();
size[2] = 0;
InputImageType::IndexType start = inputRegion.GetIndex();
const unsigned int sliceNumber = 89;
start[2] = sliceNumber;
InputImageType::RegionType desiredRegion;
desiredRegion.SetSize( size );
desiredRegion.SetIndex( start );
filter->SetExtractionRegion( desiredRegion );
filter->SetInput( reader->GetOutput() );
writer->SetInput( filter->GetOutput() );
try
{
writer->Update();
}
catch( itk::ExceptionObject & err )
{
std::cerr << "ExceptionObject caught !" << std::endl;
std::cerr << err << std::endl;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20110528/97ff0f54/attachment.htm>
More information about the Insight-users
mailing list