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/~doriad/ITK_List/CustomImageIO/">http://www.rpi.edu/~doriad/ITK_List/CustomImageIO/</a><br><br>Thoughts?<br><br>Thanks,<br><br>David<br>