<div dir="ltr">Hi <span style="font-family:verdana,sans-serif">Dženan,</span><div><font face="verdana, sans-serif"><br></font><div><span style="font-family:verdana,sans-serif">Thank you, you have been very helpful. I opted for the 'bloated' version, and it works. It's just a pity that the caller of the conversion function needs to know what type of image is to be converted. In order to convert a 3D deformation vector field, the caller needs to say:</span></div><div><div style=""><font face="verdana, sans-serif"> rc = ItkToAvs<itk::Vector<float, 3>, 3>(ppAvsVectorField, pItkVectorField);</font></div><div style=""><font face="verdana, sans-serif">(The prototype of ItkToAvs is given in the first post of this thread)</font></div><div style="font-family:verdana,sans-serif">On other words, the caller needs to know that such an image is 3D and contains float triplet pixels. Is there a way that the compiler works this out?</div></div><div style="font-family:verdana,sans-serif"><br></div><div style="font-family:verdana,sans-serif">Greetings,</div><div style="font-family:verdana,sans-serif">Lambert</div><div style="font-family:verdana,sans-serif"><br></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Mar 15, 2016 at 8:49 PM, Dženan Zukić <span dir="ltr"><<a href="mailto:dzenanz@gmail.com" target="_blank">dzenanz@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small">Hi Lambert,</div><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small"><br></div><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small">a 'general' interface cannot be made. You are not the first to face this issue. One way is to do if/else for all the supported cases. Another way is to define some template function or helper class, and then let compiler take care of type matching. But indeed, the code is either bloated (version one) or somewhat exotic (version two).</div><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small"><br></div><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small">RGB image can be stored either way. You can have itk::Image<char,3> with 3 dimensions x,y,color (consecutive color planes) or itk::Image<itk::RGBPixel<char>, 2> (consecutive triplets). It depends on your treatment. I believe that consecutive triplets is more common.</div><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small"><br></div><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small">Regards,</div><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small">Dženan</div></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Mar 15, 2016 at 3:39 PM, Lambert Zijp <span dir="ltr"><<a href="mailto:ljzijp@gmail.com" target="_blank">ljzijp@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><span style="font-size:12.8px">Hi </span><span style="font-size:12.8px;font-family:verdana,sans-serif">Dženan,</span><br><div><span style="font-size:12.8px;font-family:verdana,sans-serif"><br></span></div><div><span style="font-size:12.8px;font-family:verdana,sans-serif">Haha, true enough, ItkToAvs would have to return an errorcode </span><span style="font-family:verdana,sans-serif;font-size:12.8px">'unsupported'</span><span style="font-family:verdana,sans-serif;font-size:12.8px">. Yes, pixelspacing and origin can be retrieved. Also the size of each dimension, though that took me a while: it was well hidden.</span></div><div><span style="font-size:12.8px;font-family:verdana,sans-serif">Still, it is very frustrating that it cannot be determined from itk::image whether it is an ordinary, commonly occurring image like an BGR ARGB or a 3-vector float image.</span></div><div><span style="font-size:12.8px;font-family:verdana,sans-serif">At least, that is what I gather from your answer: a 'general' interface to other image processing libraries cannot be made!</span></div><div><span style="font-size:12.8px;font-family:verdana,sans-serif"><br></span></div><div><span style="font-size:12.8px;font-family:verdana,sans-serif">Am I the first person having problems with this?</span></div><div><span style="font-size:12.8px;font-family:verdana,sans-serif">How is an RGB image stored in itk, as consecutive triplets or as consecutive color-planes.</span></div><div><span style="font-size:12.8px;font-family:verdana,sans-serif"><br></span></div><div><span style="font-size:12.8px;font-family:verdana,sans-serif">Greetings,</span></div><div><span style="font-size:12.8px;font-family:verdana,sans-serif">Lambert</span></div></div><div><div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Mar 15, 2016 at 7:57 PM, Dženan Zukić <span dir="ltr"><<a href="mailto:dzenanz@gmail.com" target="_blank">dzenanz@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small"><span><div class="gmail_default">Yes, it knows. Using something like this:</div><div class="gmail_default"><br></div><div class="gmail_default" style="font-family:arial,sans-serif"><font face="monospace, monospace">template <typename ImageType></font></div><div class="gmail_default" style="font-family:arial,sans-serif;font-size:16px"><font face="monospace, monospace">void ItkToAvs(AVSfield** ppAvs, typename ImageType::Pointer image)<br></font></div><div class="gmail_default" style="font-family:arial,sans-serif;font-size:16px"><font face="monospace, monospace">{</font></div><div class="gmail_default" style="font-family:arial,sans-serif;font-size:16px"><font face="monospace, monospace">typename ImageType::PixelType *pixelPointer=image->GetBufferPointer();</font></div><div class="gmail_default" style="font-family:arial,sans-serif;font-size:16px"><font face="monospace, monospace">unsigned int dimension=ImageType::ImageDimension;</font></div><div class="gmail_default" style="font-family:arial,sans-serif;font-size:16px"><font face="monospace, monospace">//the rest of conversion code</font></div><div class="gmail_default" style="font-family:arial,sans-serif;font-size:16px"><font face="monospace, monospace">}</font></div><div class="gmail_default" style="font-family:arial,sans-serif;font-size:16px"><font face="verdana, sans-serif"><br></font></div><div class="gmail_default" style="font-family:arial,sans-serif;font-size:16px"><font face="verdana, sans-serif">However, </font><font face="monospace, monospace">ImageType::PixelType</font><font face="verdana, sans-serif"> can be arbitrary type. Consider this:</font></div><div class="gmail_default" style="font-family:arial,sans-serif;font-size:16px"><font face="monospace, monospace">class myClass {int a; complex<double> c; string sRep;};</font></div><div class="gmail_default" style="font-family:arial,sans-serif;font-size:16px"><font face="monospace, monospace">typedef itk::Image<myClass, 2> ImageType;</font></div><div class="gmail_default" style="font-family:arial,sans-serif;font-size:16px"><font face="monospace, monospace">ItkToAvs(ppAvs, image);</font><span style="font-family:verdana,sans-serif"><br></span></div><div class="gmail_default" style="font-family:arial,sans-serif;font-size:16px"><span style="font-family:monospace,monospace"><br></span></div><div class="gmail_default" style="font-family:arial,sans-serif;font-size:16px"><span style="font-family:monospace,monospace">What do you expect </span><font face="monospace, monospace">ItkToAvs</font><span style="font-family:monospace,monospace"> to do?</span></div><div class="gmail_default" style="font-family:arial,sans-serif;font-size:16px"><span style="font-family:monospace,monospace"><br></span></div></span><div class="gmail_default" style="font-family:arial,sans-serif;font-size:16px"><span style="font-family:monospace,monospace">Regards,</span></div><div class="gmail_default" style="font-family:arial,sans-serif;font-size:16px"><span style="font-family:monospace,monospace">Dženan</span></div></div></div><div><div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Mar 15, 2016 at 2:53 PM, Lambert Zijp <span dir="ltr"><<a href="mailto:ljzijp@gmail.com" target="_blank">ljzijp@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span><div dir="ltr">This is all very confusing to me. In the FileWriter example, the caller <b>already knows</b> what the <a href="http://www.itk.org/Doxygen/html/classitk_1_1ImageIOBase.html#a8dc783055a0af6f0a5a26cb080feb178" style="color:rgb(70,101,162);font-weight:bold;font-family:'Lucida Grande',Verdana,Geneva,Arial,sans-serif;font-size:12px;line-height:22px" target="_blank">IOComponentType</a> and what the <a href="http://www.itk.org/Doxygen/html/classitk_1_1ImageIOBase.html#abd189f096c2a1b3ea559bc3e4849f658" style="color:rgb(70,101,162);font-weight:bold;font-family:'Lucida Grande',Verdana,Geneva,Arial,sans-serif;font-size:12px;line-height:22px" target="_blank">IOPixelType</a><span style="color:rgb(0,0,0);font-family:'Lucida Grande',Verdana,Geneva,Arial,sans-serif;font-size:12px;line-height:22px;background-color:rgb(249,250,252)"> of the itk::Image is (it is hard-coded; not retrieved from the itk::Image). The same holds for the reader: it gets that information from the file.</span><div><span style="color:rgb(0,0,0);font-family:'Lucida Grande',Verdana,Geneva,Arial,sans-serif;font-size:12px;line-height:22px;background-color:rgb(249,250,252)">I want to make a general function that takes <b>ANY</b> itk::Image as input, and converts it to an AVS datasructure (which supports all of them). So I need to get the information from itk::Image.</span></div><div><span style="color:rgb(0,0,0);font-family:'Lucida Grande',Verdana,Geneva,Arial,sans-serif;font-size:12px;line-height:22px;background-color:rgb(249,250,252)">Is there a way to get it from itk::Image? </span><span style="color:rgb(0,0,0);font-family:'Lucida Grande',Verdana,Geneva,Arial,sans-serif;font-size:12px;line-height:22px;background-color:rgb(249,250,252)">Or is it true that an itk::Image does not know what it actually is/represents?</span><div style="font-size:12.8px"></div></div></div></span><div><div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Mar 15, 2016 at 7:07 PM, Dženan Zukić <span dir="ltr"><<a href="mailto:dzenanz@gmail.com" target="_blank">dzenanz@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small">If I remember correctly, using <a href="http://www.vtk.org/Wiki/ITK/Examples/IO/ReadUnknownImageType" target="_blank">this</a> approach you can also get number of components with something like:</div><div class="gmail_default"><font face="monospace, monospace">imageIO->GetNumberOfComponents();</font><br></div><div class="gmail_default"><font face="verdana, sans-serif">You can take a look at class <a href="http://www.itk.org/Doxygen/html/classitk_1_1ImageIOBase.html" target="_blank">documentation</a> for more details.</font></div></div><div><div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Mar 15, 2016 at 1:09 PM, Lambert Zijp <span dir="ltr"><<a href="mailto:ljzijp@gmail.com" target="_blank">ljzijp@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><font face="verdana, sans-serif">I'm still not sure how to handle vector images. </font><span style="font-family:verdana,sans-serif">Dženan gave an example of an RGB image. That would be a 3-vector unsigned char pixeltype.</span><div><span style="font-family:verdana,sans-serif">Would I have to write out in those <i>'if </i></span><span style="font-family:verdana,sans-serif"><i>(</i></span><span style="font-family:verdana,sans-serif"><i>typeid(ValueType) == ???)'</i> statements all permutations of the number of vectors and the type? Or is there a way to separate the number of vectors and the pixeltype?</span></div><div><span style="font-family:verdana,sans-serif">How are vector images stored in memory in ITK. In an RGB image for example, are the pixels consecutive triplets, or is the image stored as three consecutive color planes?</span></div><div><span style="font-family:verdana,sans-serif">I'm particular interested in 3D displacement vector fields, that are the result of deformable registration.</span></div><div><span style="font-family:verdana,sans-serif"><br></span></div></div><div><div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Mar 15, 2016 at 5:22 PM, Bill Lorensen <span dir="ltr"><<a href="mailto:bill.lorensen@gmail.com" target="_blank">bill.lorensen@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><p dir="ltr">This example may help<br>
<a href="http://www.vtk.org/Wiki/ITK/Examples/IO/ReadUnknownImageType" target="_blank">http://www.vtk.org/Wiki/ITK/Examples/IO/ReadUnknownImageType</a><br>
</p><div><div>
<div class="gmail_quote">On Mar 15, 2016 8:44 AM, "Dženan Zukić" <<a href="mailto:dzenanz@gmail.com" target="_blank">dzenanz@gmail.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small">Of course it complained, switch statement is for integral types (if I remember correctly).</div><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small"><br></div><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small">Regards</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Mar 15, 2016 at 11:39 AM, Lambert Zijp <span dir="ltr"><<a href="mailto:ljzijp@gmail.com" target="_blank">ljzijp@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi <span style="font-family:verdana,sans-serif">Dženan,</span><div><span style="font-family:verdana,sans-serif"><br></span></div><div><span style="font-family:verdana,sans-serif">Thank you very much!</span></div><div><span style="font-family:verdana,sans-serif">Visual Studio 9 does not recognize </span><span style="font-size:12.8px">decltype(), but </span><span style="font-family:verdana,sans-serif">typeid() worked fine. At least, when you make separate if statements, like you did in your example. When tried to use it in a switch statement, the compiler complained.</span></div><div><span style="font-family:verdana,sans-serif"><br></span></div><div><span style="font-family:verdana,sans-serif">Greetings,</span></div><div><span style="font-family:verdana,sans-serif">Lambert</span></div><div><span style="font-family:verdana,sans-serif"><br></span></div></div><div><div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Mar 15, 2016 at 2:47 PM, Dženan Zukić <span dir="ltr"><<a href="mailto:dzenanz@gmail.com" target="_blank">dzenanz@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small">Hi Lambert,</div><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small"><br></div><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small">the classic way is using a bunch of if-else's.</div><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small"><br></div>if (decltype(ValueType)==decltype(int))<br>{<br>//int specific processing<br>}<br>else if (decltype(ValueType)==decltype(itk::RGB<char>))<br>{<br>//RGB<char> specific processing<br>}<div><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small">else if ...</div><div><br></div><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small">If you can't use C++11's decltype then use typeid from <typeinfo> header.</div><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small"><br></div><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small">Regards,</div><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small">Dženan</div></div></div><div class="gmail_extra"><br><div class="gmail_quote"><div><div>On Tue, Mar 15, 2016 at 5:48 AM, Lambert Zijp <span dir="ltr"><<a href="mailto:ljzijp@gmail.com" target="_blank">ljzijp@gmail.com</a>></span> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div><div dir="ltr">I want to write a function that converts an arbitrary ITK image to another format (AVS in my case).<div>It has been suggested that following functionprototype could de the job:</div><div><div>template<typename ValueType,unsigned int Dimension></div><div>int ItkToAvs(AVSfield** ppAvs, typename itk::Image<ValueType,Dimension>::Pointer pItkImage);</div></div><div><br></div><div>Now I want to know whether ValueType equals unsigned char or short or int etc. Also whether the pixels are single numbers or vectors. How does one do that?</div><div><br></div><div>Greetings,</div><div>Lambert</div><div><br></div><div><br></div></div>
<br></div></div>_____________________________________<br>
Powered by <a href="http://www.kitware.com" rel="noreferrer" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at<br>
<a href="http://www.kitware.com/opensource/opensource.html" rel="noreferrer" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Kitware offers ITK Training Courses, for more information visit:<br>
<a href="http://www.kitware.com/products/protraining.php" rel="noreferrer" target="_blank">http://www.kitware.com/products/protraining.php</a><br>
<br>
Please keep messages on-topic and check the ITK FAQ at:<br>
<a href="http://www.itk.org/Wiki/ITK_FAQ" rel="noreferrer" target="_blank">http://www.itk.org/Wiki/ITK_FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://public.kitware.com/mailman/listinfo/insight-users" rel="noreferrer" target="_blank">http://public.kitware.com/mailman/listinfo/insight-users</a><br>
<br></blockquote></div><br></div>
</blockquote></div><br></div>
</div></div></blockquote></div><br></div>
<br>_____________________________________<br>
Powered by <a href="http://www.kitware.com" rel="noreferrer" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at<br>
<a href="http://www.kitware.com/opensource/opensource.html" rel="noreferrer" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Kitware offers ITK Training Courses, for more information visit:<br>
<a href="http://www.kitware.com/products/protraining.php" rel="noreferrer" target="_blank">http://www.kitware.com/products/protraining.php</a><br>
<br>
Please keep messages on-topic and check the ITK FAQ at:<br>
<a href="http://www.itk.org/Wiki/ITK_FAQ" rel="noreferrer" target="_blank">http://www.itk.org/Wiki/ITK_FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://public.kitware.com/mailman/listinfo/insight-users" rel="noreferrer" target="_blank">http://public.kitware.com/mailman/listinfo/insight-users</a><br>
<br></blockquote></div>
</div></div></blockquote></div><br></div>
</div></div></blockquote></div><br></div>
</div></div></blockquote></div><br></div>
</div></div><br>_____________________________________<br>
Powered by <a href="http://www.kitware.com" rel="noreferrer" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at<br>
<a href="http://www.kitware.com/opensource/opensource.html" rel="noreferrer" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Kitware offers ITK Training Courses, for more information visit:<br>
<a href="http://www.kitware.com/products/protraining.php" rel="noreferrer" target="_blank">http://www.kitware.com/products/protraining.php</a><br>
<br>
Please keep messages on-topic and check the ITK FAQ at:<br>
<a href="http://www.itk.org/Wiki/ITK_FAQ" rel="noreferrer" target="_blank">http://www.itk.org/Wiki/ITK_FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://public.kitware.com/mailman/listinfo/insight-users" rel="noreferrer" target="_blank">http://public.kitware.com/mailman/listinfo/insight-users</a><br>
<br></blockquote></div><br></div>
</div></div></blockquote></div><br></div>
</div></div></blockquote></div><br></div>
</div></div></blockquote></div><br></div>