[Insight-users] issue with metaImageIO
Luis Ibanez
luis.ibanez at kitware.com
Thu Jun 4 07:41:07 EDT 2009
Hi Ken,
Thanks for the clarification.
From your code, I don't see how is it possible that the program
is writing the image in the filename A.raw.
I would suggest to clean up your output directory, rerun the program
and to double check the date and time of creation of the output
files.
Regards,
Luis
--------------
ken wrote:
> Hi Luis,
>
> 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?
>
> Thanks,
>
> Ken
>
>
> On Wed, Jun 3, 2009 at 10:06 PM, Luis Ibanez <luis.ibanez at kitware.com
> <mailto:luis.ibanez at kitware.com>> wrote:
>
>
> Hi Ken,
>
> The description of your problem seems to be incomplete.
>
> Could you please start by telling us what
> you are actually trying to do ?
>
>
> Thanks
>
>
> Luis
>
>
> ----
>
> BTW: Please note that you don't need to connect a MetaImageIO
> to the file writer. The ImageIO factories take care of
> finding the proper ImageIO class based on the filename
> that you pass to the writer.
>
> Also, please about the use of the expression
>
> "using namespace std"
>
> it defeats the purpose of using namespaces.
>
>
> ----------------------------------------------------------------------------
> ken wrote:
>
> 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!
>
>
> /*=========================================================================*/
>
> #if defined(_MSC_VER)
> #pragma warning ( disable : 4786 )
> #endif
>
> #include "itkImage.h"
> #include "itkImageFileReader.h"
> #include "itkImageFileWriter.h"
>
> #include "itkMetaImageIO.h"
>
> #include <iostream>
> #include <limits>
> #include <iomanip>
> #include <string>
> #include <sstream>
> #include <typeinfo>
> using namespace std;
>
>
> int main( int argc, char **argv ) {
>
> //Input and output image data directory
> std::string inputImage = "A.mhd";
> std::string outputHeaderName = "Output.mhd";
>
> //Define the pixel type and dimension for reader
> typedef float InternalPixelType;
> const unsigned int Dimension=3;
> typedef itk::Image<InternalPixelType, Dimension>
> InternalImageType;
>
> //Define the reader
> typedef itk::ImageFileReader<InternalImageType> ReaderType;
> ReaderType::Pointer reader = ReaderType::New();
> typedef itk::MetaImageIO MetaImageIOType;
> MetaImageIOType::Pointer metaIO=MetaImageIOType::New();
> reader->SetImageIO(metaIO);
> reader->SetFileName(inputImage);
>
> //Update the reader
> try
> {
> reader->Update();
> }
> catch(itk::ExceptionObject & ex_reader)
> {
> std::cerr << "ExceptionObject caught @ _reader !" <<
> std::endl;
> std::cout<<ex_reader<<std::endl;
> return EXIT_FAILURE;
> }
>
>
> //Initialize the writer
> typedef unsigned char OutputPixelType;
> typedef itk::Image<OutputPixelType, Dimension>
> OutputImageType;
> typedef itk::ImageFileWriter<OutputImageType> WriterType;
> WriterType::Pointer writer=WriterType::New();
> writer->SetImageIO(metaIO);
> writer->SetFileName(outputHeaderName);
>
>
> writer->SetInput(reader->GetOutput());
>
> try
> {
> writer->Update();
> }
> catch( itk::ExceptionObject & ex)
> {
> std::cerr << "ExceptionObject caught @ _writer !" <<
> std::endl;
> std::cerr << ex << std::endl;
> return EXIT_FAILURE;
> }
>
> return EXIT_SUCCESS;
> }
>
>
> ------------------------------------------------------------------------
>
> _____________________________________
> Powered by www.kitware.com <http://www.kitware.com>
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the ITK FAQ at:
> http://www.itk.org/Wiki/ITK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.itk.org/mailman/listinfo/insight-users
>
>
More information about the Insight-users
mailing list