<div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div><div>David</div><div>Based on some message on this mailing list that now I'm unable to find, we use something like this.</div>
<div>I suppose it can be improved, but the code accomplishes the task of determining the type of data before actually reading the data.</div><div><br></div><div>HTH</div><div><br></div><div><font face="'courier new', monospace">...</font></div>
<div><font face="'courier new', monospace">typedef itk::ImageIOBase::IOComponentType ScalarPixelType;</font></div><div><font face="'courier new', monospace"><br></font></div><div><font face="'courier new', monospace"> itk::ImageIOBase::Pointer imageIO =</font></div>
<div><span style="white-space: pre-wrap; "><font face="'courier new', monospace">                </font></span><font face="'courier new', monospace">itk::ImageIOFactory::CreateImageIO(</font></div><div><span style="white-space: pre-wrap; "><font face="'courier new', monospace">                        </font></span><font face="'courier new', monospace">params::filenameIn, itk::ImageIOFactory::ReadMode);</font></div>
<div><font face="'courier new', monospace"><br></font></div><div><span style="white-space: pre-wrap; "><font face="'courier new', monospace">        </font></span><font face="'courier new', monospace">if (!imageIO) {</font></div>
<div><span style="white-space: pre-wrap; "><font face="'courier new', monospace">                </font></span><font face="'courier new', monospace">std::cerr << "Unable to create a valid ImageIO for image " <<</font></div>
<div><span style="white-space: pre-wrap; "><font face="'courier new', monospace">                        </font></span><font face="'courier new', monospace">params::filenameIn << ". Exiting." << std::endl;</font></div>
<div><span style="white-space: pre-wrap; "><font face="'courier new', monospace">                </font></span><font face="'courier new', monospace">return -1;</font></div><div><span style="white-space: pre-wrap; "><font face="'courier new', monospace">        </font></span><font face="'courier new', monospace">}</font></div>
<div><font face="'courier new', monospace"><br></font></div><div><font face="'courier new', monospace">// Now that we found the appropriate ImageIO class, ask it to</font></div><div><font face="'courier new', monospace">// read the meta data from the image file.</font></div>
<div><font face="'courier new', monospace">//</font></div><div><font face="'courier new', monospace"> imageIO->SetFileName(params::filenameIn);</font></div><div><font face="'courier new', monospace"> imageIO->ReadImageInformation();</font></div>
<div><span style="white-space: pre-wrap; "><font face="'courier new', monospace">        </font></span><font face="'courier new', monospace">const ScalarPixelType pixelType = imageIO->GetComponentType();</font></div>
<div><span style="white-space: pre-wrap; "><font face="'courier new', monospace">        </font></span><font face="'courier new', monospace">if (params::verbose)</font></div><div><span style="white-space: pre-wrap; "><font face="'courier new', monospace">                </font></span><font face="'courier new', monospace">std::cout << "Pixel Type is " << imageIO->GetComponentTypeAsString(pixelType)</font></div>
<div><span style="white-space: pre-wrap; "><font face="'courier new', monospace">                        </font></span><font face="'courier new', monospace"><< std::endl;</font></div><div><span style="white-space: pre-wrap; "><font face="'courier new', monospace">        </font></span><font face="'courier new', monospace">const size_t numDimensions = imageIO->GetNumberOfDimensions();</font></div>
<div><span style="white-space: pre-wrap; "><font face="'courier new', monospace">        </font></span><font face="'courier new', monospace">if (numDimensions != 3) {</font></div><div><span style="white-space: pre-wrap; "><font face="'courier new', monospace">                </font></span><font face="'courier new', monospace">std::cerr << "This soft only soports 3D volumes. Exiting"</font></div>
<div><span style="white-space: pre-wrap; "><font face="'courier new', monospace">                        </font></span><font face="'courier new', monospace"><< std::endl;</font></div><div><span style="white-space: pre-wrap; "><font face="'courier new', monospace">                </font></span><font face="'courier new', monospace">return -1;</font></div>
<div><span style="white-space: pre-wrap; "><font face="'courier new', monospace">        </font></span><font face="'courier new', monospace">}</font></div><div><font face="'courier new', monospace"><br></font></div>
<div><font face="'courier new', monospace"> switch (pixelType) {</font></div><div><span style="white-space: pre-wrap; "><font face="'courier new', monospace">                </font></span><font face="'courier new', monospace">case itk::ImageIOBase::UCHAR: DoTheRealThing<UC1d3ITKImgType>(); break; //</font><span style="font-family: 'courier new', monospace; ">UC1d3ITKImgType = unsigned char image of 1 channel, 3 dimensions</span></div>
<div><span style="white-space: pre-wrap; "><font face="'courier new', monospace">                </font></span><font face="'courier new', monospace">case itk::ImageIOBase::SHORT: DoTheRealThing<S1d3ITKImgType>(); break; //S1d3 = Short, one chanel, 3dimensions</font></div>
<div><span style="white-space: pre-wrap; "><font face="'courier new', monospace">                </font></span><font face="'courier new', monospace">case itk::ImageIOBase::USHORT: DoTheRealThing<US1d3ITKImgType>(); break;</font></div>
<div><span style="white-space: pre-wrap; "><font face="'courier new', monospace">                </font></span><font face="'courier new', monospace">case itk::ImageIOBase::FLOAT: DoTheRealThing<F1d3ITKImgType>(); break;</font></div>
<div><span style="white-space: pre-wrap; "><font face="'courier new', monospace">                </font></span><font face="'courier new', monospace">default:</font></div><div><span style="white-space: pre-wrap; "><font face="'courier new', monospace">                        </font></span><font face="'courier new', monospace">std::cerr << "Pixel Type ("</font></div>
<div><span style="white-space: pre-wrap; "><font face="'courier new', monospace">                                </font></span><font face="'courier new', monospace"><< imageIO->GetComponentTypeAsString(pixelType)</font></div>
<div><span style="white-space: pre-wrap; "><font face="'courier new', monospace">                                </font></span><font face="'courier new', monospace"><< ") not supported. Exiting." << std::endl;</font></div>
<div><span style="white-space: pre-wrap; "><font face="'courier new', monospace">                        </font></span><font face="'courier new', monospace">return -1;</font></div><div><font face="'courier new', monospace"> }</font></div>
<div><font face="'courier new', monospace"></font><font face="'courier new', monospace">return 0;</font></div><div><font face="'courier new', monospace"><br></font></div><div><div><font face="'courier new', monospace">template<typename TITKImgType></font></div>
<div><font face="'courier new', monospace">void</font></div><div><font face="'courier new', monospace">DoTheRealThing()</font></div><div><font face="'courier new', monospace">{</font></div><div><font face="'courier new', monospace"> // Read image with standard itkReadImageFilter as now, we know the type of image via template TITKImgType</font></div>
<div><span style="font-family: 'courier new', monospace; ">}</span></div></div><div><div></div><div class="h5"></div></div></div><div><div class="h5"><br><div class="gmail_quote">On Wed, Dec 1, 2010 at 2:37 PM, David Doria <span dir="ltr"><<a href="mailto:daviddoria@gmail.com" target="_blank">daviddoria@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Recently mhd has been my goto file format for writing non-standard-RGB<br>
type images. For example, I may write a<br>
<br>
itk::Image<float, 4><br>
<br>
or a<br>
<br>
itk::Image<float, 5><br>
<br>
To successfully read these files, I need to know ahead of time what<br>
type of pixel they contain so I can do:<br>
<br>
typedef itk::ImageFileReader<itk::Image<float, 5> > ReaderType;<br>
<br>
Is there a better way to read these files where the reader will adapt<br>
and give me back an image of the correct type without me having to<br>
specify the type before hand?<br>
<br>
Thanks,<br>
<br>
David<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>
Kitware offers ITK Training Courses, for more information visit:<br>
<a href="http://www.kitware.com/products/protraining.html" target="_blank">http://www.kitware.com/products/protraining.html</a><br>
<br>
Please keep messages on-topic and check the ITK FAQ at:<br>
<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>
</blockquote></div><br><br clear="all"><br></div></div><font color="#888888">-- <br>Sergio Vera<br><br> Alma IT Systems<br> C/ Vilana, 4B, 4º 1ª<br> 08022 Barcelona<br> T. (+34) 932 380 592<br> <a href="http://www.alma3d.com" target="_blank">www.alma3d.com</a><br>
</font></blockquote></div><br><br clear="all"><br>-- <br>Sergio Vera<br><br> Alma IT Systems<br> C/ Vilana, 4B, 4º 1ª<br> 08022 Barcelona<br> T. (+34) 932 380 592<br> <a href="http://www.alma3d.com">www.alma3d.com</a><br>