Hi Luis,<br><br>Thanks for your reply. I have a meta type data and need to do some pixelwise computation with image iterator. As the very first step , I am thinking to read it in then write it out to test if ImageIO works. The original meta data are A.mhd and A.raw. The output file name associated with writer is Output.mhd. The problem is that the writer writes the image raw data to A.raw instead of Output.raw. Do you have any idel?<br>
<br>Thanks,<br><br>Ken<br>
<br><br><div class="gmail_quote">On Wed, Jun 3, 2009 at 10:06 PM, Luis Ibanez <span dir="ltr"><<a href="mailto:luis.ibanez@kitware.com">luis.ibanez@kitware.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;">
<br>
Hi Ken,<br>
<br>
The description of your problem seems to be incomplete.<br>
<br>
Could you please start by telling us what<br>
you are actually trying to do ?<br>
<br>
<br>
Thanks<br>
<br>
<br>
Luis<br>
<br>
<br>
----<br>
<br>
BTW: Please note that you don't need to connect a MetaImageIO<br>
to the file writer. The ImageIO factories take care of<br>
finding the proper ImageIO class based on the filename<br>
that you pass to the writer.<br>
<br>
Also, please about the use of the expression<br>
<br>
"using namespace std"<br>
<br>
it defeats the purpose of using namespaces.<br>
<br>
<br>
----------------------------------------------------------------------------<br>
ken wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div><div></div><div class="h5">
I am facing some problems with read/write metaImages. The original raw data file was overwritten by the generated raw data files even a new file name was assigned to the writer. Code is below and any input will be appreciated!<br>
<br>
<br>
/*=========================================================================*/<br>
<br>
#if defined(_MSC_VER)<br>
#pragma warning ( disable : 4786 )<br>
#endif<br>
<br>
#include "itkImage.h"<br>
#include "itkImageFileReader.h"<br>
#include "itkImageFileWriter.h"<br>
<br>
#include "itkMetaImageIO.h"<br>
<br>
#include <iostream><br>
#include <limits><br>
#include <iomanip><br>
#include <string><br>
#include <sstream><br>
#include <typeinfo><br>
using namespace std;<br>
<br>
<br>
int main( int argc, char **argv ) {<br>
<br>
//Input and output image data directory<br>
std::string inputImage = "A.mhd";<br>
std::string outputHeaderName = "Output.mhd";<br>
<br>
//Define the pixel type and dimension for reader<br>
typedef float InternalPixelType;<br>
const unsigned int Dimension=3;<br>
typedef itk::Image<InternalPixelType, Dimension> InternalImageType;<br>
<br>
//Define the reader<br>
typedef itk::ImageFileReader<InternalImageType> ReaderType;<br>
ReaderType::Pointer reader = ReaderType::New();<br>
typedef itk::MetaImageIO MetaImageIOType;<br>
MetaImageIOType::Pointer metaIO=MetaImageIOType::New();<br>
reader->SetImageIO(metaIO);<br>
reader->SetFileName(inputImage);<br>
<br>
//Update the reader<br>
try<br>
{<br>
reader->Update();<br>
}<br>
catch(itk::ExceptionObject & ex_reader)<br>
{<br>
std::cerr << "ExceptionObject caught @ _reader !" << std::endl;<br>
std::cout<<ex_reader<<std::endl;<br>
return EXIT_FAILURE;<br>
}<br>
<br>
<br>
//Initialize the writer<br>
typedef unsigned char OutputPixelType;<br>
typedef itk::Image<OutputPixelType, Dimension> OutputImageType;<br>
typedef itk::ImageFileWriter<OutputImageType> WriterType;<br>
WriterType::Pointer writer=WriterType::New();<br>
writer->SetImageIO(metaIO);<br>
writer->SetFileName(outputHeaderName);<br>
<br>
<br>
writer->SetInput(reader->GetOutput());<br>
<br>
try<br>
{<br>
writer->Update();<br>
}<br>
catch( itk::ExceptionObject & ex)<br>
{<br>
std::cerr << "ExceptionObject caught @ _writer !" << std::endl;<br>
std::cerr << ex << std::endl;<br>
return EXIT_FAILURE;<br>
}<br>
<br>
return EXIT_SUCCESS;<br>
}<br>
<br>
<br></div></div>
------------------------------------------------------------------------<br>
<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>
</blockquote>
</blockquote></div><br>