void ReadImage(medAbstractData* medData,itk::DCMTKImageIO::Pointer io,const QStringList& paths) {
    typename itk::ImageFileReader<itk::Image<TYPE,DIM> >::Pointer Reader = itk::ImageFileReader<itk::Image<TYPE,DIM> >::New();
    Reader->SetImageIO(io);
    Reader->SetFileName(paths[0].toAscii().constData());
    medData->setData(Reader->GetOutput());
    Reader->Update();
}
//! a helper function for image loading
template <class T> typename T::Pointer load_image(const char *file)
{
  typename itk::ImageFileReader<T>::Pointer reader = itk::ImageFileReader<T>::New();
  reader->SetFileName(file);
  reader->Update();
  return reader->GetOutput();
}
Beispiel #3
0
// a helper function for minc reading
template <class T> typename T::Pointer load_minc(const char *file)
{
  typedef itk::MincImageIO ImageIOType;
  ImageIOType::Pointer minc2ImageIO = ImageIOType::New();
     
  typename itk::ImageFileReader<T>::Pointer reader = itk::ImageFileReader<T>::New();
    
  reader->SetFileName(file);
  reader->SetImageIO( minc2ImageIO );
  reader->Update();
    
  return reader->GetOutput();
}
bool itkDataImageReaderBase::read_image(const QString& path,const char* type)
{
    medAbstractData* medData = dynamic_cast<medAbstractData*>(this->data());
    if (medData && medData->identifier()!=type)
        return false;

    typedef itk::Image<T,DIM> Image;
    typename itk::ImageFileReader<Image>::Pointer TReader = itk::ImageFileReader<Image>::New();
    TReader->SetImageIO(this->io);
    TReader->SetFileName(path.toAscii().constData());
    TReader->SetUseStreaming(true);
    typename Image::Pointer im = TReader->GetOutput();
    medData->setData(im);

    //  Recover the pixel meaning from the intent_name.

    const itk::MetaDataDictionary dict = im->GetMetaDataDictionary();
    std::string PixMeaning;
    if (itk::ExposeMetaData(dict,"intent_name",PixMeaning))
        medData->addMetaData(medAbstractImageData::PixelMeaningMetaData,QString(PixMeaning.c_str()));

    TReader->Update();

    return true;
}
void readwarpfile(int nlhs,
               mxArray *plhs[],
               int nrhs,
               const mxArray *prhs[])
{
   typedef int PixelType;
   typedef itk::Image< PixelType, Dimension >           ImageType;
 //  mexPrintf("the dimentsion is ", Dimension);   
 //  typedef                                           PixelType;
   typedef itk::Vector<PixelType, Dimension>  VectorPixelType;
   typedef itk::Image<VectorPixelType, Dimension>       DeformationFieldType;

   typedef itk::WarpImageFilter
      <ImageType, ImageType, DeformationFieldType>      WarperType;
   mexPrintf("input number is: %d", nrhs);
   mexPrintf("output parameternumber is: %d", nlhs);
 // mexPrintf("the dimentsion is :%d", Dimension); 
   //boost::timer timer;
   typename DeformationFieldType::SizeType       size;
   typename DeformationFieldType::IndexType      start;
   unsigned int numPix(1u);
   char * inputDfFilename; 
   mwSize matlabdims[Dimension];

// here, we should read image parameter
   for (unsigned int d=0; d<Dimension; d++)
   {
      matlabdims[d]= mxGetDimensions(prhs[1])[d];
      size[d] = matlabdims[d];
      start[d] = 0;
      numPix *= size[d];

//    inptrs[d] = static_cast<const MatlabPixelType *>(mxGetData(prhs[d]));
   }
   inputDfFilename = mxArrayToString(prhs[0]);
   mexPrintf("output file name is %s", inputDfFilename);
   typename itk::ImageFileReader<DeformationFieldType>::Pointer df_reader = itk::ImageFileReader<DeformationFieldType>::New();
   df_reader->SetFileName(inputDfFilename);
   df_reader->Update();

   // Allocate images and deformation field
   typename ImageType::Pointer image
      = ImageType::New();
   typename DeformationFieldType::Pointer field = DeformationFieldType::New();
//  typename DeformationFieldType::Pointer field = 0; 
   typename DeformationFieldType::SpacingType spacing;
   spacing.Fill( 1.0 );
   
   typename DeformationFieldType::PointType origin;
   origin.Fill( 0.0 );
   
   typename DeformationFieldType::RegionType     region;
   field = df_reader->GetOutput();


   region = field->GetLargestPossibleRegion();

// initialize output point
   const mxClassID classID = mxGetClassID(prhs[1]);
   MatlabPixelType * fieldoutptrs[Dimension];
   for (unsigned int d=0; d<Dimension; d++)
   {
      plhs[d] = mxCreateNumericArray(
         Dimension, matlabdims, classID, mxREAL);

      fieldoutptrs[d] = static_cast<MatlabPixelType *>(mxGetData(plhs[d]));
   }


// read field
   VectorPixelType * fieldptr = field->GetBufferPointer();
   const VectorPixelType * const buff_end = fieldptr + numPix;
 

     while ( fieldptr != buff_end )
   {
      for (unsigned int d=0; d<Dimension; d++)
      {
         *(fieldoutptrs[d])++ = (*fieldptr)[d];
      }
      ++fieldptr;
   }

}