[Insight-users] XCode crashes at Chan Vese Filter

Ella Maria Kadas ella_kadas at yahoo.com
Fri Feb 25 16:09:11 EST 2011



Hi all,#
1.     I can finally use my ITK320 dir installed with CMake in Xcode for an Osirix plugin.2.     My images are t2 3D MRI 256x256 min gray value = -21, max = 800.           -first i just tried to segment the ventricles. The compilation takes a very long time             and has very little with the image information to do.  
        - i assume is because of the sigmoid values that i set, and the 
distance map using                  FastMarchingFilter. 
3.    When i try to use the Chan Vese Filter the example
 from          http://www.itk.org/Wiki/ITK/Examples/Segmentation/MultiphaseChanAndVeseSparseFieldLevelSetSegmentation      by
 adding stuff to the class ActiveContours  i can first include the 
headers and define    that some filters for CHan Vese, but when i run it in Osirix i get 
BAD_ACCESS which means that i am using some thing that were not 
initialized properly (at least this is what i noticed so far in my 
development ). Even when i comment the new written lines it just doesn't
 change anything althought it had been working a second ago. Is this an 
Xcode bug?4.       I tried to create a class with a different 
name, and somehow write everything i need for Chan Vese step by step 
again, and now although i got no errors in the #include headers part, i 
got in the class when defining for ex at:
typedef itk::ScalarChanAndVeseLevelSetFunctionData< LevelSetImageType,    FeatureImageType > DataHelperType;
Error expected before token"<".  
     My problem is just that i don't see any logic in this behaviour, and i can't really reproduce
 it so at least i would know that the instalation with Cmake didn't work out, or I am not 
setting the right flags in XCode.
My code is:
- (void) ActiveContour3D:(ViewerController *)sourceV :(int)slice :(NSPoint)startingPoint :(NSString*)newname

{

typedef float InternalPixelType;
const unsigned int Dimension = 3; 
typedef itk::Image< InternalPixelType, Dimension > InternalImageType;
typedef unsigned char OutputPixelType;
typedef itk::Image< OutputPixelType, Dimension > OutputImageType;

typedef itk::CastImageFilter< OutputImageType, OutputImageType > CastingFilterType;
CastingFilterType::Pointer casterfinal = CastingFilterType::New();


typedef itk::BinaryThresholdImageFilter<InternalImageType,OutputImageType > ThresholdingFilterType;
ThresholdingFilterType::Pointer thresholder = ThresholdingFilterType::New();
thresholder->SetLowerThreshold( -1000.0 );
thresholder->SetUpperThreshold( 0.0 );
thresholder->SetOutsideValue( 0 );
thresholder->SetInsideValue( 255 );


typedef itk::GiplImageIO GiplIOType;
GiplIOType::Pointer giplIO = GiplIOType::New();
typedef itk::ImageFileWriter< OutputImageType > WriterType; 
WriterType::Pointer writer = WriterType::New();

typedef itk::RescaleIntensityImageFilter<InternalImageType,OutputImageType > CastFilterType;
typedef itk::CurvatureAnisotropicDiffusionImageFilter<InternalImageType,InternalImageType > SmoothingFilterType;
SmoothingFilterType::Pointer smoothing = SmoothingFilterType::New(); 
typedef itk::GradientMagnitudeRecursiveGaussianImageFilter<InternalImageType,InternalImageType > GradientFilterType;
typedef itk::SigmoidImageFilter<InternalImageType,InternalImageType > SigmoidFilterType;
GradientFilterType::Pointer gradientMagnitude = GradientFilterType::New();
SigmoidFilterType::Pointer sigmoid = SigmoidFilterType::New();


sigmoid->SetOutputMinimum( 0.0 );
sigmoid->SetOutputMaximum( 1.0 );


typedef itk::FastMarchingImageFilter<InternalImageType,InternalImageType > FastMarchingFilterType;
FastMarchingFilterType::Pointer fastMarching = FastMarchingFilterType::New();

typedef itk::GeodesicActiveContourLevelSetImageFilter< InternalImageType,InternalImageType > GeodesicActiveContourFilterType;
GeodesicActiveContourFilterType::Pointer geodesicActiveContour = GeodesicActiveContourFilterType::New();
const double propagationScaling = 10.0;
geodesicActiveContour->SetPropagationScaling(propagationScaling);
geodesicActiveContour->SetCurvatureScaling(1.0);
geodesicActiveContour->SetAdvectionScaling( 1.0 );
geodesicActiveContour->SetMaximumRMSError( 0.02 );
geodesicActiveContour->SetNumberOfIterations( 40 );

InternalImageType::IndexType index;
index[0] = (long) startingPoint.x;
index[1] = (long) startingPoint.y;
index[2] = [[sourceV imageView] curImage];
NSLog(@"StartingPoint is %d %d %d", index[0],index[1],index[2]);


smoothing->SetInput([itkImage itkImporter]->GetOutput() );
gradientMagnitude->SetInput( smoothing->GetOutput() );
sigmoid->SetInput( gradientMagnitude->GetOutput() );
geodesicActiveContour->SetInput( fastMarching->GetOutput() );
geodesicActiveContour->SetFeatureImage( sigmoid->GetOutput() );
thresholder->SetInput( geodesicActiveContour->GetOutput() );
smoothing->SetTimeStep( 0.0625 );
smoothing->SetNumberOfIterations( 5 );
smoothing->SetConductanceParameter( 6.0 );
const double sigma =  1.0;
gradientMagnitude->SetSigma( sigma );
const double alpha = -5.0;
const double beta = 3.0;
sigmoid->SetAlpha( alpha );
sigmoid->SetBeta( beta );


typedef FastMarchingFilterType::NodeContainer NodeContainer;
typedef FastMarchingFilterType::NodeType NodeType; 
NodeContainer::Pointer seeds = NodeContainer::New();
double initialDistance = 5.0;
double seedValue = -initialDistance;
NodeType node;
node.SetValue(seedValue);
node.SetIndex(index);
seeds->Initialize();
seeds->InsertElement(0,node);
fastMarching->SetTrialPoints(seeds);
fastMarching->SetSpeedConstant(1.0);
fastMarching->SetOutputSize([itkImage image]->GetBufferedRegion().GetSize());


CastFilterType::Pointer caster1 = CastFilterType::New();
CastFilterType::Pointer caster2 = CastFilterType::New();
CastFilterType::Pointer caster3 = CastFilterType::New();
CastFilterType::Pointer caster4 = CastFilterType::New();
CastFilterType::Pointer caster5 = CastFilterType::New();

WriterType::Pointer writer1 = WriterType::New();
WriterType::Pointer writer2 = WriterType::New();
WriterType::Pointer writer3 = WriterType::New();
WriterType::Pointer writer4 = WriterType::New();
WriterType::Pointer writer5 = WriterType::New();
WriterType::Pointer writerfinal = WriterType::New();

caster1->SetInput( smoothing->GetOutput() );
writer1->SetInput( caster1->GetOutput() );
char *name1 = "smoothed_dataset.gipl";
writer1->SetFileName(name1);
caster1->SetOutputMinimum( 0 );
caster1->SetOutputMaximum( 255 );
writer1->SetImageIO(giplIO);
try{
writer1->Update();
}
catch( itk::ExceptionObject & excep ){
NSLog(@ "Exception caught at writer1!.gipl");
}
caster2->SetInput( gradientMagnitude->GetOutput() );
writer2->SetInput( caster2->GetOutput() );
char *name2 = "3DKanten.gipl";
writer2->SetFileName(name2);
caster2->SetOutputMinimum( 0 );
caster2->SetOutputMaximum( 255 );
writer2->SetImageIO(giplIO);
try{
writer2->Update();
}
catch( itk::ExceptionObject & excep ){
NSLog(@"Exceptionin writer2.gipl");
}
caster3->SetInput( sigmoid->GetOutput() );
writer3->SetInput( caster3->GetOutput() );
char *name3 = "inverse3DKanten.gipl";
writer3->SetFileName(name3);
caster3->SetOutputMinimum( 0 );
caster3->SetOutputMaximum( 255 );
writer3->SetImageIO(giplIO);
try{
writer3->Update();
}
catch( itk::ExceptionObject & excep ){
NSLog(@"Exception caught at writer3 !.gipl");
}
caster4->SetInput( fastMarching->GetOutput() );
writer4->SetInput( caster4->GetOutput() );
char *name4 = "FFM.gipl";
writer4->SetFileName(name4);
caster4->SetOutputMinimum( 0 );
caster4->SetOutputMaximum( 255 );
writer4->SetImageIO(giplIO);
try{
writer4->Update();
}
catch( itk::ExceptionObject & excep ){
NSLog(@"Exception caught at writer4!.gipl");
}
caster5->SetInput( geodesicActiveContour->GetOutput() );
writer5->SetInput( caster5->GetOutput() );
char *name5 = "ActiveContour.gipl";
writer5->SetFileName(name5);
caster5->SetOutputMinimum( 0 );
caster5->SetOutputMaximum( 255 );
writer5->SetImageIO(giplIO);
try{
writer5->Update();
}
catch( itk::ExceptionObject & excep ){
NSLog(@"Exception caught at writer45!.gipl");
}

NSLog(@"I am here already will go  further");

casterfinal->SetInput(thresholder->GetOutput());
writerfinal->SetInput(thresholder->GetOutput());
char *name6 = "Segmentation.gipl";
writerfinal->SetFileName(name6);
writerfinal->SetImageIO(giplIO);
try
{
casterfinal->Update();
writerfinal->Update();
}
catch( itk::ExceptionObject & excep )
{
NSLog(@"Exception caught at main writer!");
} 
//THIS CAUSES MY PLUGIN TO CRASH!!!!!!!

/*unsigned int nb_iteration = 10;
double rms = 0.02;
double epsilon = 1.5;
double curvature_weight = 1.;
double area_weight = 10000;
double volume_weight = 1.;
double volume = 1.;
double overlap_weight = 1.;
double l1 = 1.;
double l2 = 1.;

typedef itk::Image< unsigned char, Dimension > FeatureImageType;
typedef itk::ScalarChanAndVeseLevelSetFunctionData< InternalImageType,FeatureImageType > DataHelperType;
typedef itk::ConstrainedRegionBasedLevelSetFunctionSharedData<InternalImageType, FeatureImageType, DataHelperType > SharedDataHelperType;
typedef itk::ScalarChanAndVeseLevelSetFunction< InternalImageType,FeatureImageType, SharedDataHelperType > LevelSetFunctionType;
typedef itk::ScalarChanAndVeseSparseLevelSetImageFilter< InternalImageType,FeatureImageType, OutputImageType,LevelSetFunctionType,SharedDataHelperType > MultiLevelSetType;
typedef itk::AtanRegularizedHeavisideStepFunction<float,float >  DomainFunctionType;
DomainFunctionType::Pointer domainFunction = DomainFunctionType::New();
domainFunction->SetEpsilon( epsilon );*/


NSLog(@"I go on step and another ONEEEEEE");
unsigned char *buff = casterfinal->GetOutput()->GetBufferPointer();
if( buff)
{
.... i SHOW THE ROI IN OSIRIX
}



@end




-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20110225/0595d982/attachment.htm>


More information about the Insight-users mailing list