[Insight-users] use PET volume in order to modify CT segmentation

Luis Ibanez luis.ibanez at kitware.com
Sun May 2 17:18:08 EDT 2010


Hi Marco,


                            Wecome to ITK !


Please take the time to read the introductory chapters
of the ITK Software Guide

         http://www.itk.org/ItkSoftwareGuide.pdf


In particular, you should read the "Data Representation"
chapter and its "Image"' section.

In your current code you are doing a lot of unnecessary
processing.

You are mixing

A) Creating an image from scratch, with
B) Reading the image from a file.


If what you want to do is to read the image from a file,
modify the pixels and save the modified version then
you should do:


   typedef short      PixelType;
   const   unsigned int        Dimension = 3;
   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  = argv[1];
   const char * outputFilename = argv[2];
   reader->SetFileName( inputFilename  );

   reader->Update();

  ImageType::Pointer image = reader->GetOutput();
  image->DisconnectPipeline();


   //  Then change the pixel values.
   //  Preferably using ImageIterators.

   then save the image with the Writer.


You DO NOT need to do the manual creation
of the image. That is done for you in the reader.


Note that there are many segmentation filters
already available in ITK. It is likely that one of
them already offers a segmentation processing
similar to what you are trying to implement.



   Regards,


        Luis



------------------------------------------------------------------------------
On Thu, Apr 29, 2010 at 3:58 AM, Marco Gheza
<marcogheza4mailinglists at gmail.com> wrote:
> Hi,
> i'm working with ITK and my purpose is to segment a gradient 3D image of a
> CT volume in the best way possible. I have to use smoothed PET volumes  in
> order to increase precision in segmenting the gradient image. My idea is to
> modify the gradient image voxel per voxel in particular those voxels that
> can make more sharp the edges. I wrote a code that accesses to voxels and
> modifies them. The problem is that a volume is made by a set of slice and  i
> can't modify simply the voxel but i must look also to changing slices.
> The code is here:
> #include "itkImage.h"
> #include "itkImageFileReader.h"
> #include "itkImageFileWriter.h"
> #include "itkImageToVTKImageFilter.h"
> #include "vtkImageViewer.h"
> int main( int argc, char * argv[] )
> {
>   // Verify the number of parameters in the command line
>   if( argc < 3 )
>     {
>     std::cerr << "Usage: " << std::endl;
>     std::cerr << argv[0] << " inputImageFile  outputImageFile " <<
> std::endl;
>     return EXIT_FAILURE;
>     }
>   typedef short      PixelType;
>   const   unsigned int        Dimension = 3;
>   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();
>
>   // Here we recover the file names from the command line arguments
>   //
>   const char * inputFilename  = argv[1];
>   const char * outputFilename = argv[2];
>   reader->SetFileName( inputFilename  );
>
> ///
> ImageType::Pointer image = reader->GetOutput();
>
>   ImageType::IndexType start;
>   ImageType::SizeType  size;
>   size[0]  = 100;  // size along X
>   size[1]  = 100;  // size along Y
>   size[2]  = 100;  // size along Z
>   start[0] =   109;  // first index on X
>   start[1] =   190;  // first index on Y
>   start[2] =   177;  // first index on Z
>   ImageType::RegionType region;
>   region.SetSize( size );
>   region.SetIndex( start );
>
>   // Pixel data is allocated
>   image->SetRegions( region );
>   image->Allocate();
>   ImageType::PixelType  initialValue = 0;
>   image->FillBuffer( initialValue );
>   reader->Update();
> image->DisconnectPipeline();
>    ImageType::IndexType pixelIndex;
>
>    int i,j,k;
>    for(i=103;i<203;i++)
>    {
> for(j=282;j<382;j++)
> {
> for(k=186;k<286;k++)
> {
> pixelIndex[0] = i;   // x position
> pixelIndex[1] = j;   // y position
> pixelIndex[2] = k;   // z position
> // ImageType::PixelType   pixelValue = image->GetPixel( pixelIndex );
> image->SetPixel(   pixelIndex,   256  );
> }
> }
>    }
> ///
>   writer->SetFileName( outputFilename );
>   writer->SetInput( image );
>   try
>     {
>     writer->Update();
>     }
>   catch( itk::ExceptionObject & err )
>     {
>     std::cerr << "ExceptionObject caught !" << std::endl;
>     std::cerr << err << std::endl;
>     return EXIT_FAILURE;
>     }
> }
>
> this code is only an example: it draws a 3D rectangle in the image. Imagine
> you want to modify the edges around liver. I'm not able to modify the
> desidered voxels using this code.
> Does anyone know how to simply access to the voxels in order to modify them?
> Please give an idea, also a raw idea...thanks so much.
> Bye,
> Marco
> _____________________________________
> 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