[Insight-users] Changing InputPixelType in an easy way?

Iván Macía imacia at vicomtech.es
Thu May 24 09:46:07 EDT 2007


Hi Frederic,

 

For storing the images you can create a container of pointers to any of the
base classes, for example itk::ImageBase but you still need to know which
image types you intend to use. You can do something like

 

typedef itk::Image<unsigned char,2>  UCharImageType;

typedef itk::Image<short,2>               ShortImageType;

 

typedef itk::ImageBase<2>                ImageBaseType;

typedef std::vector<ImageBaseType::Pointer>  ImageContainerType;

 

ImageContainerType imageContainer;

 

ShortImageType::Pointer  shortImage = ShortImageType::New();




do something with the image




 

// Store the image in the container

imageContainer.push_back( shortImage.GetPointer() );

 

UCharImageType::Pointer  ucharImage = UCharImageType::New();




do something with the image




 

// Store the image in the container

imageContainer.push_back( ucharImage.GetPointer() );

 

The problem here is how to down-cast the image to the specific type when
retrieving it from the container. One way is to use dynamic_cast or typeid
to check among the types of itk::Image that you might expect. For example :

 

UCharImageType::Pointer ucharImage = dynamic_cast< UCharImageType*>(
imageContainer[0].GetPointer() );

 

if( ucharImage.IsNotNull() )

{

   // do something with the ucharImage

}

 

Of course there are more complicated and clean approaches.

 

Hope that helps

 

Ivan

 

   _____  

De: Frédéric Stevens [mailto:frederic.stevens at gmail.com] 
Enviado el: jueves, 24 de mayo de 2007 15:07
Para: Iván Macía
Asunto: Re: [Insight-users] Changing InputPixelType in an easy way?

 

Hi Ivan,

Thank you for answering. I am actually storing image in containers
(importing an image from IDL and exporting it back with filters applied on
it). That is why I need to have different kind of pixel and I intented to
implement it such as we don't need to know what the original pixel type is. 

Regards,

Frédéric

On 5/24/07, Iván Macía <HYPERLINK
"mailto:imacia at vicomtech.es"imacia at vicomtech.es> wrote:

Hi Frederic,

 

You cannot do what you intend. This is a C++ issue. With typedef you are
defining new types which are valid only in the space between the braces and
those types no longer exist (go out of scope) after them. So when you reach
the point where you define the image types, InputPixelType and
OutputPixelType don't exist because they cannot be seen.

 

The class itk::Image is not intended for changing the pixel type
dinamically. If you need to use several pixel types then you need to use
several image types and you need to know them and define them beforehand,
that is at compile time. For example :

 

typedef itk::Image<unsigned char,2>   UCharImageType;

typedef itk::Image<short,2>                ShortImageType;

 

and then use each image type where necessary. 

 

The only way of managing itk images independently of the pixel type is using
polymorphism by recurring to pointers to itk::ImageBase which is depends
only on the image dimension. But this is only practical if you need to do
something like storing images in containers. 

 

Best regards

 

Ivan

 

   _____  

De: insight-users-bounces+imacia=HYPERLINK "mailto:vicomtech.es at itk.org"
\nvicomtech.es at itk.org [mailto:HYPERLINK
"mailto:insight-users-bounces+imacia=vicomtech.es at itk.org"
\ninsight-users-bounces+imacia=vicomtech.es at itk.org] En nombre de Frédéric
Stevens
Enviado el: jueves, 24 de mayo de 2007 14:27
Para: HYPERLINK "mailto:Insight-users at itk.org" \nInsight-users at itk.org
Asunto: [Insight-users] Changing InputPixelType in an easy way?

 

Hi,

I was wondering if you could change the InputPixelType easily ? 
I have tried something like :

     int test = 1;    // just to be sure it enters the first if for
InputPixeltype to be defined
     if( test == 1)
    {
        typedef  unsigned char InputPixelType; 
        typedef  unsigned char OutputPixelType; 
    }
    else
    {
        typedef  short InputPixelType; 
        typedef  short OutputPixelType; 
    }
 
typedef itk::Image< InputPixelType,  2 >   InputImageType;
typedef itk::Image< OutputPixelType, 2>   OutputImageType;

But It doesn't work: gives that error " Error    4    error C2065:
'InputPixelType' : undeclared identifier
e:\tmp\Imageimport\binarytest.cxx    62    " 
If i put directly one type it works, but if i put an "if", even though I am
sure in goes in, the InputPixelType isn't known. Could you explain me why it
doesn't recognize it ?

Thank you in advance, 
Regards,

Frédéric





No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.467 / Virus Database: 269.7.7/816 - Release Date: 23/05/2007
15:59

 

No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.5.467 / Virus Database: 269.7.7/816 - Release Date: 23/05/2007
15:59

 

No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.467 / Virus Database: 269.7.7/816 - Release Date: 23/05/2007
15:59


No virus found in this outgoing message.
Checked by AVG Free Edition. 
Version: 7.5.467 / Virus Database: 269.7.7/816 - Release Date: 23/05/2007
15:59
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://public.kitware.com/pipermail/insight-users/attachments/20070524/e6a5970e/attachment-0001.htm


More information about the Insight-users mailing list