[Insight-users] In / out
Einstein, Daniel R
daniel.einstein at pnl.gov
Fri Aug 26 00:25:13 EDT 2005
Hello,
Terribly sorry. I have read the UG and looked over the tutorials concerning reading and writing to a buffer. My code compiles and runs .... but does nothing. To troubleshoot, I have implemented as fast and naïve threshold filter. Could someone please look this over and tell me what I am doing wrong?
Regards,
Dan
void myfunction::helloWorldFilter(float *fdata, int xdim, int ydim, int zdim,
int numiter, QApplication *app)
{
//
// ***********************************************************************
// Preliminaries to read the array into an ITK Image class *
// ***********************************************************************
//
typedef float PixelType;
const unsigned int Dimension = 3;
typedef itk::Image< PixelType, Dimension > ImageType;
typedef itk::ImportImageFilter< PixelType, Dimension > ImportFilterType;
ImportFilterType::Pointer importer = ImportFilterType::New();
ImportFilterType::SizeType size;
size[0] = xdim; // size along X
size[1] = ydim; // size along Y
size[2] = zdim; // size along Z
ImportFilterType::IndexType start;
start[0]=0;
start[1]=0;
start[2]=0;
ImportFilterType::RegionType region;
region.SetIndex( start );
region.SetSize( size );
importer->SetRegion( region );
double origin[ Dimension ];
origin[0] = 0.0; // X coordinate
origin[1] = 0.0; // Y coordinate
origin[2] = 0.0; // Z coordinate
importer->SetOrigin( origin );
double spacing[ Dimension ];
spacing[0] = 1.0; // along X direction
spacing[1] = 1.0; // along Y direction
spacing[2] = 1.0; // along Z direction
importer->SetSpacing( spacing );
const bool importFilterWillDeleteTheInputBuffer = false;
PixelType * pixeldata = static_cast< PixelType * >( fdata );
const unsigned int numberOfPixels = size[0] * size[1] * size[2];
importer->SetImportPointer( pixeldata, numberOfPixels,
importFilterWillDeleteTheInputBuffer );
importer->Update();
// ****************************************************************
// End preliminaries *
// ****************************************************************
//
// THRESHOLDING EXAMPLE
typedef itk::ThresholdImageFilter< ImageType > FilterType;
FilterType::Pointer filter = FilterType::New();
filter->SetInput( importer->GetOutput() );
filter->ThresholdBelow( 180 );
filter->Update();
//
// **************************************************************
// End Filter *
// **************************************************************
//
// **************************************************************
// Write back to array *
// **************************************************************
ImageType::PixelContainer * container;
container = filter->GetOutput()->GetPixelContainer();
container->SetContainerManageMemory( false );
fdata = container->GetImportPointer();
//
//
}
Best Regards,
Dan
Daniel R Einstein, PhD
Biological Monitoring and Modeling
Pacific Northwest National Laboratory
P.O. Box 999; MSIN P7-59
Richland, WA 99352
Tel: 509/ 376-2924
Fax: 509/376-9064
daniel.einstein at pnl.gov
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://public.kitware.com/pipermail/insight-users/attachments/20050825/8ea322a5/attachment.htm
More information about the Insight-users
mailing list