[Insight-users] Problem when collapsing a dimension
in itkExtractImageFilter
Karthik Krishnan
Karthik.Krishnan at kitware.com
Wed Sep 7 17:22:44 EDT 2005
Thanks for reporting the bug.
Andinet found a bug in the filter. The Output image direction was not
correctly updated when the extracted output image had dimensions less
than the input image.
Please update
Code/BasicFilters/itkExtractImageFilter.txx
Regards
karthik
Didier Rajon wrote:
> Hi
> I'm having a problem with itkExtractImageFilter. When I try to extract
> a 2D slice from a 3D image dataset, the slice seems to be extracted
> correctly, but the spacing of the first dimension of the slice is
> always 0.
> I just switched from ITK 2.0 to ITK 2.2 and the problem only happens
> with ITK 2.2, never with ITK 2.0.
> I'm using ITK on redhat linux 9.0.
> I attached a little C++ program to show the problem. The program
> reads a 3D image from a file, display the spacing of the image,
> extract a slice perpendicular to the 3rd dimension, and display the
> spacing of the slice.
> If I compile the program with ITK 2.0 and execute the program, I get
> the following result:
>
> Executing program ExtractSlice.
> Input file name: My3DImage.vtk.
> Slice no: 15.
> Reading input image.
> Execution terminated successfully.
> Input spacing: [2, 2, 2]
> Extracting slice no 15.
> Execution terminated successfully.
> Slice spacing: [2, 2]
>
> If I compile the program with ITK 2.2 and execute the program I get
> the following result:
>
> Executing program ExtractSlice.
> Input file name: My3DImage.vtk.
> Slice no: 15.
> Reading input image.
> Execution terminated successfully.
> Input spacing: [2, 2, 2]
> Extracting slice no 15.
> Execution terminated successfully.
> Slice spacing: [0, 2]
>
> The first dimension of the slice has been set to 0 by the filter.
>
> Note that if I don't collapse the dimension (by setting the size of
> the extraction region to [Nx, Ny, 1] instead of [Nx, Ny, 0] and
> setting the filter output type to a 3D image), I get the correct
> spacing: [2, 2, 2]. This problem seems to occur only if I try to
> collapse a dimension.
>
> Is there anything that has changed with ITK 2.2 and that I should
> incorporate to my program in order to get the correct spacing?
> Thanks for helping me solving this problem.
>
> Didier.
>
>------------------------------------------------------------------------
>
>// system include files
>#include <string>
>
>// itk include files
>#include "itkImageFileReader.h"
>#include "itkExtractImageFilter.h"
>
>// local include files.
>
>main (int argc, char **argv)
> {
> // 0) To get and check the program arguments.
> /////////////////////////////////////////////
> std::string inputFileName;
> int sliceNo;
> {
> // To check the command line
> if ( argc != 3 )
> {
> std::cerr << "Error: bad command-line. Try again with command-line:" << std::endl;
> std::cerr << "ExtractSlice InputFileName SliceNo" << std::endl;
> std::cerr << " - InputFileName: The full path name of the file that contains the input image." << std::endl;
> std::cerr << " - SliceNo: The slice to be extracted." << std::endl;
> std::cerr << "ex: ExtractSlice ./LowResolution.vtk 12" << std::endl;
> exit(0);
> }
> // To get the arguments.
> inputFileName = argv[1];
> sliceNo = atoi(argv[2]);
> std::cout << std::endl << "Executing program ExtractSlice." << std::endl;
> std::cout << "Input file name: " << inputFileName << "." << std::endl;
> std::cout << "Slice no: " << sliceNo << "." << std::endl;
> std::cout << std::endl;
> }
>
> // 1) To define the image type.
> ///////////////////////////////
> const unsigned int ImageDimension = 3;
> const unsigned int SliceDimension = 2;
> typedef unsigned short VoxelType;
> typedef itk::Image<VoxelType, ImageDimension> ImageType;
> typedef itk::Image<VoxelType, SliceDimension> SliceType;
>
> // 2) To read the input image.
> //////////////////////////////
> ImageType::Pointer inputImage;
> {
> std::cout << "Reading input image." << std::endl;
> typedef itk::ImageFileReader<ImageType> ReaderType;
> ReaderType::Pointer imageReader = ReaderType::New();
> imageReader->SetFileName(inputFileName.c_str());
> try {
> imageReader->Update();
> std::cout << "Execution terminated successfully." << std::endl;
> }
> catch(itk::ExceptionObject & err) {
> std::cerr << err << std::endl;
> exit(0);
> }
> inputImage = imageReader->GetOutput();
> }
> std::cout << "Input spacing: " << inputImage->GetSpacing() << std::endl;
>
> // 3) To extract the slice.
> ///////////////////////////
> SliceType::Pointer extractedSlice;
> {
> std::cout << "Extracting slice no " << sliceNo << "." << std::endl;
> typedef itk::ExtractImageFilter<ImageType, SliceType> FilterType;
> FilterType::Pointer sliceExtractor = FilterType::New();
> sliceExtractor->SetInput(inputImage);
> ImageType::RegionType extractionRegion = inputImage->GetLargestPossibleRegion();
> ImageType::SizeType extractionSize = extractionRegion.GetSize();
> ImageType::IndexType extractionIndex = extractionRegion.GetIndex();
> extractionSize[2] = 0;
> extractionIndex[2] = sliceNo;
> extractionRegion.SetSize(extractionSize);
> extractionRegion.SetIndex(extractionIndex);
> sliceExtractor->SetExtractionRegion(extractionRegion);
> try {
> sliceExtractor->Update();
> std::cout << "Execution terminated successfully."
> << std::endl;
> }
> catch(itk::ExceptionObject & err) {
> std::cerr << err << std::endl;
> exit(0);
> }
> extractedSlice = sliceExtractor->GetOutput();
> }
> std::cout << "Slice spacing: " << extractedSlice->GetSpacing() << std::endl;
> }
>
>
>
>------------------------------------------------------------------------
>
>_______________________________________________
>Insight-users mailing list
>Insight-users at itk.org
>http://www.itk.org/mailman/listinfo/insight-users
>
>
More information about the Insight-users
mailing list