[Insight-users] Data transfer

Zihua Su zihuabox at gmail.com
Wed Apr 4 17:32:50 EDT 2007


Hi there,

Though I tried the whole day, i finally gave it up. The Data trasnfer
is not right.

My situation is like follows:
  I have a pre-defined data with the format unsigned short and a
pointer pImg to it.
I choose ImportImageFilter to chang it to ITK image data format so
that it can be processed by DanielssonDistanceMapImageFilter. It ends
up give me a balck sceen with nothing in it.

core part of my code is in the attachment.

Pls give me some clue for this/

Richard
-------------- next part --------------

#include "LcgParticalSegmentation.h" 
#include "LcgUtilities.h"

typedef  unsigned short  PixelType;
typedef itk::Image< PixelType,  2 >   ImageType;
typedef itk::ImageRegionConstIterator<ImageType> IteratorType; 
typedef itk::ImportImageFilter< PixelType, 2 > ImportFilterType;
/// define input and output imagetype,  2 stands for 2 dimension
typedef itk::DanielssonDistanceMapImageFilter<
                   ImageType, ImageType >  FilterType;
typedef itk::RescaleIntensityImageFilter< 
                   ImageType, ImageType > RescalerType;
typedef PixelType* PixelBufferPointer;

void LcgParticalSegmentation::RichardDistanceMap(unsigned short *pImg, unsigned short *pBufferImage, int nx, int ny, int nz)
{
			///// 3d data will be processed slice by slice
			//// convert each slice to ITK supported format
      const int Dimension=2;
	  FilterType::Pointer filter = FilterType::New();
	  ImportFilterType::Pointer importFilter = ImportFilterType::New();
	  ImportFilterType::SizeType size;
       size[0] = nx; // size along X
       size[1] = ny; // size along Y
	   ImportFilterType::IndexType start;
       start.Fill( 0 );
	   ImportFilterType::RegionType region;
       region.SetIndex( start );
       region.SetSize( size );
	   importFilter->SetRegion( region );
	   double origin[ Dimension ];
       origin[0] = 0.0; // X coordinate
       origin[1] = 0.0; // Y coordinate
       importFilter->SetOrigin( origin );
	   double spacing[ Dimension ];
		spacing[0] = 1.0; // along X direction
		spacing[1] = 1.0; // along Y direction

	   const unsigned int numberOfPixels = size[0] * size[1] ;
       PixelType ** localBuffer = new PixelType* [nx ];
	   int i;
	   for (i=0;i<nx;i++)
	   {
		   *(localBuffer+i)=new PixelType [ny ];
	   }
       // localBuffer[0][0] = 3;
	  // PixelType * it = localBuffer;

	   int x,y;
	   int z=200;
	   for (x=0;x<nx;x++)
	  {
		  for (y=0;y<ny;y++)
		  {
			    localBuffer[x][y]=*(pImg+x+y*nx+z*nx*ny);

	          // image->SetPixel(   pixelIndex,   *(pImg+x+y*nx+z*nx*ny)  );

		 }

	}
      PixelType * pixelData= static_cast<PixelType*>( *localBuffer );
	  const bool importImageFilterWillOwnTheBuffer = true;
      importFilter->SetImportPointer( pixelData, numberOfPixels,
      importImageFilterWillOwnTheBuffer );
	  importFilter->Update();


	  
	
     
	  ImageType::Pointer image=importFilter->GetOutput();
	  
	  /*ImageType::RegionType imageregion;
	  ImageType::SizeType imagesize;
      imagesize[0] = nx; // size along X
      imagesize[1] = ny; // size along Y
      
      imageregion.SetSize(imagesize);
      image.se*/
   



	  filter->SetInput (image);
	    filter->InputIsBinaryOn();
	//  filter->Update;

		//ImageType::
	 ImageType::Pointer image2=filter->GetOutput();
	 //ImageType::Pointer  image2=ImageType::New(); 
	//image2=filter->GetOutput();
    
	ImageType::RegionType region2;
    region2 = image2->GetBufferedRegion();

    const unsigned int totalNumberOfPixels= nx* ny;
  //  const PixelBufferPointer & buffer= new PixelType[ totalNumberOfPixels] ;

	IteratorType it2( image2, region2);
	it2.GoToBegin();
	unsigned short * data= pBufferImage+200*nx*ny;
	while( ! it2.IsAtEnd() )
	{
	*data= it2.Get();
	++it2;
	++data;
	}



	  for (z=0;z<nz;z++)
	  {
		  for (x=0;x<nx;x++)
			{
				for (y=0;y<ny;y++)
				{
	
					*(pImg+x+y*nx+z*nx*ny)=*(pBufferImage+x+y*nx+z*nx*ny);
				}

			}
	  }

}


void LcgParticalSegmentation::RichardParticalSegmentation(unsigned short *pImg, unsigned short *pBufferImage, int nx, int ny, int nz)
{

}

























More information about the Insight-users mailing list