[Insight-users] problem with defining public Filter objects

Luis Ibanez luis.ibanez at kitware.com
Wed Aug 31 11:14:17 EDT 2005



Hi Seniha,

It seems that you are misusing the SetSize() method
of the ImageRegion class.

The argument for this method are not Width,Height
as you are providing in your code.
Instead, they are:

        SetSize( dimension, size );


This is because ITK supports N-Dimensional images,
not just 2D images.


Your code should be:

   regionGL.SetSize(0,Width );  // dimension 0 is X
   regionGL.SetSize(1,Height);  // dimension 1 is Y

and

   regionGL.SetIndex(0,0);  // index in X
   regionGL.SetIndex(1,0);  // index in Y


You can also follow the example illustrated in the
ITK Software Guide

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

where objects for Index and Size are explicitly created,
and initialized, like

    RegionType::IndexType start;
    start[0] = 0;  // dimension X
    start[1] = 0;  // dimension Y

    RegionType::SizeType size;
    size[0] = Width; // dimension X
    size[1] = Width; // dimension Y

    regionGl.SetSize( size );
    regionGl.SetIndex( start );


This is a bit verbose, but it is much clearer.


   Regards,


      Luis



-------------------------
Seniha Esen Yuksel wrote:
> Hi all,
> I want to define a public filter in my function which I will use as 
> a buffer to hold my images, but I am getting an exception error. 
> Actually even before the exception error, I can see that the  output of 
> the filter is empty, which makes me think that I am defining the 
> RegionType in a wrong way -- could you please particularly look at that 
> and tell me if it is correct?   I am copying parts of the code below 
> from the header file and the c++ file.
>  
> //------------------------------------------------------------------------------
> //part of the code from my .h file:
> //------------------------------------------------------------------------------
>  
> public:
>  
> // ........
>  
> //===================
> //My ITK Object Pointers
> //===================
>    
>   typedef int integer;
>   typedef unsigned short      PixelType;
>   typedef  unsigned char  InputPixelType;
>   typedef  unsigned char  OutputPixelType;
>   typedef itk::Image< InputPixelType,  2 >   InputImageType;
>   typedef itk::Image< OutputPixelType, 2 >   OutputImageType;
>   typedef itk::RegionOfInterestImageFilter<InputImageType, 
> OutputImageType >  FilterType;
>   typedef itk::ImageFileWriter< OutputImageType> WriterTypeGL;
> 
>   FilterType::Pointer filter;
>   WriterTypeGL::Pointer writergl;
>  
>  InputImageType::RegionType regionGL;
> // ........
>  
>  
> //------------------------------------------------------------------------------
> //-------------------- part of my c++ code --------------------------
>  
> int FrontDialog::CropImage(){
>  
> //...........................
>  
>  writerMoving->SetFileName( output.c_str() );
>  writerMoving->SetInput( cropMoving->GetOutput() );
>  try {
>          writerMoving->Update();
>          }     catch (itk::ExceptionObject &err)         {
>          std::cout<< "Exception caught:" << std::endl;
>          std::cout<< err <<std::endl;
>        
>          return -1;
>          }
>  
> //here I definitely know that cropMoving->GetOutput()  gives correct results
> //because I am able to save it as an image. However, I also want to save 
> it in a
> //public variable to use over and over.
>  
> //here comes the part which fails:
>  
>  regionGL.SetSize(Width, Height);
>  regionGL.SetIndex(0,0);
> 
>  filter = FilterType::New();
>  filter->SetRegionOfInterest(regionGL);
>  filter->SetInput( crop->GetOutput());
>  try {
>           filter->Update();
>          }     catch (itk::ExceptionObject &err)         {
>          std::cout<< "Exception caught:" << std::endl;
>          std::cout<< err <<std::endl;
>        
>          return -1;
>          }
> 
>  filter->GetOutput()->Print( std::cout );
>  
> //.............
> return 0;
> }
>  
>  
> //-------------------------------------------------------------------
>  
>  
> I spent too much time to figure out this problem but I am now clueless 
> on what to do. The output of the exe file is as below.  I will really 
> appreciate it a lot if anyone could help me...
> Thanks a lot in advance,
> Seniha
>  
>  
> This program resizes the input file with the following parameters
> x starting value: 300
> y starting value: 300
> x extension     : 200
> y extension     : 200
> ===========================
> images are cropped
> Image (02695AA0)
>   RTTI typeinfo:   class itk::Image<unsigned char,2>
>   Reference Count: 1
>   Modified Time: 236
>   Debug: Off
>   Observers:
>     none
>   Source: (02695B90)
>   Source output index: 0
>   Release Data: Off
>   Data Released: False
>   Global Release Data: Off
>   PipelineMTime: 222
>   UpdateMTime: 237
>   LargestPossibleRegion:
>     Dimension: 2
>     Index: [0, 0]
>     Size: [0, 0]
>   BufferedRegion:
>     Dimension: 2
>     Index: [0, 0]
>     Size: [0, 0]
>   RequestedRegion:
>     Dimension: 2
>     Index: [0, 0]
>     Size: [0, 0]
>   Spacing: [1, 1]
>   Origin: [300, 300]
>   PixelContainer:
>     ImportImageContainer (02694BE0)
>       RTTI typeinfo:   class itk::ImportImageContainer<unsigned 
> long,unsigned ch
> ar>
>       Reference Count: 1
>       Modified Time: 235
>       Debug: Off
>       Observers:
>         none
>       Pointer: 02694C10
>       Container manages memory: true
>       Size: 0
>       Capacity: 0
> Exception caught:
> itk::ExceptionObject (0109E4C0)
> Location: "Unknown"
> File: 
> C:\ITK\InsightToolkit-2.0.0\InsightToolkit-2.0.0\Code\IO\itkPNGImageIO.cxx
> Line: 395
> Description: itk::ERROR: PNGImageIO(026955F0): PNG Writer can only write 
> 2-dimen
> sional images
> 
>  
> 
> 
> Seniha Esen Yuksel
> Research Assistant
> Computer Vision and Image Processing Lab,
> Lutz Hall Rm 414,
> University of Louisville,
> Louisville, KY
> work ph: 502- 8521528
> home ph: 502- 8549856
> email: esen at cvip.uofl.edu // esenyuksel at ieee.org
> web: http://www.cvip.louisville.edu/~esen/
> 
> __________________________________________________
> Do You Yahoo!?
> Tired of spam? Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users



More information about the Insight-users mailing list