[Insight-users] Interpolation Volume

Gupt adityargupta at gmail.com
Wed Dec 9 11:14:33 EST 2009


Hello Luis,

I'm using the ImageSeriesReadWrite example from ITK User guide. I'm reading
a set of 2d png images and writing to a 3d file. Irene280052.png to
Irene280061.png - grayscale images of size 131 X141. With the program below,
at the command prompt I call the program with parameters >>ImageReadWrite 52
61 out1.mhd. 

Program:

#include "itkImage.h"
#include "itkImageSeriesReader.h"
#include "itkImageFileWriter.h"
#include "itkNumericSeriesFileNames.h"
#include "itkPNGImageIO.h"

int main( int argc, char ** argv )
{
  // Verify the number of parameters in the command line
  if( argc < 4 )
    {
    std::cerr << "Usage: " << std::endl;
    std::cerr << argv[0] << " firstSliceValue lastSliceValue 
outputImageFile " << std::endl;
    return EXIT_FAILURE;
    }
 
  typedef unsigned char                       PixelType;
  const unsigned int Dimension = 3;

  typedef itk::Image< PixelType, Dimension >  ImageType;
  typedef itk::ImageSeriesReader< ImageType >  ReaderType;
  typedef itk::ImageFileWriter<   ImageType >  WriterType;

  ReaderType::Pointer reader = ReaderType::New();
  WriterType::Pointer writer = WriterType::New();

  const unsigned int first = atoi( argv[1] );
  const unsigned int last  = atoi( argv[2] );

  const char * outputFilename = argv[3];

  typedef itk::NumericSeriesFileNames    NameGeneratorType;

  NameGeneratorType::Pointer nameGenerator = NameGeneratorType::New();

  nameGenerator->SetSeriesFormat( "Irene2800%02d.png" );

  nameGenerator->SetStartIndex( first );
  nameGenerator->SetEndIndex( last );
  nameGenerator->SetIncrementIndex( 1 );

  reader->SetImageIO( itk::PNGImageIO::New() );
  reader->SetFileNames( nameGenerator->GetFileNames()  );

  writer->SetFileName( outputFilename );
  writer->SetInput( reader->GetOutput() );
  try 
    { 
    writer->UpdateLargestPossibleRegion(); 
	writer->Update();
    } 
  catch( itk::ExceptionObject & err ) 
    { 
    std::cerr << "ExceptionObject caught !" << std::endl; 
    std::cerr << err << std::endl; 
    return EXIT_FAILURE;
    } 
  return EXIT_SUCCESS;
}


The images are the slices of the heart which I converted from DICOM to png
and did some image processing operations - improving resolution, resizing.
Is the problem related to the images I'm using?

Thanks.

Regards,
Gupt




Luis Ibanez wrote:
> 
> Hi Gupt,
> 
> We are talking about two different problems here.
> 
> In your previous email, we dealt with a Reading problem
> that happens when a reader is reused for loading images
> of different sizes.
> 
> That seems to have been fixed with the use of method
> 
>            reader->UpdateLargestPossibleRegion().
> 
> ...
> 
> Now, we seem to be dealing with a problem in the output
> of your program.
> 
> Please tell us what happens in the middle (between the
> reader and the writer).
> 
> Are you simply reading a series of 2D images, and then
> writing them out right away  ?
> 
> 
> If your program is a single file (source code), and if it is not
> too long (less than 30Kb), it will be very helpful if you can
> post your source code to the mailing list.
> 
> 
>     Thanks
> 
> 
>           Luis
> 
> 
> ------------------------------
> On Tue, Dec 8, 2009 at 4:17 PM, Gupt <adityargupta at gmail.com> wrote:
>>
>> Hello Luis,
>>
>> Using UpdateLargestPossibleRegion() didn't give me the error for one set
>> of
>> slices but the mhd (raw and hdr) file created had errors. When I try to
>> open
>> the volume using MRIcro, I get the error -
>>
>> Unknown image format, and file size smaller than described in 'Header
>> Information' panel.
>>
>> I also tried using ITK SNAP but am unable to open the file.
>>
>> When I re-run the program for a different set of slices, I get the error
>> described in my last post - "Largest possible region  does not fully
>> contain
>> requested paste IO regionPaste IO region:..."
>>
>> Thank you for your help.
>>
>> Regards,
>> Gupt
>>
>> Luis Ibanez wrote:
>>>
>>> Hi Gupt,
>>>
>>> This error is usually produced when you attempt to "reuse" a
>>> reader to load two images of different size, one after another.
>>>
>>> For example:
>>>
>>>     reader->SetFileName("myImage1.mhd");
>>>     reader->Update();
>>>
>>>     reader->SetFileName("myImage2.mhd");
>>>     reader->Update();
>>>
>>>
>>> The simple solution is to call "UpdateLargestPossibleRegion()"
>>> instead of calling the typical "Update()" method.
>>>
>>> So your code your look more like:
>>>
>>>
>>>     reader->SetFileName("myImage1.mhd");
>>>     reader->UpdateLargestPossibleRegion();
>>>
>>>     reader->SetFileName("myImage2.mhd");
>>>     reader->UpdateLargestPossibleRegion();
>>>
>>>
>>> Please let us know if that helps,
>>>
>>>
>>>      Thanks
>>>
>>>
>>>           Luis
>>>
>>>
>>> --------------------------------------------------------------------------------------------------------
>>> On Mon, Dec 7, 2009 at 5:11 PM, Gupt <adityargupta at gmail.com> wrote:
>>>>
>>>> Hello,
>>>>
>>>> I'm working with ImageSeriesReadWrite.cxx example from ITK user guide.
>>>> I'm
>>>> trying to build the 3d volume from a set of 2d mri images -
>>>> file280054.jpg
>>>> to file280062.jpg. But I'm receiving the following error:
>>>>
>>>> ExceptionObject Caught!
>>>>
>>>> itk:ExceptionObject <0134F560>
>>>> itk::Location: "void __thiscall itk::ImageFileWriter<class
>>>> itk::Image<unsigned
>>>> char,3> >::Write(void)"
>>>> File: c:\itk\insight_toolkit\code\io\itkImageFileWriter.txx
>>>> Line: 271
>>>> Description: itk::ERROR: ImageFileWriter(01934508): Largest possible
>>>> region
>>>> does not fully contain requested paste IO regionPaste IO region:
>>>> ImageIORegion (0134F998)
>>>>  Dimension: 3
>>>>  Index: 0 0 0
>>>>  Size: 0 0 0
>>>> Largest possible region: ImageRegion (0134FA4C)
>>>>  Dimension: 3
>>>>  Index: [0, 0, 0]
>>>>  Size: [0, 0, 0]
>>>>
>>>> Thanks for your help.
>>>>
>>>> Gupt
>>>>
>>>>
>>>>
>>>>
>>>> Luis Ibanez wrote:
>>>>>
>>>>> Hi Gupt,
>>>>>
>>>>> We no longer make any difference between a sequence of 2D slices
>>>>> and a 3D volume... unless.... they are not aligned, or... the spacing
>>>>> in
>>>>> the inter-slice direction is more than 5 times the intra-slice
>>>>> spacing.
>>>>>
>>>>>
>>>>> If you have segmentations for all the 2D slices, you can simply load
>>>>> them
>>>>> all into a single 3D image using an ImageSeriesReader, and then you
>>>>> can process it as a 3D volume.  More specifically, you can proceed to
>>>>> compute its volume by using the LabelStatisticsImageFilter.
>>>>>
>>>>>
>>>>>      Regards,
>>>>>
>>>>>
>>>>>            Luis
>>>>>
>>>>>
>>>>> --------------------------------
>>>>> On Mon, Dec 7, 2009 at 12:10 PM, Aditya Gupta <adityargupta at gmail.com>
>>>>> wrote:
>>>>>> Hello Luis,
>>>>>>
>>>>>> Thanks for the reply. In continuation to my previous question... So
>>>>>> using
>>>>>> the stack of 2d MRI slices, I've a certain segmentation on each of
>>>>>> the
>>>>>> slices and using the segmented output I've built a surface model and
>>>>>> now
>>>>>> I've incorporated the intensities of the slices in the surface model.
>>>>>> Now,
>>>>>> I'm interested to find the volume of the segmented region. So, using
>>>>>> the
>>>>>> segmented outputs from the various slices, I want to reconstruct a
>>>>>> volume,
>>>>>> compute and finally visualize the volume. Can you give me a start on
>>>>>> how
>>>>>> I
>>>>>> can proceed? Is it possible to build a 3d volume (not surface model)
>>>>>> from
>>>>>> a
>>>>>> stack of 2d slices (only one axial view not 3 views)? Are there any
>>>>>> standard
>>>>>> algorithms being used for construction of 3d volumes from 2d slices?
>>>>>>
>>>>>> Appreciate your help in this matter.
>>>>>>
>>>>>> Regards,
>>>>>> Gupt
>>>>>>
>>>>>> On Wed, Dec 2, 2009 at 7:07 PM, Luis Ibanez <luis.ibanez at kitware.com>
>>>>>> wrote:
>>>>>>>
>>>>>>> Hi  Gupt,
>>>>>>>
>>>>>>>
>>>>>>> Yes, just do the following:
>>>>>>>
>>>>>>>
>>>>>>> A) Load the 2D slices into a single 3D image using the
>>>>>>>     itk::ImageSeriesReader,
>>>>>>>
>>>>>>>
>>>>>>> B) Connect the image an ImageInterpolator
>>>>>>>     The typical choice is the itkLinearImageInterpolateFunction
>>>>>>> class,
>>>>>>>     (but you can also use NearestNeighbors, BSpline and
>>>>>>>      WindowedSinc, it is a trade-off between computation time and
>>>>>>>      interpolation precision)
>>>>>>>
>>>>>>>
>>>>>>> C) Take all the points from your surface model and for every
>>>>>>>     point call the method:
>>>>>>>
>>>>>>>       PixelType  pixelValue =    Interpolator->Evaluate( point )
>>>>>>>
>>>>>>>    and then assign that pixel value to the corresponding point
>>>>>>>    in the surface model.
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>  Please let us know if you run into any problem.
>>>>>>>
>>>>>>>
>>>>>>>       Thanks
>>>>>>>
>>>>>>>
>>>>>>>          Luis
>>>>>>>
>>>>>>>
>>>>>>> ------------------------------------------------------------------
>>>>>>> On Wed, Dec 2, 2009 at 2:35 PM, Gupt <adityargupta at gmail.com> wrote:
>>>>>>> >
>>>>>>> > I've a stack of 2d cardiac mri images in single view. I've written
>>>>>>> the
>>>>>>> > code
>>>>>>> > to do a surface reconstruction of the left ventricle wall of the
>>>>>>> heart
>>>>>>> > (looks like a hollow cylinder). Is there a method/ function to
>>>>>>> > incorporate
>>>>>>> > the intensity information (in the 2d slices) in to the model, like
>>>>>>> some
>>>>>>> > kind
>>>>>>> > of interpolation to obtain intensity between the slices? Thanks
>>>>>>> for
>>>>>>> the
>>>>>>> > help.
>>>>>>> > --
>>>>>>> > View this message in context:
>>>>>>> >
>>>>>>> http://old.nabble.com/Interpolation-Volume-tp26614974p26614974.html
>>>>>>> > Sent from the ITK - Users mailing list archive at Nabble.com.
>>>>>>> >
>>>>>>> > _____________________________________
>>>>>>> > 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
>>>>>>> >
>>>>>>
>>>>>>
>>>>>>
>>>>>> --
>>>>>> Regards,
>>>>>> Aditya Gupta, Ph.D.
>>>>>> Post Doc Researcher
>>>>>> UCF Computer Vision Lab
>>>>>> Orlando, FL
>>>>>> O: (407) 882 0130
>>>>>> M: (407) 451 7735
>>>>>>
>>>>> _____________________________________
>>>>> 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
>>>>>
>>>>>
>>>>
>>>> --
>>>> View this message in context:
>>>> http://old.nabble.com/Interpolation-Volume-tp26614974p26685129.html
>>>> Sent from the ITK - Users mailing list archive at Nabble.com.
>>>>
>>>> _____________________________________
>>>> 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
>>>>
>>> _____________________________________
>>> 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
>>>
>>>
>>
>> --
>> View this message in context:
>> http://old.nabble.com/Interpolation-Volume-tp26614974p26700914.html
>> Sent from the ITK - Users mailing list archive at Nabble.com.
>>
>> _____________________________________
>> 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
>>
> _____________________________________
> 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
> 
> 

-- 
View this message in context: http://old.nabble.com/Interpolation-Volume-tp26614974p26712924.html
Sent from the ITK - Users mailing list archive at Nabble.com.



More information about the Insight-users mailing list