<br>Hi David,<br><br>The approach that you are taking for serialization will not be<br>very portable. It probably will only work for reading images <br>that you save in your exact same computer.<br><br><br>Your pixel type "TestClass" is particularly difficult for serializing<br>
an image, given that your string component will probably have<br>a different size on every pixel .... (does that happen ?).<br><br><br>You may have to write your own customized ImageIO class.<br><br><br> Regards,<br><br>
<br> Luis<br><br><br>-------------------------------------------------------------------------------------<br><div class="gmail_quote">On Wed, Aug 12, 2009 at 11:13 AM, David Doria <span dir="ltr"><<a href="mailto:daviddoria%2Bitk@gmail.com">daviddoria+itk@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">It is easy to construct an itk image of a custom class:<br><br>class TestClass<br>{<br> public:<br>
TestClass(){}<br> TestClass(const double d, const std::string &s) : MyDouble(d), MyString(s) {}<br><br>
double MyDouble;<br> std::string MyString;<br>};<br><br> typedef TestClass PixelType;<br>
const unsigned int Dimension = 2;<br> typedef itk::Image< PixelType, Dimension > ImageType;<br><br><br>But is there a way to read/write to a file? Clearly it would not fit in any predefined IO class (itkMYCLASSImageIO), but couldn't serialization be used to convert the contents into an binary array that can be vectorized and un-vectorized into an N-D image?<br clear="all">
<br>When I try to write the TestClass image using the itkRawImageIO<br><br> itk::RawImageIO<PixelType,2>::Pointer io;<br> io = itk::RawImageIO<PixelType,2>::New();<br> <br> typedef itk::ImageFileWriter< ImageType > WriterType;<br>
WriterType::Pointer writer = WriterType::New();<br> writer->SetFileName( "test.raw" );<br> writer->SetInput(image); <br> writer->SetImageIO(io);<br><br>I get:<br><br>error: 'Length' is not a member of 'TestClass'<br>
error: no type named 'ValueType' in 'class TestClass'<br><br>
I added<br><br>class TestClass<br>{<br> public:<br> typedef TestClass ValueType;<br><br>(The error went way, but I'm not sure that this is right?)<br><br>It seems like all that is left is defining Length? It seems like read and write functions were never specified, so I feel like this isn't going to work anyway?<br>
<br>With VSL from VXL, you simply have to define these functions in your class:<br><br>//: Binary save to stream.<br>
void vsl_b_write(vsl_b_ostream & os, TestClass const & obj);<br>
//: Binary load from stream.<br>
void vsl_b_read(vsl_b_istream & is, TestClass & obj);<br>
//: Print human readable summary of object to a stream<br>
void vsl_print_summary(vcl_ostream & os, TestClass const & obj);<br><br>These functions are very easy to write as VSL provides the same functions for all "built in" types (so in this case, we would just have to call vsl_b_write(os, double) followed by vsl_b_write(os, string) ). Is something like this possible in ITK?<br>
<br>Some compilable code (with the error) is here:<br><a href="http://www.rpi.edu/%7Edoriad/ITK_List/CustomImageIO/" target="_blank">http://www.rpi.edu/~doriad/ITK_List/CustomImageIO/</a><br><br>Thoughts?<br><br>Thanks,<br>
<font color="#888888"><br>David<br>
</font><br>_____________________________________<br>
Powered by <a href="http://www.kitware.com" 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" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Please keep messages on-topic and check the ITK FAQ at: <a href="http://www.itk.org/Wiki/ITK_FAQ" target="_blank">http://www.itk.org/Wiki/ITK_FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.itk.org/mailman/listinfo/insight-users" target="_blank">http://www.itk.org/mailman/listinfo/insight-users</a><br>
<br></blockquote></div><br>