[Insight-users] Reading/writing images and CMake

Luis Ibanez luis.ibanez at kitware.com
Tue Nov 30 23:21:26 EST 2010


Hi Brecht,

Please see comments below.

On Fri, Nov 26, 2010 at 1:57 PM, Brecht Heyde
<Brecht.Heyde at med.kuleuven.be> wrote:
> Hi all,
>
>
>
> I am fairly new to ITK and have a couple of questions:
>
>
>
> 1. When creating a new ITK program, do I always have to go through CMake to
> create (in my case) a .sln Visual Studio Solution? Or do I otherwise have to
> specify all the additional directories + libraries for the linker manually?
>

Using CMake is the easiest way to configure ITK.

You can still use ITK from a project that doesn't use
CMake, but in that case, you want to install ITK, so
that you pass a smaller number of include directories
to your project.


>
>
> 2. I tried adapting the ImageReadWrite.cxx slightly in order to read the
> BrainMidSagittalSlice.png found in the ITK/Examples/Data directory.
> My source code is:
>
> #include "itkImageFileReader.h"
>
> #include "itkImageFileWriter.h"
>
>
>
> #include "itkImage.h"
>
>
>
>
>
> int main()
>
> {
>
>   typedef short      PixelType;
>
>   const   unsigned int        Dimension = 2;
>
>   typedef itk::Image< PixelType, Dimension >    ImageType;
>
>
>
>   typedef itk::ImageFileReader< ImageType >  ReaderType;
>
>   typedef itk::ImageFileWriter< ImageType >  WriterType;
>
>
>
>   ReaderType::Pointer reader = ReaderType::New();
>
>   WriterType::Pointer writer = WriterType::New();
>
>
>
>   const char * inputFilename  = "BrainMidSagittalSlice.png";
>
>   const char * outputFilename = "BrainMidSagittalSlice_output.png";
>
>
>
>   reader->SetFileName( inputFilename  );
>
>   writer->SetFileName( outputFilename );
>
>
>
>   writer->SetInput( reader->GetOutput() );
>
>
>
>   try
>
>     {
>
>     writer->Update();
>
>     }
>
>   catch( itk::ExceptionObject & err )
>
>     {
>
>     std::cerr << "ExceptionObject caught !" << std::endl;
>
>     std::cerr << err << std::endl;
>
>     return EXIT_FAILURE;
>
>     }
>
>
>
>   return EXIT_SUCCESS;
>
> }
>
>
>
> With CmakeList.txt:
>
>
>
>                 CMAKE_MINIMUM_REQUIRED(VERSION 2.4)
>
> IF(COMMAND CMAKE_POLICY)
>
>   CMAKE_POLICY(SET CMP0003 NEW)
>
> ENDIF(COMMAND CMAKE_POLICY)
>
>
>
>
>
> # This project is designed to be built outside the Insight source tree.
>
> PROJECT(ImageReadWrite)
>
>
>
> # Find ITK.
>
> FIND_PACKAGE(ITK REQUIRED)
>
> INCLUDE(${ITK_USE_FILE})
>
>
>
> ADD_EXECUTABLE(ImageReadWrite ImageReadWrite.cxx)
>
>
>
> TARGET_LINK_LIBRARIES(ImageReadWrite ITKIO)
>
>
>
> When running the resulting executable from a cmd prompt as ‘ImageReadWrite’,
> I get the following error:
>
>
>
> C:\ITK-dev\ImageReadWrite\debug>ImageReadWrite
>
> ExceptionObject caught !
>
>
>
> itk::ImageFileReaderException (0133F0CC)
>
> Location: "void __thiscall itk::ImageFileReader<class
> itk::Image<short,2>,class
>
> itk::DefaultConvertPixelTraits<short> >::GenerateOutputInformation(void)"
>
> File:
> c:\itk-src\insighttoolkit-3.20.0\insighttoolkit-3.20.0\code\io\itkImageFileReader.txx
>
> Line: 146
>
> Description:  Could not create IO object for file BrainMidSagittalSlice.png
>
>   Tried to create one of the following:
>
>     BioRadImageIO
>
>     GDCMImageIO
>
>     MetaImageIO
>
>     PNGImageIO
>
>     VTKImageIO
>
>     GiplImageIO
>
>     LSMImageIO
>
>     AnalyzeImageIO
>
>     NiftiImageIO
>
>     StimulateImageIO
>
>     JPEGImageIO
>
>     TIFFImageIO
>
>     NrrdImageIO
>
>     BMPImageIO
>
>     DICOMImageIO2
>
>   You probably failed to set a file suffix, or  set the suffix to an
> unsupported type.
>
>
>
> As I understood from previous mails on this list, the IO object decides
> automatically to what format it should write. What am I doing wrong?
>
>


The problem is that you are not giving the full path to your image:


>   const char * inputFilename  = "BrainMidSagittalSlice.png";


The executable is looking for this image in the same directory
where the executable is launched from.

You should pass something like:

    "C:/Users/brecht/myimages/BrainMidSagittalSlice.png";

>
> 3. I’d like to read a 3D+time dataset in ITK. The original dataset is in
> dicom format but I have previously extracted the relevant data and converted
> to a .mat format for further processing in Matlab (in practice this is just
> one big 4D matrix). Furthermore, we have developed a visualisation tool to
> manually segment such a dataset and export a mesh (cloud of points with
> connectivity matrix) containing this manual contouring.
>
>

ITK will read DICOM, VTK, Meta, PNG, TIFF, JPEG, GIPL, Nifti, Nrrd
as image file formats.

If you have a raw binary block, you can write a Meta image header for it:

See detail in
http://www.itk.org/ITK/resources/links.html


>
> I was wondering what format I could use to import such a series of 3D
> matrices and import this cloud of points. I doubt that a dicomreader would
> work as the image data is stored in a private datastructure in the
> dicomformat.
>
>

Why would the image data be stored in private tags ?

Have you tried reading your DICOM image with ITK directly ?


>
> 4. I’d like to register this set of 3D images and know how my cloud of
> points are deformed by the registration algorithm. Is this possible in ITK?


ITK has a variety of registration algorithms.
Please see the ITK Software Guide for full details.
http://www.itk.org/ItkSoftwareGuide.pdf


> Likewise, would it be possible to calculate how an overlying grid deforms
> due to this registration?

Please see this paper in the Insight Journal:
http://www.insight-journal.org/browse/publication/140


Finally, I would like to export the positions of
> this deformed set of points (and preferably the deformed floating images).

You could save the deformed images in DICOM,
I believe that Matlab has a dicom reader.

You could also save them as Meta image (.mhd  extension)
this will give you two files (a header text file with .mhd extension)
and (a binary file with .raw extension).  You should be able to
read the .raw file in Matlab by using the parameters in the
.mhd file.



> Can I do this in a Matlab compatible format or do I have to write a mex
> wrapper for this?
>
>

You should be able to do this
without a mex wrapper.


     Regards,


              Luis

>
> Many thanks,
>
>
>
> Best regards,
>
> Brecht
>
>
>
> _____________________________________
> 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.html
>
> 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://www.itk.org/mailman/listinfo/insight-users
>
>


More information about the Insight-users mailing list