[ITK] [ITK-users] read/write images in ITK

Timothee Evain tevain at telecom-paristech.fr
Mon Oct 3 10:47:44 EDT 2016


Hi,

Including the itkImage header as nothing to do with the ImageReader correctly calling the needed ImageIO.
Could you provide the error that arise when you try to read your image ?

Tim

----- Mail original -----
De: "adariush" <adariush at ast.cam.ac.uk>
À: insight-users at itk.org
Envoyé: Lundi 3 Octobre 2016 16:01:49
Objet: [ITK] [ITK-users] read/write images in ITK

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
_______________________________________________
Community mailing list
Community at itk.org
http://public.kitware.com/mailman/listinfo/community
_____________________________________
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