[ITK-users] read/write images in ITK

adariush adariush at ast.cam.ac.uk
Mon Oct 3 10:01:49 EDT 2016


Hello,

I am using ITK 10.0 on a MacBook Pro running on OS X El Capitan.

I have problem with reading/writing images. For example to read/write 
PNG image formats, I expect to do something like this:

=========================================================
#include "itkImage.h"
#include "itkImageFileReader.h"

typedef unsigned char  InputPixelType;
typedef itk::Image< InputPixelType , 2 > InputImageType;
typedef itk::ImageFileReader<InputImageType> ReaderType;
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName('image name');
reader->Update();
=========================================================
However, the above code returns an error since it seems that 
"itkImage.h" does nothing at all!

Instead every time I want to read/write a PNG image, I should modify the 
above code as follow:


=========================================================
#include "itkImageFileReader.h"
#include "itkPNGImageIOFactory.h"                        // new line

typedef unsigned char  InputPixelType;
typedef itk::Image< InputPixelType , 2 > InputImageType;
typedef itk::ImageFileReader<InputImageType> ReaderType;
ReaderType::Pointer reader = ReaderType::New();
itk::PNGImageIOFactory::RegisterOneFactory();             // new line
reader->SetFileName('image name');
reader->Update();
=========================================================


In short, I expect by including "itkImage.h", ITK automatically identify 
input/output image format. However, I have to do it manually. The 
problem is when I want to read for example a '.mha' file format.

Does anyone know what might be the problem and how could I 'SOLVE' it?

Thanks, Ali


More information about the Insight-users mailing list