[Insight-users] error during extracting slice from 3D image
alaamegawer
alaamegawer at yahoo.com
Tue Mar 13 17:48:48 EDT 2012
Hi all
actually i want to extract slice from 3D image , in x or y dir , i used itk
example . and it's working great if i extract in z direction but if i try to
extract in x or y direction i have run time error
the error is , itk::error : extractimagefilter: invalid submatrix extracted
for collapsed direction
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
#include "itkExtractImageFilter.h"
#include "itkImage.h"
int main( int argc, char ** argv )
{
typedef signed char InputPixelType;
typedef signed char OutputPixelType;
typedef itk::Image< InputPixelType, 3 > InputImageType;
typedef itk::Image< OutputPixelType, 2 > OutputImageType;
typedef itk::ImageFileReader< InputImageType > ReaderType;
typedef itk::ImageFileWriter< OutputImageType > WriterType;
const char * inputFilename =
"C:/Users/Administrator/Desktop/test/src/brainweb1e1a10f20.mha";
const char * outputFilename =
"C:/Users/Administrator/Desktop/test/src/brainweb.mha";
ReaderType::Pointer reader = ReaderType::New();
WriterType::Pointer writer = WriterType::New();
reader->SetFileName( inputFilename );
writer->SetFileName( outputFilename );
typedef itk::ExtractImageFilter< InputImageType, OutputImageType >
FilterType;
FilterType::Pointer filter = FilterType::New();
filter->InPlaceOn();
filter->SetDirectionCollapseToSubmatrix();
reader->UpdateOutputInformation();
InputImageType::RegionType inputRegion =
reader->GetOutput()->GetLargestPossibleRegion();
InputImageType::SizeType size = inputRegion.GetSize();
size[0] = 0;
InputImageType::IndexType start = inputRegion.GetIndex();
const unsigned int sliceNumber = 0;
start[0] = 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;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
please help me if u can
--
View this message in context: http://itk-insight-users.2283740.n2.nabble.com/error-during-extracting-slice-from-3D-image-tp7370067p7370067.html
Sent from the ITK Insight Users mailing list archive at Nabble.com.
More information about the Insight-users
mailing list