[Insight-users] setorigin and setspacing for itkimage problem

Luis Ibanez luis.ibanez@kitware.com
Thu, 19 Dec 2002 13:50:38 -0500


Hi Lydia,

Your code compiles and runs ok for me.

There may be something else producing the
error condition that you reported.

--

Some comments about your code:

1) When you create an image by hand you want to
    setup three regions:

    - LargestPossibleRegion
    - RequestedRegion
    - BufferedRegion.

    In your code, the Buffered region is missing.

    For convinience, you can use the SetRegions( region )
    method that will set the three regions using the
    "region" specified.

2) Please don't invoke "Update()" in an image.
    This method is intended to be used only by
    the pipeline mechanism.

3) Is there a particular reason why you want to
    set the pixel container ?
    This is only intended to facilitate connecting
    ITK with other systems. specifically if you
    want to share the image buffer.

4) If you really need the pixel container, please
    make sure that it allocates the necessary amount
    of  memory for the image.


In any case, something else is producing the
exception in your code.

Could you tell us more about your platform and
the code that can be around of what you posted ?

You may want to make the tour of the examples
in:

   Insight/Examples/DataRepresentation/Image

Please find below the image.cxx programm I tried
using your code.


Regards,

    Luis

-------------------------------------
#include <itkImage.h>

int main()
{

    int size[2];
    size[0] = 0;
    size[1] = 0;

    typedef unsigned char PixelType;
    typedef itk::ImportImageContainer<unsigned long,PixelType> 
ContainerType;
    typedef itk::Image<PixelType, 2> ImageType;

    ContainerType::Pointer import = ContainerType::New();

    import->Reserve( size[0] * size[1] );

    ImageType:: Pointer img = ImageType::New();
    float values[2]={0.76,0.76};// values[0]=0.76; values[1]=0.76;
    float origin_x= ((size[0]/2)*0.76*(-1));
    float origin_y=((size[1]/2)*0.76*(-1));
    float origin[2] = {origin_x, origin_y};
    ImageType::SizeType         imagesize;
    imagesize[0] = 256;
    imagesize[1] = 256;
    ImageType::RegionType region;
    region.SetSize( imagesize );
    img->SetLargestPossibleRegion( region );
    img->SetBufferedRegion( region );
    img->Allocate();
    img->SetOrigin(origin);
    img->SetSpacing(values);
    img->SetPixelContainer(import);

return 0;
}


-------------------------------------

lydia coin wrote:
> Hi everyone
> 
> Thanks Luis for your help of yesterday about smartPointers
> 
> Now I have another problem that maybe many of you know its solution.
> 
> by using this code, I get an execption at SetOrigin method. The 
> execption is in the file itkimgae.txx, SetOrigin method, 
> this->RebuildTransform() function.
> 
> Does someone know how to solve it?
> 
>  typedef itk::Image<unsigned char, 2> ImageType;
>    ImageType:: Pointer img = ImageType::New();
>    float values[2]={0.76,0.76};// values[0]=0.76; values[1]=0.76;
>    float origin_x= ((size[0]/2)*0.76*(-1));
>    float origin_y=((size[1]/2)*0.76*(-1));
>    float origin[2] = {origin_x, origin_y};
>    ImageType::SizeType         imagesize;
>    imagesize[0] = 256;
>    imagesize[1] = 256;
>    ImageType::RegionType region;
>    region.SetSize( imagesize );
>    img->SetLargestPossibleRegion( region );
>    img->SetBufferedRegion( region );
>    img->Allocate();
>    img->SetOrigin(origin);
>    img->SetSpacing(values);
>    img->SetPixelContaine r(import);
>    img->Update();
> 
> 
> ------------------------------------------------------------------------
> Do You Yahoo!? -- Une adresse @yahoo.fr gratuite et en français !
> Testez le nouveau Yahoo! Mail <http://fr.mail.yahoo.com>