[ITK] [ITK-users] read/write images in ITK
Francois Budin
francois.budin at kitware.com
Mon Oct 3 10:49:32 EDT 2016
Hello,
If you use the ITK IO factory, your first piece of code should work. The
automatic detection of the image format does not rely on the inclusion of
"itkImage.h", but relies on itkImageFileReader.h.
Do you use CMake to configure your project? If so, if you have the
following lines in your CMakeLists files, everything should be done
automatically:
find_package(ITK REQUIRED)
include(${ITK_USE_FILE})
After configuring your project, your build directory should contain a
folder named ITKIOFactoryRegistration.
If you do not use CMake to configure your project, I strongly suggest you
to do so. It will simplify a lot of things.
You can also manually register the ITK IOs that you want to support before
use reading your file. You can find some information in the last part of
the documentation provided on this page:
https://itk.org/Wiki/ITK/FAQ
Hope this helps,
Francois
On Mon, Oct 3, 2016 at 10:01 AM, adariush <adariush at ast.cam.ac.uk> wrote:
> 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/community/attachments/20161003/f9ad6831/attachment.html>
-------------- next part --------------
_____________________________________
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