[vtkusers] Problem in opening ".mhd" file.

D, Yamini Yamini.D at philips.com
Fri Aug 31 09:34:09 EDT 2012


Hi,

I am trying to run the code for connected components, the input is in ".mhd"  format and code cannot read the input. The following are the code and the error.


#include "stdafx.h"
#include "itkConnectedComponentImageFilter.h"
#include "itkImageIOBase.h"
#include "itkMetaImageIO.h"
#include "itkCastImageFilter.h"
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"

using namespace std;
int main(int argc, char* argv[] )
{
      typedef   unsigned char  CPixelType;
       typedef float FPixelType;
       const     unsigned int    Dimension = 2;

  typedef itk::Image< CPixelType, Dimension > CImageType;
  typedef itk::Image< FPixelType, Dimension > FImageType;

   typedef itk::ImageFileReader< FImageType > ReaderType;
   typedef itk::CastImageFilter < FImageType,CImageType > CastType;
   typedef itk::ImageFileWriter< CImageType > WriterType;
   typedef itk::ConnectedComponentImageFilter<CImageType,CImageType,CImageType > FilterType;
  ReaderType::Pointer reader = ReaderType::New();
  CastType::Pointer caster = CastType::New();
  WriterType::Pointer writer = WriterType::New();
  FilterType::Pointer filter = FilterType::New();
  reader->SetFileName("d:\\EnhancedOutputImage2.mhd");
  cout<<"reader passed"<<endl;
  caster->SetInput(reader->GetOutput());
  cout<<"caster passed"<<endl;
  filter->SetInput (caster->GetOutput());

   try
      {
      writer->SetInput (filter->GetOutput());
      writer->SetFileName( "d:\\CCEOI2.png" );
           cout<<"writer passed"<<endl;
      writer->Update();
      }
   catch( itk::ExceptionObject & excep )
    {
    std::cerr << "Exception caught !" << std::endl;
    std::cerr << excep << std::endl;
    }

return EXIT_SUCCESS;

}

Error:
reader passed
caster passed
writer passed
MetaImage: Read: Cannot open data file
Exception caught !

itk::ExceptionObject (00C3E104)
Location: "void __thiscall itk::MetaImageIO::Read(void *)"
File: D:\Projects\InsightToolkit-4.1.0\Modules\IO\Meta\src\itkMetaImageIO.cxx
Line: 482
Description: itk::ERROR: MetaImageIO(03E86B80): File cannot be read: d:\EnhancedOutputImage2.mhd for r
eading.
Reason: No such file or directory
-----------------------------------

I also tried opening the input image in Para view , but it threw the following error:


ERROR: In ..\..\..\..\src\VTK\IO\vtkMetaImageReader.cxx, line 224

vtkMetaImageReader (16F67F70): MetaImage cannot read data from file.

Thank you,
Yamini.D


________________________________
The information contained in this message may be confidential and legally protected under applicable law. The message is intended solely for the addressee(s). If you are not the intended recipient, you are hereby notified that any use, forwarding, dissemination, or reproduction of this message is strictly prohibited and may be unlawful. If you are not the intended recipient, please contact the sender by return e-mail and destroy all copies of the original message.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20120831/17f07cb4/attachment.htm>


More information about the vtkusers mailing list