Hi Iv<span class="gmail_quote"><span class="gmail_sendername">án,<br><br>Thank you to keep helping me. Please let me know if I understood correctly :<br>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&#39;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].
<br>I think that this method must work but the problem is the time eaten by applying 2 times a filter ?<br>Well, maybe I misunderstood the way you suggested me to do. <br>Otherwise I can still try to use the polymorphism as you told me before but it&#39;s kind of complicated since I am using ITK as a DLL in my program that is intended to be run on IDL.
<br><br>Thank you again for spending your time on this problem,<br><br>Frédéric <br><br><br><br><br><br></span></span><br><div><span class="gmail_quote">On 5/24/07, <b class="gmail_sendername">Iván Macía</b> &lt;<a href="mailto:imacia@vicomtech.es">
imacia@vicomtech.es</a>&gt; wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">












<div link="blue" vlink="blue" lang="ES">

<div>

<p><font color="navy" face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial; color: navy;">Hi Frederic,</span></font></p>

<p><font color="navy" face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial; color: navy;">&nbsp;</span></font></p>

<p><font color="navy" face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial; color: navy;" lang="EN-GB">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</span></font></p><span class="q">

<p><font color="navy" face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial; color: navy;" lang="EN-GB">&nbsp;</span></font></p>

<p><font color="navy" face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial; color: navy;" lang="EN-GB">typedef
itk::Image&lt;unsigned char,2&gt;&nbsp; UCharImageType;</span></font></p>

<p><font color="navy" face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial; color: navy;" lang="EN-GB">typedef itk::Image&lt;short,2&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
ShortImageType;</span></font></p>

<p><font color="navy" face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial; color: navy;" lang="EN-GB">&nbsp;</span></font></p></span>

<p><font color="navy" face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial; color: navy;" lang="EN-GB">typedef
itk::ImageBase&lt;2&gt;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ImageBaseType;</span></font></p>

<p><font color="navy" face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial; color: navy;" lang="EN-GB">typedef
std::vector&lt;ImageBaseType::Pointer&gt;&nbsp; ImageContainerType;</span></font></p>

<p><font color="navy" face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial; color: navy;" lang="EN-GB">&nbsp;</span></font></p>

<p><font color="navy" face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial; color: navy;" lang="EN-GB">ImageContainerType
imageContainer;</span></font></p>

<p><font color="navy" face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial; color: navy;" lang="EN-GB">&nbsp;</span></font></p>

<p><font color="navy" face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial; color: navy;" lang="EN-GB">ShortImageType::Pointer&nbsp;
shortImage = ShortImageType::New();</span></font></p>

<p><font color="navy" face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial; color: navy;" lang="EN-GB">…</span></font></p>

<p><font color="navy" face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial; color: navy;" lang="EN-GB">do something with the
image</span></font></p>

<p><font color="navy" face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial; color: navy;" lang="EN-GB">…</span></font></p>

<p><font color="navy" face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial; color: navy;" lang="EN-GB">&nbsp;</span></font></p>

<p><font color="navy" face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial; color: navy;" lang="EN-GB">// Store the image in the
container</span></font></p>

<p><font color="navy" face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial; color: navy;" lang="EN-GB">imageContainer.push_back(
shortImage.GetPointer() );</span></font></p>

<p><font color="navy" face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial; color: navy;" lang="EN-GB">&nbsp;</span></font></p>

<p><font color="navy" face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial; color: navy;" lang="EN-GB">UCharImageType::Pointer&nbsp; ucharImage
= UCharImageType::New();</span></font></p>

<p><font color="navy" face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial; color: navy;" lang="EN-GB">…</span></font></p>

<p><font color="navy" face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial; color: navy;" lang="EN-GB">do something with the
image</span></font></p>

<p><font color="navy" face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial; color: navy;" lang="EN-GB">…</span></font></p>

<p><font color="navy" face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial; color: navy;" lang="EN-GB">&nbsp;</span></font></p>

<p><font color="navy" face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial; color: navy;" lang="EN-GB">// Store the image in the
container</span></font></p>

<p><font color="navy" face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial; color: navy;" lang="EN-GB">imageContainer.push_back(
ucharImage.GetPointer() );</span></font></p>

<p><font color="navy" face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial; color: navy;" lang="EN-GB">&nbsp;</span></font></p>

<p><font color="navy" face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial; color: navy;" lang="EN-GB">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 :</span></font></p>

<p><font color="navy" face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial; color: navy;" lang="EN-GB">&nbsp;</span></font></p>

<p><font color="navy" face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial; color: navy;" lang="EN-GB">UCharImageType::Pointer
ucharImage = dynamic_cast&lt; UCharImageType*&gt;( imageContainer[0].GetPointer()
);</span></font></p>

<p><font color="navy" face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial; color: navy;" lang="EN-GB">&nbsp;</span></font></p>

<p><font color="navy" face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial; color: navy;" lang="EN-GB">if(
ucharImage.IsNotNull() )</span></font></p>

<p><font color="navy" face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial; color: navy;" lang="EN-GB">{</span></font></p>

<p><font color="navy" face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial; color: navy;" lang="EN-GB">&nbsp;&nbsp; // do something with
the ucharImage</span></font></p>

<p><font color="navy" face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial; color: navy;" lang="EN-GB">}</span></font></p>

<p><font color="navy" face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial; color: navy;" lang="EN-GB">&nbsp;</span></font></p>

<p><font color="navy" face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial; color: navy;" lang="EN-GB">Of course there are more
complicated and clean approaches.</span></font></p>

<p><font color="navy" face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial; color: navy;" lang="EN-GB">&nbsp;</span></font></p>

<p><font color="navy" face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial; color: navy;" lang="EN-GB">Hope that helps</span></font></p>

<p><font color="navy" face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial; color: navy;" lang="EN-GB">&nbsp;</span></font></p>

<p><font color="navy" face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial; color: navy;" lang="EN-GB">Ivan</span></font></p>

<p><font color="navy" face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial; color: navy;" lang="EN-GB">&nbsp;</span></font></p>

<div>

<div style="text-align: center;" align="center"><font face="Times New Roman" size="3"><span style="font-size: 12pt;">

<hr align="center" size="2" width="100%">

</span></font></div>

<p><b><font face="Tahoma" size="2"><span style="font-size: 10pt; font-family: Tahoma; font-weight: bold;" lang="EN-GB">De:</span></font></b><font face="Tahoma" size="2"><span style="font-size: 10pt; font-family: Tahoma;" lang="EN-GB">

Frédéric Stevens [mailto:<a href="mailto:frederic.stevens@gmail.com" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">frederic.stevens@gmail.com</a>] <br>
<b><span style="font-weight: bold;">Enviado el:</span></b> jueves, 24 </span></font><font face="Tahoma" size="2"><span style="font-size: 10pt; font-family: Tahoma;">de mayo de
2007 15:07<br>
<b><span style="font-weight: bold;">Para:</span></b> Iván Macía<br>
<b><span style="font-weight: bold;">Asunto:</span></b> Re: [Insight-users]
Changing InputPixelType in an easy way?</span></font></p>

</div><div><span class="e" id="q_112be546a4eb4a80_3">

<p><font face="Times New Roman" size="3"><span style="font-size: 12pt;">&nbsp;</span></font></p>

<p style="margin-bottom: 12pt;"><font face="Times New Roman" size="3"><span style="font-size: 12pt;">Hi Ivan,<br>
<br>
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&#39;t need to know what the original pixel type is. <br>
<br>
Regards,<br>
<br>
Frédéric</span></font></p>

<div>

<p><span><font face="Times New Roman" size="3"><span style="font-size: 12pt;">On 5/24/07, <b><span style="font-weight: bold;">Iván Macía</span></b>
&lt;<a href="mailto:imacia@vicomtech.es" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">imacia@vicomtech.es</a>&gt; wrote:</span></font></span></p>

<div link="blue" vlink="purple">

<div>

<p><font color="navy" face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial; color: navy;">Hi Frederic,</span></font></p>

<p><font color="navy" face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial; color: navy;">&nbsp;</span></font></p>

<p><font color="navy" face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial; color: navy;" lang="EN-GB">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&#39;t exist because they cannot be seen.</span></font></p>

<p><font color="navy" face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial; color: navy;" lang="EN-GB">&nbsp;</span></font></p>

<p><font color="navy" face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial; color: navy;" lang="EN-GB">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 :</span></font></p>

<p><font color="navy" face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial; color: navy;" lang="EN-GB">&nbsp;</span></font></p>

<p><font color="navy" face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial; color: navy;" lang="EN-GB">typedef itk::Image&lt;unsigned char,2&gt;
&nbsp;&nbsp;UCharImageType;</span></font></p>

<p><font color="navy" face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial; color: navy;" lang="EN-GB">typedef itk::Image&lt;short,2&gt;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ShortImageType;</span></font></p>

<p><font color="navy" face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial; color: navy;" lang="EN-GB">&nbsp;</span></font></p>

<p><font color="navy" face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial; color: navy;" lang="EN-GB">and then use each image type where necessary. </span></font></p>

<p><font color="navy" face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial; color: navy;" lang="EN-GB">&nbsp;</span></font></p>

<p><font color="navy" face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial; color: navy;" lang="EN-GB">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. </span></font></p>

<p><font color="navy" face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial; color: navy;" lang="EN-GB">&nbsp;</span></font></p>

<p><font color="navy" face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial; color: navy;" lang="EN-GB">Best regards</span></font></p>

<p><font color="navy" face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial; color: navy;" lang="EN-GB">&nbsp;</span></font></p>

<p><font color="navy" face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial; color: navy;" lang="EN-GB">Ivan</span></font></p>

<p><font color="navy" face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial; color: navy;" lang="EN-GB">&nbsp;</span></font></p>

<div>

<div style="text-align: center;" align="center"><font face="Times New Roman" size="3"><span style="font-size: 12pt;">

<hr align="center" size="2" width="100%">

</span></font></div>

<p><b><font face="Tahoma" size="2"><span style="font-size: 10pt; font-family: Tahoma; font-weight: bold;">De:</span></font></b><font face="Tahoma" size="2"><span style="font-size: 10pt; font-family: Tahoma;"> insight-users-bounces+imacia=
<a href="mailto:vicomtech.es@itk.org" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">vicomtech.es@itk.org</a>
[mailto:<a href="mailto:insight-users-bounces+imacia=vicomtech.es@itk.org" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">insight-users-bounces+imacia=vicomtech.es@itk.org</a>] <b><span style="font-weight: bold;">
En nombre de </span></b>Frédéric Stevens<br>
<b><span style="font-weight: bold;">Enviado el:</span></b> jueves, 24 de mayo de
2007 14:27<br>
<b><span style="font-weight: bold;">Para:</span></b> <a href="mailto:Insight-users@itk.org" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">Insight-users@itk.org</a><br>
<b><span style="font-weight: bold;">Asunto:</span></b> [Insight-users] Changing
InputPixelType in an easy way?</span></font></p>

</div>

<div><span>

<p><font face="Times New Roman" size="3"><span style="font-size: 12pt;">&nbsp;</span></font></p>

<p style="margin-bottom: 12pt;"><font face="Times New Roman" size="3"><span style="font-size: 12pt;">Hi,<br>
<br>
I was wondering if you could change the InputPixelType easily ? <br>
I have tried something like :<br>
<br>
&nbsp; &nbsp;&nbsp; int test = 1;&nbsp;&nbsp;&nbsp; // just to be sure it
enters the first if for InputPixeltype to be defined<br>
&nbsp;&nbsp;&nbsp;&nbsp; if( test == 1)<br>
&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; typedef&nbsp; unsigned char
InputPixelType; <br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; typedef&nbsp; unsigned char
OutputPixelType; <br>
&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp; else<br>
&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; typedef&nbsp; short InputPixelType; <br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; typedef&nbsp; short OutputPixelType; <br>
&nbsp;&nbsp;&nbsp; }<br>
&nbsp;<br>
typedef itk::Image&lt; InputPixelType,&nbsp; 2 &gt;&nbsp;&nbsp; InputImageType;<br>
typedef itk::Image&lt; OutputPixelType, 2&gt;&nbsp;&nbsp; OutputImageType;<br>
<br>
But It doesn&#39;t work: gives that error &quot; Error&nbsp;&nbsp;&nbsp;
4&nbsp;&nbsp;&nbsp; error C2065: &#39;InputPixelType&#39; : undeclared
identifier&nbsp;&nbsp;&nbsp;
e:\tmp\Imageimport\binarytest.cxx&nbsp;&nbsp;&nbsp; 62&nbsp;&nbsp;&nbsp; &quot;
<br>
If i put directly one type it works, but if i put an &quot;if&quot;, even
though I am sure in goes in, the InputPixelType isn&#39;t known. Could you explain
me why it doesn&#39;t recognize it ?<br>
<br>
Thank you in advance, <br>
Regards,<br>
<br>
Frédéric<br>
<br>
<br>
<br>
</span></font></p>

</span></div>

<p><font face="Times New Roman" size="2"><span style="font-size: 10pt;"></span>No
virus found in this incoming message.<br>
Checked by AVG Free Edition.<br>
Version: 7.5.467 / Virus Database: 269.7.7/816 - Release Date: 23/05/2007 15:59</font></p>

</div>

</div>

<p><font face="Times New Roman" size="3"><span style="font-size: 12pt;">&nbsp;</span></font></p>

<p><font face="Times New Roman" size="2"><span style="font-size: 10pt;">No virus
found in this outgoing message.<br>
Checked by AVG Free Edition.<br>
Version: 7.5.467 / Virus Database: 269.7.7/816 - Release Date: 23/05/2007 15:59</span></font></p>

</div>

<p style="margin-bottom: 12pt;"><font face="Times New Roman" size="3"><span style="font-size: 12pt;">&nbsp;</span></font></p>

<p><font face="Times New Roman" size="2"><span style="font-size: 10pt;">No virus
found in this incoming message.<br>
Checked by AVG Free Edition.<br>
Version: 7.5.467 / Virus Database: 269.7.7/816 - Release Date: 23/05/2007 15:59</span></font></p>

</span></div></div>

</div><div><span class="e" id="q_112be546a4eb4a80_5">


<br>

<p><font size="2">No virus found in this outgoing message.<br>
Checked by AVG Free Edition.<br>
Version: 7.5.467 / Virus Database: 269.7.7/816 - Release Date: 23/05/2007 15:59<br>
</font> </p>
</span></div></blockquote></div><br>