[Insight-users] How to access every image?
Mark Foskey
mark_foskey at unc . edu
Thu, 25 Sep 2003 11:02:05 -0400
jiang wrote:
> Hi, all
> I read a series of DICOM images by itkImageSeriesReader. Now I want to
> access one image of this series. How can I get it?
> Thank you very much!
>
> Chunyan
>
You can create a region that has a thickness of 1 slice and use
ExtractImageFilter. I generated my region by starting with
GetLargestPossibleRegion and changing the size. Here's a code sample
below. I didn't include the #includes.
typedef itk::Image< float, 3 > InputImageType;
typedef itk::Image< float, 2 > ExtractorImageType;
typedef itk::Image< unsigned short, 2 > OutputImageType;
int main( int argc, char * argv[] )
{
if( argc < 3 )
{
std::cerr << "Usage: " << argv[0]
<< " inputImage outputImage sliceNumber"
<< std::endl;
return 1;
}
//-------------------------------------
// Reader
typedef itk::ImageFileReader< InputImageType > ReaderType;
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName( argv[1] );
//-------------------------------------
// Slice region and index
reader->Update();
InputImageType::RegionType sliceRegion =
reader->GetOutput()->GetLargestPossibleRegion();
unsigned long lastSlice = sliceRegion.GetSize( 2 ) - 1;
sliceRegion.SetSize( 2, 0 );
std::istringstream ist( argv[3] );
unsigned int whichSlice;
ist >> whichSlice;
if( whichSlice > lastSlice ) { whichSlice = lastSlice; }
sliceRegion.SetIndex( 2, whichSlice );
//-------------------------------------
// Extractor
typedef itk::ExtractImageFilter<
InputImageType, ExtractorImageType > ExtractorType;
ExtractorType::Pointer extractor = ExtractorType::New();
extractor->SetExtractionRegion( sliceRegion );
extractor->SetInput( reader->GetOutput() );
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk . org
> http://www . itk . org/mailman/listinfo/insight-users
--
Mark Foskey (919) 843-5436 Computer-Aided Diagnosis and Display Lab
mark_foskey at unc . edu Department of Radiology, CB 7515, UNC
http://www . cs . unc . edu/~foskey Chapel Hill, NC 27599-7515