Пример #1
0
void
ipMITKSegmentationUndo (mitkIpPicDescriptor* segmentation)
{
    mitkIpPicTSV_t *undo, *data;

    assert (segmentation);
    undo = mitkIpPicQueryTag (segmentation, tagUNDO);
    if (!undo) {
        ipMITKSegmentationError (ipMITKSegmentationUNDO_DISABLED);
    }

    /* if any level is stored ... */
    data = mitkIpPicQuerySubTag (undo, tagUNDO_DATA);
    if (data->n[0]) {
        /* ... replace the image data and remove this level */
        _mitkIpPicTagsElement_t* head = (_mitkIpPicTagsElement_t *) data->value;
        _mitkIpPicTagsElement_t* current = head;
        mitkIpPicTSV_t* tag;

        while( current->next != NULL ) {
            current = current->next;
        }
        tag = _mitkIpPicRemoveTag (&head, current, current->tsv->tag);
        data->value = head;
        data->n[0]--;
        memmove (segmentation->data, tag->value, _mitkIpPicSize (segmentation));
        mitkIpPicFreeTag (tag);

        tag = mitkIpPicDelTag (segmentation, tagSEGMENTATION_EMPTY);
        if (tag) {
            mitkIpPicFreeTag (tag);
        }
    }
}
Пример #2
0
mitkIpBool_t
ipMITKSegmentationUndoIsEnabled (mitkIpPicDescriptor* segmentation)
{
    mitkIpPicTSV_t *undo = NULL;

    if (segmentation) {
  undo = mitkIpPicQueryTag (segmentation, tagUNDO);
    }
    return (undo ? mitkIpTrue : mitkIpFalse);
}
Пример #3
0
void mitk::PicFileReader::FillImage(Image::Pointer output)
{
  mitkIpPicDescriptor *outputPic = mitkIpPicNew();
  outputPic = CastToIpPicDescriptor(output, nullptr, outputPic);
  mitkIpPicDescriptor *pic = mitkIpPicGet(const_cast<char *>(this->GetLocalFileName().c_str()), outputPic);
  // comes upside-down (in MITK coordinates) from PIC file
  ConvertHandedness(pic);

  mitkIpPicTSV_t *tsv;
  if ((tsv = mitkIpPicQueryTag(pic, "SOURCE HEADER")) != NULL)
  {
    if (tsv->n[0] > 1e+06)
    {
      mitkIpPicTSV_t *tsvSH;
      tsvSH = mitkIpPicDelTag(pic, "SOURCE HEADER");
      mitkIpPicFreeTag(tsvSH);
    }
  }
  if ((tsv = mitkIpPicQueryTag(pic, "ICON80x80")) != NULL)
  {
    mitkIpPicTSV_t *tsvSH;
    tsvSH = mitkIpPicDelTag(pic, "ICON80x80");
    mitkIpPicFreeTag(tsvSH);
  }
  if ((tsv = mitkIpPicQueryTag(pic, "VELOCITY")) != NULL)
  {
    mitkIpPicDescriptor *header = mitkIpPicCopyHeader(pic, NULL);
    header->data = tsv->value;
    ConvertHandedness(header);
    output->SetChannel(header->data, 1);
    header->data = NULL;
    mitkIpPicFree(header);
    mitkIpPicDelTag(pic, "VELOCITY");
  }

  // Copy the memory to avoid mismatches of malloc() and delete[].
  // mitkIpPicGet will always allocate a new memory block with malloc(),
  // but MITK Images delete the data via delete[].
  output->SetImportChannel(pic->data, 0, Image::CopyMemory);
  pic->data = nullptr;
  mitkIpPicFree(pic);
}
Пример #4
0
mitkIpBool_t
ipMITKSegmentationUndoAvailable (mitkIpPicDescriptor* segmentation)
{
    mitkIpPicTSV_t *undo, *data;

    assert (segmentation);
    undo = mitkIpPicQueryTag (segmentation, tagUNDO);
    if (!undo) {
        ipMITKSegmentationError (ipMITKSegmentationUNDO_DISABLED);
    }
    data = mitkIpPicQuerySubTag (undo, tagUNDO_DATA);
    return (data->n[0] ? mitkIpTrue : mitkIpFalse);
}
Пример #5
0
void
ipMITKSegmentationUndoSave (mitkIpPicDescriptor* segmentation)
{
    mitkIpPicTSV_t *undo, *data, *level, *tag;

    assert (segmentation);
    undo = mitkIpPicQueryTag (segmentation, tagUNDO);
    if (!undo) {
        ipMITKSegmentationError (ipMITKSegmentationUNDO_DISABLED);
    }

    /* if no level is available ... */
    data = mitkIpPicQuerySubTag (undo, tagUNDO_DATA);
    level = mitkIpPicQuerySubTag (undo, tagUNDO_LEVEL);
    if (*((mitkIpUInt1_t *) level->value) > 0) {
        if (data->n[0] == *((mitkIpUInt1_t *) level->value)) {
            /* ... remove the first one. */
            _mitkIpPicTagsElement_t* head = (_mitkIpPicTagsElement_t *) data->value;
            mitkIpPicTSV_t* tag = _mitkIpPicRemoveTag (&head, head, head->tsv->tag);
      data->value = head;
      data->n[0]--;
            mitkIpPicFreeTag (tag);
        }
        /* build and store the level */
        tag = (mitkIpPicTSV_t *) malloc (sizeof (mitkIpPicTSV_t));
        if (!tag) {
            ipMITKSegmentationError (ipMITKSegmentationOUT_OF_MEMORY);
        }
        strcpy (tag->tag, "IMAGE");
        tag->type = segmentation->type;
        tag->bpe = segmentation->bpe;
        tag->dim = segmentation->dim;
        tag->n[0] = segmentation->n[0];
        tag->n[1] = segmentation->n[1];
        tag->value = malloc (_mitkIpPicSize (segmentation));
        memmove (tag->value, segmentation->data, _mitkIpPicSize (segmentation));
        mitkIpPicAddSubTag (data, tag);
    }
}
Пример #6
0
void mitk::PicFileReader::GenerateOutputInformation()
{
    Image::Pointer output = this->GetOutput();

    if ((output->IsInitialized()) && (this->GetMTime() <= m_ReadHeaderTime.GetMTime()))
        return;

    itkDebugMacro(<<"Reading file for GenerateOutputInformation()" << m_FileName);

    // Check to see if we can read the file given the name or prefix
    //
    if ( m_FileName == "" && m_FilePrefix == "" )
    {
        throw itk::ImageFileReaderException(__FILE__, __LINE__, "One of FileName or FilePrefix must be non-empty");
    }

    if( m_FileName != "")
    {
        mitkIpPicDescriptor* header=mitkIpPicGetHeader(const_cast<char *>(m_FileName.c_str()), NULL);

        if ( !header )
        {
            throw itk::ImageFileReaderException(__FILE__, __LINE__, "File could not be read.");
        }

        header=MITKipPicGetTags(const_cast<char *>(m_FileName.c_str()), header);

        int channels = 1;

        mitkIpPicTSV_t *tsv;
        if ( (tsv = mitkIpPicQueryTag( header, "SOURCE HEADER" )) != NULL)
        {
          if(tsv->n[0]>1e+06)
          {
            mitkIpPicTSV_t *tsvSH;
            tsvSH = mitkIpPicDelTag( header, "SOURCE HEADER" );
            mitkIpPicFreeTag(tsvSH);
          }
        }
        if ( (tsv = mitkIpPicQueryTag( header, "ICON80x80" )) != NULL)
        {
          mitkIpPicTSV_t *tsvSH;
          tsvSH = mitkIpPicDelTag( header, "ICON80x80" );
          mitkIpPicFreeTag(tsvSH);
        }
        if ( (tsv = mitkIpPicQueryTag( header, "VELOCITY" )) != NULL)
        {
          ++channels;
          mitkIpPicDelTag( header, "VELOCITY" );
        }

        if( header == NULL || header->bpe == 0)
        {
            itk::ImageFileReaderException e(__FILE__, __LINE__);
            itk::OStringStream msg;
            msg << " Could not read file "
                << m_FileName.c_str();
            e.SetDescription(msg.str().c_str());
            throw e;
            return;
        }

        // First initialize the geometry of the output image by the pic-header
        SlicedGeometry3D::Pointer slicedGeometry = mitk::SlicedGeometry3D::New();
        PicHelper::InitializeEvenlySpaced(header, header->n[2], slicedGeometry);

        // if pic image only 3D, the n[3] value is not initialized
        unsigned int timesteps = 1;
        if( header->dim > 3 )
            timesteps = header->n[3];

        TimeSlicedGeometry::Pointer timeSliceGeometry = TimeSlicedGeometry::New();
        timeSliceGeometry->InitializeEvenlyTimed(slicedGeometry, timesteps);
        timeSliceGeometry->ImageGeometryOn();

        // Cast the pic descriptor to ImageDescriptor and initialize the output

        output->Initialize( CastToImageDescriptor(header));
        output->SetGeometry( timeSliceGeometry );
        mitkIpPicFree ( header );
    }
    else
    {
        int numberOfImages=0;
        m_StartFileIndex=0;

        mitkIpPicDescriptor* header=NULL;

        char fullName[1024];

        while(m_StartFileIndex<10)
        {
            sprintf(fullName, m_FilePattern.c_str(), m_FilePrefix.c_str(), m_StartFileIndex+numberOfImages);
            FILE * f=fopen(fullName,"r");
            if(f==NULL) 
            {
                //already found an image?
                if(numberOfImages>0)
                    break;
                //no? let's increase start
                ++m_StartFileIndex;
            }
            else
            {
                fclose(f);
                //only open the header of the first file found,
                //@warning what to do when images do not have the same size??
                if(header==NULL) 
                {
                    header=mitkIpPicGetHeader(fullName, NULL);
                    header=MITKipPicGetTags(fullName, header);
                }
                ++numberOfImages;
            }
        }

        printf("\n numberofimages %d\n",numberOfImages);

        if(numberOfImages==0)
        {
            itk::ImageFileReaderException e(__FILE__, __LINE__);
            itk::OStringStream msg;
            msg << "no images found";
            e.SetDescription(msg.str().c_str());
            throw e;
            return;
        }

        //@FIXME: was ist, wenn die Bilder nicht alle gleich gross sind?
        if(numberOfImages>1)
        {  
            printf("\n numberofimages %d > 1\n",numberOfImages);
            header->dim=3;
            header->n[2]=numberOfImages;
        }

        printf(" \ninitialisize output\n");
        output->Initialize( CastToImageDescriptor(header) );
        mitkIpPicFree ( header );
    }

    m_ReadHeaderTime.Modified();
}
Пример #7
0
void mitk::PicFileReader::GenerateData()
{
    Image::Pointer output = this->GetOutput();

    // Check to see if we can read the file given the name or prefix
    //
    if ( m_FileName == "" && m_FilePrefix == "" )
    {
        throw itk::ImageFileReaderException(__FILE__, __LINE__, "One of FileName or FilePrefix must be non-empty");
    }

    if( m_FileName != "")
    {
        mitkIpPicDescriptor* outputPic = mitkIpPicNew();
        outputPic = CastToIpPicDescriptor(output, outputPic);
        mitkIpPicDescriptor* pic=MITKipPicGet(const_cast<char *>(m_FileName.c_str()),
                                              outputPic);
        // comes upside-down (in MITK coordinates) from PIC file
        ConvertHandedness(pic);

        mitkIpPicTSV_t *tsv;
        if ( (tsv = mitkIpPicQueryTag( pic, "SOURCE HEADER" )) != NULL)
        {
          if(tsv->n[0]>1e+06)
          {
            mitkIpPicTSV_t *tsvSH;
            tsvSH = mitkIpPicDelTag( pic, "SOURCE HEADER" );
            mitkIpPicFreeTag(tsvSH);
          }
        }
        if ( (tsv = mitkIpPicQueryTag( pic, "ICON80x80" )) != NULL)
        {
          mitkIpPicTSV_t *tsvSH;
          tsvSH = mitkIpPicDelTag( pic, "ICON80x80" );
          mitkIpPicFreeTag(tsvSH);
        }
        if ( (tsv = mitkIpPicQueryTag( pic, "VELOCITY" )) != NULL)
        {
          mitkIpPicDescriptor* header = mitkIpPicCopyHeader(pic, NULL);
          header->data = tsv->value;
          ConvertHandedness(header);
          output->SetChannel(header->data, 1);
          header->data = NULL;
          mitkIpPicFree(header);
          mitkIpPicDelTag( pic, "VELOCITY" );
        }

        //slice-wise reading
        //currently much too slow.
        //else
        //{
        //  int sstart, smax;
        //  int tstart, tmax;

        //  sstart=output->GetRequestedRegion().GetIndex(2);
        //  smax=sstart+output->GetRequestedRegion().GetSize(2);

        //  tstart=output->GetRequestedRegion().GetIndex(3);
        //  tmax=tstart+output->GetRequestedRegion().GetSize(3);

        //  int s,t;
        //  for(s=sstart; s<smax; ++s)
        //  {
        //    for(t=tstart; t<tmax; ++t)
        //    {
        //      mitkIpPicDescriptor* pic=mitkIpPicGetSlice(const_cast<char *>(m_FileName.c_str()), NULL, t*smax+s+1);
        //      output->SetPicSlice(pic,s,t);
        //    }
        //  }
        //}
    }
    else
    {
        int position;
        mitkIpPicDescriptor*  pic=NULL;

        int zDim=(output->GetDimension()>2?output->GetDimensions()[2]:1);
        printf("\n zdim is %u \n",zDim);

        for (position = 0; position < zDim; ++position) 
        {
            char fullName[1024];

            sprintf(fullName, m_FilePattern.c_str(), m_FilePrefix.c_str(), m_StartFileIndex+position);

            pic=MITKipPicGet(fullName, pic);
            if(pic==NULL)
            {
                itkDebugMacro("Pic file '" << fullName << "' does not exist."); 
            }
            /* FIXME else
            if(output->SetPicSlice(pic, position)==false)
            {
                itkDebugMacro("Image '" << fullName << "' could not be added to Image."); 
            }*/
       }
       if(pic!=NULL)
         mitkIpPicFree(pic);
    }
}
Пример #8
0
main( int argc, char *argv[] )
{
  XtAppContext app_context;
  Widget toplevel, bb, pic, annotation;
  /*Widget button;*/


  toplevel = XtVaAppInitialize( &app_context,
                                "Test",
                                NULL, 0,
                                &argc, argv,
                                fallback_resources,
                                NULL );

  XtAddEventHandler( toplevel,
                     (EventMask)0,
                     True,_XEditResCheckMessages,
                     NULL );

  n = 0;
  XtSetArg( args[n], XmNheight, 400 ); n++;
  XtSetArg( args[n], XmNwidth, 400 ); n++;

  XtSetValues( toplevel, args, n );

  bb = XmCreateDrawingArea( toplevel, "bb", args, n );
  XtManageChild( bb );


  n = 0;
  XtSetArg( args[n], XmNx, 200 ); n++;
  XtSetArg( args[n], XmNy, 100 ); n++;
  annotation = XtCreateManagedWidget( "annotation",
                                      xipAnnotationWidgetClass,
                                      bb,
                                      args, n );
  XtAddCallback( annotation, XipNactivateCallback, activate, NULL );

  n = 0;
  XtSetArg( args[n], XmNx, 0 ); n++;
  XtSetArg( args[n], XmNy, 0 ); n++;
  XtSetArg( args[n], XipNquantisation, True ); n++;
  XtSetArg( args[n], XipNpic, mitkIpPicGet( "../b.pic", NULL ) ); n++;
  pic = XtCreateManagedWidget( "pic",
                               xipPicWidgetClass,
                               bb,
                               args, n );
/**************/
  XtRealizeWidget( toplevel );
/**************/
  {
    mitkIpPicDescriptor *pic;
    _mitkIpPicTagsElement_t *head;
    mitkIpPicTSV_t *tsv;

    pic = mitkIpPicGetTags( "../b.pic",
                        NULL );
    tsv = mitkIpPicQueryTag( pic, "ANNOTATION" );
    if( tsv != NULL )
      {
        head = tsv->value;

        tsv = _mitkIpPicFindTag( head, "TEXT" )->tsv;
        text = malloc( strlen(tsv->value) );
        strcpy( text, tsv->value );
        printf( "%s\n", text );

        tsv = _mitkIpPicFindTag( head, "POSITION" )->tsv;
        x = ((mitkIpUInt4_t *)(tsv->value))[0];
        y = ((mitkIpUInt4_t *)(tsv->value))[1];
        printf( "%i %i\n", x, y );
      }

    mitkIpPicFree( pic );
  }
/**************/
  XtVaSetValues( annotation,
                 XmNx, x,
                 XmNy, y,
                 NULL );
/**************/
  XtAppMainLoop(app_context);
}
Пример #9
0
bool mitk::PicHelper::GetSpacing(const mitkIpPicDescriptor* aPic, Vector3D & spacing)
{
    mitkIpPicDescriptor* pic = const_cast<mitkIpPicDescriptor*>(aPic);

    mitkIpPicTSV_t *tsv;
    bool pixelSize = false;

    tsv = mitkIpPicQueryTag( pic, "REAL PIXEL SIZE" );
    if(tsv==NULL)
    {
        tsv = mitkIpPicQueryTag( pic, "PIXEL SIZE" );
        pixelSize = true;
    }
    if(tsv)
    {
        bool tagFound = false;
        if((tsv->dim*tsv->n[0]>=3) && (tsv->type==mitkIpPicFloat))
        {
            if(tsv->bpe==32)
            {
                FillVector3D(spacing,((mitkIpFloat4_t*)tsv->value)[0], ((mitkIpFloat4_t*)tsv->value)[1],((mitkIpFloat4_t*)tsv->value)[2]);
                tagFound = true;
            }
            else if(tsv->bpe==64)
            {
                FillVector3D(spacing,((mitkIpFloat8_t*)tsv->value)[0], ((mitkIpFloat8_t*)tsv->value)[1],((mitkIpFloat8_t*)tsv->value)[2]);
                tagFound = true;
            }
        }
        if(tagFound && pixelSize)
        {
            tsv = mitkIpPicQueryTag( pic, "PIXEL SPACING" );
            if(tsv)
            {
                mitk::ScalarType zSpacing = 0;
                if((tsv->dim*tsv->n[0]>=3) && (tsv->type==mitkIpPicFloat))
                {
                    if(tsv->bpe==32)
                    {
                        zSpacing = ((mitkIpFloat4_t*)tsv->value)[2];
                    }
                    else if(tsv->bpe==64)
                    {
                        zSpacing = ((mitkIpFloat8_t*)tsv->value)[2];
                    }
                    if(zSpacing != 0)
                    {
                        spacing[2] = zSpacing;
                    }
                }
            }
        }
        if(tagFound) return true;
    }
#ifdef HAVE_IPDICOM
    tsv = mitkIpPicQueryTag( pic, "SOURCE HEADER" );
    if( tsv )
    {
        void *data;
        mitkIpUInt4_t len;
        mitkIpFloat8_t spacing_z = 0;
        mitkIpFloat8_t thickness = 1;
        mitkIpFloat8_t fx = 1;
        mitkIpFloat8_t fy = 1;
        bool ok=false;

        if( dicomFindElement( (unsigned char *) tsv->value, 0x0018, 0x0088, &data, &len ) )
        {
            ok=true;
            sscanf( (char *) data, "%lf", &spacing_z );
//        itkGenericOutputMacro( "spacing:  " << spacing_z << " mm");
        }
        if( dicomFindElement( (unsigned char *) tsv->value, 0x0018, 0x0050, &data, &len ) )
        {
            ok=true;
            sscanf( (char *) data, "%lf", &thickness );
//        itkGenericOutputMacro( "thickness: " << thickness << " mm");

            if( thickness == 0 )
                thickness = 1;
        }
        if( dicomFindElement( (unsigned char *) tsv->value, 0x0028, 0x0030, &data, &len )
                && len>0 && ((char *)data)[0] )
        {
            sscanf( (char *) data, "%lf\\%lf", &fy, &fx );    // row / column value
//        itkGenericOutputMacro( "fx, fy: " << fx << "/" << fy  << " mm");
        }
        else
            ok=false;
        if(ok)
            FillVector3D(spacing, fx, fy,( spacing_z > 0 ? spacing_z : thickness));
        return ok;
    }
#endif /* HAVE_IPDICOM */
    if(spacing[0]<=0 || spacing[1]<=0 || spacing[2]<=0)
    {
        itkGenericOutputMacro(<< "illegal spacing by pic tag: " << spacing << ". Setting spacing to (1,1,1).");
        spacing.Fill(1);
    }
Пример #10
0
void
ipMITKSegmentationUndoEnable (mitkIpPicDescriptor* segmentation, const mitkIpUInt1_t level)
{
    mitkIpPicTSV_t *undo, *data, *max;

    assert (segmentation);
    undo = mitkIpPicQueryTag (segmentation, tagUNDO);
    if (!undo) {
        undo = (mitkIpPicTSV_t *) malloc (sizeof (mitkIpPicTSV_t));
        if (!undo) {
            ipMITKSegmentationError (ipMITKSegmentationOUT_OF_MEMORY);
        }
        strcpy (undo->tag, tagUNDO);
        undo->type = mitkIpPicTSV;
        undo->bpe = 32;
        undo->dim = 1;
        undo->n[0] = 0;
        undo->value = NULL;
        mitkIpPicAddTag (segmentation, undo);
    }

    data = mitkIpPicQuerySubTag (undo, tagUNDO_DATA);
    if (!data) {
        data = (mitkIpPicTSV_t *) malloc (sizeof (mitkIpPicTSV_t));
        if (!data) {
            ipMITKSegmentationError (ipMITKSegmentationOUT_OF_MEMORY);
        }
        strcpy (data->tag, tagUNDO_DATA);
        data->type = mitkIpPicTSV;
        data->bpe = 32;
        data->dim = 1;
        data->n[0] = 0;
        data->value = NULL;
        mitkIpPicAddSubTag (undo, data);
    }
    if (data->n[0] > level) {
        /* remove levels which exceed the maximum */
        mitkIpUInt1_t i;

        for (i = data->n[0] - level; i > 0; i--) {
            _mitkIpPicTagsElement_t *head = (_mitkIpPicTagsElement_t *) data->value;
            mitkIpPicTSV_t* tag = _mitkIpPicRemoveTag (&head, head, head->tsv->tag);
      data->value = head;
      data->n[0]--;
            mitkIpPicFreeTag (tag);
        }
    }

    max = mitkIpPicQuerySubTag (undo, tagUNDO_LEVEL);
    if (max) {
        /* change the maximum of levels */
        mitkIpUInt1_t* value = (mitkIpUInt1_t *) max->value;
        *value = level;
    } else {
        mitkIpUInt1_t* value = (mitkIpUInt1_t *) malloc (sizeof (mitkIpUInt1_t));
        if (!value) {
            ipMITKSegmentationError (ipMITKSegmentationOUT_OF_MEMORY);
        }
        *value = level;

        max = (mitkIpPicTSV_t *) malloc (sizeof (mitkIpPicTSV_t));
        if (!max) {
            ipMITKSegmentationError (ipMITKSegmentationOUT_OF_MEMORY);
        }
        strcpy (max->tag, tagUNDO_LEVEL);
        max->type = mitkIpPicUInt;
        max->bpe = 8;
        max->dim = 1;
        max->n[0] = 1;
        max->value = value;
        mitkIpPicAddSubTag (undo, max);
    }
}
Пример #11
0
mitk::Image::Pointer mitk::PicFileReader::CreateImage()
{
  Image::Pointer output = Image::New();

  std::string fileName = this->GetLocalFileName();

  mitkIpPicDescriptor *header = mitkIpPicGetHeader(const_cast<char *>(fileName.c_str()), NULL);

  if (!header)
  {
    mitkThrow() << "File could not be read.";
  }

  header = mitkIpPicGetTags(const_cast<char *>(fileName.c_str()), header);

  int channels = 1;

  mitkIpPicTSV_t *tsv;
  if ((tsv = mitkIpPicQueryTag(header, "SOURCE HEADER")) != NULL)
  {
    if (tsv->n[0] > 1e+06)
    {
      mitkIpPicTSV_t *tsvSH;
      tsvSH = mitkIpPicDelTag(header, "SOURCE HEADER");
      mitkIpPicFreeTag(tsvSH);
    }
  }
  if ((tsv = mitkIpPicQueryTag(header, "ICON80x80")) != NULL)
  {
    mitkIpPicTSV_t *tsvSH;
    tsvSH = mitkIpPicDelTag(header, "ICON80x80");
    mitkIpPicFreeTag(tsvSH);
  }
  if ((tsv = mitkIpPicQueryTag(header, "VELOCITY")) != NULL)
  {
    ++channels;
    mitkIpPicDelTag(header, "VELOCITY");
  }

  if (header == NULL || header->bpe == 0)
  {
    mitkThrow() << " Could not read file " << fileName;
  }

  // if pic image only 2D, the n[2] value is not initialized
  unsigned int slices = 1;
  if (header->dim == 2)
  {
    header->n[2] = slices;
  }

  // First initialize the geometry of the output image by the pic-header
  SlicedGeometry3D::Pointer slicedGeometry = mitk::SlicedGeometry3D::New();
  PicHelper::InitializeEvenlySpaced(header, header->n[2], slicedGeometry);

  // if pic image only 3D, the n[3] value is not initialized
  unsigned int timesteps = 1;
  if (header->dim > 3)
  {
    timesteps = header->n[3];
  }

  slicedGeometry->ImageGeometryOn();
  ProportionalTimeGeometry::Pointer timeGeometry = ProportionalTimeGeometry::New();
  timeGeometry->Initialize(slicedGeometry, timesteps);

  // Cast the pic descriptor to ImageDescriptor and initialize the output

  output->Initialize(CastToImageDescriptor(header));
  output->SetTimeGeometry(timeGeometry);
  mitkIpPicFree(header);

  return output;
}