[Insight-users] itk surface extraction
Manuel
manuel.haegeli at students.fhnw.ch
Fri Apr 27 11:38:52 EDT 2012
Hi,
I'm trying to make a surface extraction on the iPad using itk v4
BinaryMask3DMeshSource and get an EXC_BAD_ACCESS inside BinaryMask3DMeshSource
on the InputImageIterator's Value call. I hoped a itk expert out there could
help me.
My Code is:
- (UIImage *) extractThreedImage{
unsigned int first = 0;
unsigned int last = 7;
const char* outputFilename = "out.vtk";
const char* seriesFormat = "/Users/manuel/Library/Application Support/iPhone
Simulator/5.1/
Applications/2199300E-AAFC-4E5D-8B2D-FC8880C04F2C/iMedviewer.app/slice%d.png";
itk::itkiOSImageIO::Pointer returnImage = itk::itkiOSImageIO::New();
typedef unsigned char PixelTp;
const unsigned int Dimension = 3;
typedef itk::Image< PixelType, Dimension > ImageTp;
typedef itk::ImageSeriesReader< ImageType > ReaderType;
typedef itk::ImageFileWriter< ImageType > WriterType;
ReaderType::Pointer reader = ReaderType::New();
WriterType::Pointer writer = WriterType::New();
typedef itk::NumericSeriesFileNames NameGeneratorType;
NameGeneratorType::Pointer nameGenerator = NameGeneratorType::New();
nameGenerator->SetSeriesFormat(seriesFormat);
nameGenerator->SetStartIndex( first );
nameGenerator->SetEndIndex( last );
nameGenerator->SetIncrementIndex( 1 );
reader->SetImageIO( itk::PNGImageIO::New() );
reader->SetFileNames( nameGenerator->GetFileNames() );
std::vector<std::string> names = nameGenerator->GetFileNames();
UIImage *outputImage = nil;
writer->SetInput( reader->GetOutput() );
writer->SetImageIO(returnImage);
writer->SetFileName( outputFilename );
returnImage->SetFileName(outputImage);
try {
writer->Update();
return returnImage->ReturnOutputImage();
}
catch( itk::ExceptionObject & err )
{
std::cerr << "ExceptionObject caught !" << std::endl;
std::cerr << err << std::endl;
return nil;
}
}
- (void) createSurfaceModelFrom3DImage: (UIImage *) threeDImage{
double objectValue = 125.0;
const unsigned int Dimension = 3;
typedef unsigned char PixelTp;
typedef itk::Image< PixelTp, Dimension > ImageTp;
typedef itk::ImageFileReader< ImageType > ReaderType;
ReaderType::Pointer reader = ReaderType::New();
itk::itkiOSImageIO::Pointer inputImage = itk::itkiOSImageIO::New();
inputImage->SetFileName(threeDImage);
reader->SetImageIO(inputImage);
reader->SetFileName("out.vtk");
typedef itk::Mesh<double> MeshType;
typedef itk::BinaryMask3DMeshSource< ImageType, MeshType > MeshSourceType;
MeshSourceType::Pointer meshSource = MeshSourceType::New();
meshSource->SetObjectValue( objectValue );
meshSource->SetInput( reader->GetOutput() );
try {
meshSource->Update();
std::cout << "Nodes = " << meshSource->GetNumberOfNodes() << std::endl;
std::cout << "Cells = " << meshSource->GetNumberOfCells() << std::endl;
}
catch( itk::ExceptionObject & exp )
{
std::cerr << "Exception thrown during Update() " << std::endl; std::cerr
<< exp << std::endl;
}
}
The console output:
itkiOSImageIO::SetFileName()
The image supplied is a NULL pointer
itkiOSImageIO::SetFileName() end
itkiOSImageIO::Write() Begin
width = 8
height = 8
multiplier = 4
writing 1 components
Using scalar pixel type
itkiOSImageIO::Write() End
itkiOSImageIO::~itkiOSImageIO() destructor called
itkiOSImageIO::SetFileName()
itkiOSImageIO::SetFileName() end
component type = uint
The image is 8 by 8 pixels in size
There are 32 bits per pixel
There are 32 bits per component
The colour space used is 0xd77a4b0
There are 1 components to the colour space
itkiOSImageIO::GenerateStreamableReadRegionFromRequestedRegion()
Requested region = ImageIORegion (0xbfffd888)
Dimension: 3
Index: 0 0 0
Size: 8 8 1
StreamableRegion = ImageIORegion (0xbfffd868)
Dimension: 3
Index: 0 0 0
Size: 8 8 1
itkiOSImageIO::Read() Begin
width = 8
height = 8
Using Scalar pixel type
setting parameters
creating context
releasing colour space
draw image
performing cast
itkiOSImageIO::Read() End
Thanks for your help.
Regards
Manuel
More information about the Insight-users
mailing list