Get zero size when read an image

I tried to use the following code to read an image

#include “itkImageFileReader.h”
#include “itkImage.h”

int main(int argc, char * argv[]){
const unsigned int Dimension = 3;
typedef float PixelType;
typedef itk::Image< PixelType, Dimension > ImageType;
typedef itk::ImageFileReader< ImageType > ImageReaderType;
ImageReaderType::Pointer fixedImageReader = ImageReaderType::New();
fixedImageReader->SetFileName(argv[1]);

ImageType::SizeType size = fixedImageReader->GetOutput()->GetLargestPossibleRegion().GetSize();
std::cout<<"image size "<<size<<std::endl;

return EXIT_SUCCESS;

}

I am able to open the image with software like Slicer, but the out put image size is [0 0 0]. Could anyone help? Thanks!

1 Like

Hi,

You should call Update() on the reader, otherwise the image will not be read.

HTH,

Tim

1 Like