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

Frédéric Stevens frederic.stevens at gmail.com
Thu May 24 10:13:31 EDT 2007


Hi Iván,

Thank you to keep helping me. Please let me know if I understood correctly :
>From what you told me, for each picture I use as input, I will apply my
filter 2 times but using 2 different types for the image. And then you said
that there was a problem about downcasting. But since I only have 1 of those
pictures that will be useful, maybe the result downcasting isn't a problem ?
For instance, if my input picture a short type, I will only need the one in
the container[1] without caring about the result of the container[0]. On the
opposite, if it is a unsigned char, I will only need the one in the
container[0] instead of the container[1].
I think that this method must work but the problem is the time eaten by
applying 2 times a filter ?
Well, maybe I misunderstood the way you suggested me to do.
Otherwise I can still try to use the polymorphism as you told me before but
it's kind of complicated since I am using ITK as a DLL in my program that is
intended to be run on IDL.

Thank you again for spending your time on this problem,

Frédéric






On 5/24/07, Iván Macía <imacia at vicomtech.es> wrote:
>
>  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* <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=vicomtech.es at itk.org [mailto:
> insight-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:* Insight-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/86835483/attachment.html


More information about the Insight-users mailing list