[ITK] [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
_____________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html

Kitware offers ITK Training Courses, for more information visit:
http://www.kitware.com/products/protraining.php

Please keep messages on-topic and check the ITK FAQ at:
http://www.itk.org/Wiki/ITK_FAQ

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/insight-users


More information about the Community mailing list