[Insight-users] Reading ROI of 3D volume from 2D slices
Matthias Schneider
schneider at vision.ee.ethz.ch
Fri Oct 7 10:15:52 EDT 2011
Hi,
I am trying to load a 3D volume from 2D slices using
itkImageSeriesReader (ITK v3.20.0). Moreover, I'm using
itkRegionOfInterestImageFilter to read a particular subvolume. Some
sample code is attached at the very end.
The code works fine as long as all slice files are available. However,
when deleting slice 'img_0003.tif', I get an ImageFileReaderException.
Even though the itkImageSeriesReader::GenerateData() is supposed to read
only slices that are inside of the requested region, slices outside the
ROI are not skipped (ll 317/337: needToUpdateMetaDataDictionaryArray is
true!)
Is there any way to circumvent this problem except for manually
selecting the slices to be read and adjusting the ROI properly?
Any hint is appreciated very much!
Thanks,
matthias
======
Here is the code:
#include <itkImage.h>
#include <itkImageSeriesReader.h>
#include <itkRegionOfInterestImageFilter.h>
int main(int, char **) {
typedef itk::Image<unsigned int, 2> SliceType;
typedef itk::Image<unsigned int, 3> VolumeType;
typedef itk::ImageSeriesReader<VolumeType> VolumeReaderType;
// slice images [256x256]
std::vector<std::string> input_slices;
input_slices.push_back("img_0001.tif");
input_slices.push_back("img_0002.tif");
input_slices.push_back("img_0003.tif");
VolumeReaderType::Pointer reader = VolumeReaderType::New();
reader->SetFileNames(input_slices);
VolumeType::RegionType roi;
double range[6] = { 0, 255, 0, 255, 0, 1 };
for (int i = 0; i < 3; ++i) {
roi.SetIndex(i, range[2 * i]);
roi.SetSize(i, range[2 * i + 1] - range[2 * i] + 1);
}
typedef itk::RegionOfInterestImageFilter<VolumeType, VolumeType>
ROIFilterType;
ROIFilterType::Pointer roiFilter = ROIFilterType::New();
roiFilter->SetRegionOfInterest(roi);
roiFilter->SetInput(reader->GetOutput());
reader->UseStreamingOn();
roiFilter->Update();
return EXIT_SUCCESS;
}
--
Matthias Schneider
Computer Vision Laboratory
ETH Zürich, ETF D114.1
Sternwartstrasse 7
CH-8092 Zürich, Switzerland
fon: +41 44 63 20379
fax: +41 44 63 21199
More information about the Insight-users
mailing list