<table cellspacing="0" cellpadding="0" border="0" ><tr><td valign="top" style="font: inherit;"><br><br>--- Ella Maria Kadas <i><ella_kadas@yahoo.com></i> schrieb am <b>Fr, 11.2.2011:<br></b><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px;"><b><br>Von: Ella Maria Kadas <ella_kadas@yahoo.com><br>Betreff: Re: [Insight-users] Help with GeodesicActiveContourImageFilter --> Modification to example code does not seem to work<br>An: "Vimal Singh" <vimal@mail.utexas.edu><br>Datum: Freitag, 11. Februar, 2011 02:05 Uhr<br><br></b><div id="yiv578554426"><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td style="font: inherit;" valign="top">Hi,<br><br>I am trying to use this filter for a plugin n Osirix for lesion detection in MRT images.<br>ItkImageImporter is a itk wrap for the dicom images read with Osirix. <br>And the seed point in taken from a mouse klick in the viewer from
Osirix.<br>I already used the ConnectedThresholdFilter but i am not really satisfied with the results.<br>I also don;t really know how to retrieve from the writer the information to create Roi<br>For the Connected Threshold Filter i used<br><br><br> typedef float InternalPixelType;<br> typedef itk::Image< InternalPixelType, 3 > InternalImageType; <br> // Char Output image<br> typedef unsigned char OutputPixelType;<br> typedef itk::Image< OutputPixelType, 3 > OutputImageType;<br> // Type
Caster<br> typedef itk::CastImageFilter< InternalImageType, OutputImageType > CastingFilterType;<br> CastingFilterType::Pointer caster = CastingFilterType::New();<br>//.....<br> caster->SetInput(thresholdFilter->GetOutput()); // <- FLOAT TO CHAR<br>NSLog(@"RegionGrowing starts...");<br> <br> try<br> {<br> caster->Update();<br> }<br> catch( itk::ExceptionObject & excep )<br> {<br> NSLog(@"RegionGrowing failed...");<br> }<br> <br> NSLog(@"Done...");<br>//...<br>unsigned char *buff = caster->GetOutput()->GetBufferPointer();<br>ROI *theNewROI = [[ROI alloc] initWithTexture:buff<br>
textWidth:buffWidth<br> textHeight:buffHeight<br> textName:newname<br>
positionX:0<br> positionY:0<br> spacingX:[[[srcViewer imageView] curDCM] pixelSpacingX]<br>
spacingY:[[[srcViewer imageView] curDCM] pixelSpacingY]<br> imageOrigin:NSMakePoint([[[srcViewer imageView] curDCM] originX], [[[srcViewer imageView] curDCM] originY])];<br><br><br><br>The code is for GeodesicActiveContours is :<br><br><br><br>@implementation ActiveContours<br><br>- (id) initWith :(ViewerController*) v :(int) slice {<br> if (self = [super init])<br> {<br> <br> itkImage = [[Importer alloc]Create:[v pixList] slice:slice volume:[v volumePtr]];<br> }<br>
return self;<br>}<br><br>-(void) dealloc<br>{<br> [itkImage release];<br> <br> [super dealloc];<br>}<br><br>- (void) ActiveContour3D:(ViewerController *)sourceV :(int)slice :(NSPoint)startingPoint :(NSString*)newname<br>{<br> <br> <br><br><br> <br> typedef float InternalPixelType;<br> const unsigned int Dimension = 3; <br> typedef itk::Image< InternalPixelType, Dimension > InternalImageType;<br> typedef itk::OrientedImage< PixelType, Dimension > ImageType;<br> typedef itk::ImageSeriesReader< ImageType > ReaderType;<br> ReaderType::Pointer reader = ReaderType::New();<br> typedef itk::GDCMImageIO ImageIOType;<br>
ImageIOType::Pointer dicomIO = ImageIOType::New();<br> <br> reader->SetImageIO( dicomIO );<br> <br> <br> <br> typedef unsigned char OutputPixelType;<br> typedef itk::Image< OutputPixelType, Dimension > OutputImageType;<br> <br> typedef itk::BinaryThresholdImageFilter<<br> InternalImageType,<br> OutputImageType > ThresholdingFilterType;<br> <br> ThresholdingFilterType::Pointer thresholder = ThresholdingFilterType::New();<br> //I supose here is the problem in settin the lower and Upper threshold for thresholder. the timestep=upperThreshold<br> //in the userGuide should come from the fastmarching Filter??????<br> thresholder->SetLowerThreshold( -1000.0
);<br> thresholder->SetUpperThreshold( 0.0 );<br> <br> thresholder->SetOutsideValue( 0 );<br> thresholder->SetInsideValue( 255 );<br> <br> //typedef itk::ImageFileReader< InternalImageType > ReaderType;<br> typedef itk::GDCMImageIO ImageIOType;<br> ImageIOType::Pointer gdcmImageIO = ImageIOType::New();<br> typedef itk::VTKImageIO VTKIOType;<br> VTKIOType::Pointer vtkIO = VTKIOType::New();<br> typedef itk::GiplImageIO GiplIOType;<br> GiplIOType::Pointer giplIO = GiplIOType::New(); <br> <br> typedef itk::ImageFileWriter< OutputImageType > WriterType; <br> WriterType::Pointer writer = WriterType::New();<br> char *name =
"volume_dataset";<br> writer->SetFileName(name);<br> writer->SetImageIO(gdcmImageIO);<br> typedef itk::RescaleIntensityImageFilter<InternalImageType,OutputImageType > CastFilterType;<br> typedef itk::CurvatureAnisotropicDiffusionImageFilter<InternalImageType,InternalImageType > SmoothingFilterType;<br> SmoothingFilterType::Pointer smoothing = SmoothingFilterType::New(); <br> typedef itk::GradientMagnitudeRecursiveGaussianImageFilter<InternalImageType,InternalImageType > GradientFilterType;<br> typedef itk::SigmoidImageFilter<InternalImageType,InternalImageType > SigmoidFilterType;<br> GradientFilterType::Pointer gradientMagnitude = GradientFilterType::New();<br> <br> SigmoidFilterType::Pointer sigmoid =
SigmoidFilterType::New();<br> <br> sigmoid->SetOutputMinimum( 0.0 );<br> sigmoid->SetOutputMaximum( 1.0 );<br> <br> typedef itk::FastMarchingImageFilter<InternalImageType,InternalImageType > FastMarchingFilterType;<br> FastMarchingFilterType::Pointer fastMarching = FastMarchingFilterType::New();<br> <br> typedef itk::GeodesicActiveContourLevelSetImageFilter< InternalImageType,InternalImageType > GeodesicActiveContourFilterType;<br> GeodesicActiveContourFilterType::Pointer geodesicActiveContour = GeodesicActiveContourFilterType::New();<br> <br> const double propagationScaling = 3.0;<br> <br> geodesicActiveContour->SetPropagationScaling(propagationScaling);<br>
geodesicActiveContour->SetCurvatureScaling(2.0);<br> geodesicActiveContour->SetAdvectionScaling( 3.0 );<br> geodesicActiveContour->SetMaximumRMSError( 0.02 );<br> geodesicActiveContour->SetNumberOfIterations( 3 );<br> <br> smoothing->SetInput([itkImage itkImporter]->GetOutput() );<br> gradientMagnitude->SetInput( smoothing->GetOutput() );<br> sigmoid->SetInput( gradientMagnitude->GetOutput() );<br> <br> geodesicActiveContour->SetInput( fastMarching->GetOutput() );<br> geodesicActiveContour->SetFeatureImage( sigmoid->GetOutput() );<br> <br> thresholder->SetInput( geodesicActiveContour->GetOutput() );<br> writer->SetInput( thresholder->GetOutput() );<br>
<br> smoothing->SetTimeStep( 0.0625 );<br> smoothing->SetNumberOfIterations( 10 );<br> smoothing->SetConductanceParameter( 1.0 );<br> <br> const double sigma = 1.0;<br> gradientMagnitude->SetSigma( sigma );<br> <br> const double alpha = -4.0;<br> const double beta = 0.0;<br> <br> sigmoid->SetAlpha( alpha );<br> sigmoid->SetBeta( beta );<br> <br> typedef FastMarchingFilterType::NodeContainer NodeContainer;<br> typedef FastMarchingFilterType::NodeType NodeType; <br> <br> InternalImageType::IndexType index;<br> index[0] = (long) startingPoint.x;<br> index[1] = (long)
startingPoint.y;<br> <br> <br> if(slice == -1) index[2] = [[sourceV imageView] curImage];<br> else index[2] = 0;<br> <br> NSLog(@"StartingPoint is %d %d %d", index[0],index[1],index[2]);<br> <br> NodeContainer::Pointer seeds = NodeContainer::New();<br> double initialDistance = 5.0;<br> double seedValue = -initialDistance;<br> NodeType node;<br> node.SetValue(seedValue);<br> node.SetIndex(index);<br> seeds->Initialize();<br> seeds->InsertElement(0,node);<br> fastMarching->SetTrialPoints(seeds);<br> fastMarching->SetSpeedConstant(1.0);<br> const double stoppingTime = 10.0;<br>
fastMarching->SetStoppingValue( stoppingTime );<br> <br> <br> <br> CastFilterType::Pointer caster1 = CastFilterType::New();<br> CastFilterType::Pointer caster2 = CastFilterType::New();<br> CastFilterType::Pointer caster3 = CastFilterType::New();<br> CastFilterType::Pointer caster4 = CastFilterType::New();<br> <br> WriterType::Pointer writer1 = WriterType::New();<br> WriterType::Pointer writer2 = WriterType::New();<br> WriterType::Pointer writer3 = WriterType::New();<br> WriterType::Pointer writer4 = WriterType::New();<br> <br> caster1->SetInput( smoothing->GetOutput() );<br> writer1->SetInput( caster1->GetOutput() );<br> char *name1 =
"smoothed_dataset";<br> writer1->SetFileName(name1);<br> caster1->SetOutputMinimum( 0 );<br> caster1->SetOutputMaximum( 255 );<br> writer1->SetImageIO(giplIO);<br> try{<br> writer1->Update();<br> }<br> catch( itk::ExceptionObject & excep ){<br> NSLog(@ "Exception caught at writer1!");<br> <br> }<br> <br> caster2->SetInput( gradientMagnitude->GetOutput() );<br> writer2->SetInput( caster2->GetOutput() );<br> char *name2 = "3DKanten";<br> writer2->SetFileName(name2);<br> caster2->SetOutputMinimum( 0 );<br> caster2->SetOutputMaximum( 255
);<br> writer2->SetImageIO(giplIO);<br> try{<br> writer2->Update();<br> }<br> catch( itk::ExceptionObject & excep ){<br> NSLog(@"Exceptionin writer2");<br> }<br> <br> caster3->SetInput( sigmoid->GetOutput() );<br> writer3->SetInput( caster3->GetOutput() );<br> char *name3 = "inverse3DKanten";<br> writer3->SetFileName(name3);<br> caster3->SetOutputMinimum( 0 );<br> caster3->SetOutputMaximum( 255 );<br> writer3->SetImageIO(giplIO);<br> try{<br> writer3->Update();<br> }<br> catch( itk::ExceptionObject & excep
){<br> NSLog(@"Exception caught at writer3 !");<br> <br> }<br> <br> caster4->SetInput( fastMarching->GetOutput() );<br> writer4->SetInput( caster4->GetOutput() );<br> char *name4 = "FFM";<br> writer4->SetFileName(name4);<br> caster4->SetOutputMinimum( 0 );<br> caster4->SetOutputMaximum( 255 );<br> <br> writer4->SetImageIO(giplIO);<br> try{<br> writer4->Update();<br> NSLog(@"FMIF: GetOutputSize: ");<br> }<br> catch( itk::ExceptionObject & excep ){<br> NSLog(@"Exception caught at
writer4!");<br> }<br> NSLog(@"I am here already will go further");<br><br> try<br> {<br> writer->Update();<br> }<br> catch( itk::ExceptionObject & excep )<br> {<br> NSLog(@"Exception caught at main writer!");<br> } <br> <br> <br> NSLog(@"DOOOOOONNNNNNEEEEEE");<br><br> <br> <br> <br> <br> <br> <br> <br> <br>/* if( slice == -1)<br> { <br> unsigned char *buff =
writer->GetOutput()->GetBufferPointer();<br> <br> if( buff)<br> {<br> for( int i = 0; i < [[sourceV pixList] count]; i++)<br> {<br> int buffHeight = [[[sourceV pixList] objectAtIndex: i] pheight];<br> int buffWidth = [[[sourceV pixList] objectAtIndex: i] pwidth];<br> <br> if( memchr( buff, 255, buffWidth * buffHeight))<br> {<br>
ROI *theNewROI = [[ROI alloc] initWithTexture:buff<br> textWidth:buffWidth<br> textHeight:buffHeight<br>
textName:newname<br> positionX:0<br> positionY:0<br> spacingX:[[[sourceV imageView] curDCM]
pixelSpacingX]<br> spacingY:[[[sourceV imageView] curDCM] pixelSpacingY]<br> imageOrigin:NSMakePoint([[[sourceV imageView] curDCM] originX], [[[sourceV imageView] curDCM] originY])];<br> NSLog(@"I am working wiht a ROI");<br> [[[sourceV roiList]
objectAtIndex:i] addObject:theNewROI];<br> [[NSNotificationCenter defaultCenter] postNotificationName: OsirixROIChangeNotification object:theNewROI userInfo: nil]; <br> <br> /*if( [newname isEqualToString: @"Segmentation Preview"])<br> {<br> RGBColor color;<br> <br>
color.red = 0.67*65535.;<br> color.green = 0.90*65535.;<br> color.blue = 0.58*65535.;<br> NSLog(@"I am preview in a slice -1");<br> <br> [theNewROI setColor: color];<br> }<br>
else {*/<br> /* RGBColor roiColor;<br> roiColor.red = 0.20 * 65535;<br> roiColor.blue = 0.50 * 65535;<br> roiColor.green = 0.50 * 65535;<br> [theNewROI setColor: roiColor];<br> <br>
//}<br> <br> [theNewROI setROIMode: ROI_selected];<br> [[NSNotificationCenter defaultCenter] postNotificationName: OsirixROISelectedNotification object:theNewROI userInfo: nil];<br> <br> [theNewROI setSliceThickness:[[[sourceV imageView] curDCM] sliceThickness]];<br> [theNewROI release];<br> }<br>
<br> buff+= buffHeight*buffWidth;<br> }<br> <br> }<br> <br> }<br> else<br> {<br> // result of the segmentation will only contain one slice.<br> NSLog(@"Result conteins only one slide");<br> unsigned char *buff = caster->GetOutput()->GetBufferPointer();<br> //NSLog(@"buff ISSSSS %c",buff);<br> if(buff) NSLog(@"The buffer is not nill");<br> int buffHeight =
[[[sourceV pixList] objectAtIndex: 0] pheight];<br> int buffWidth = [[[sourceV pixList] objectAtIndex: 0] pwidth];<br> <br> ROI *theNewROI = [[ROI alloc] initWithTexture:buff<br> textWidth:buffWidth<br> textHeight:buffHeight<br>
textName:newname<br> positionX:0<br> positionY:0<br> spacingX:[[[sourceV imageView] curDCM] pixelSpacingX]<br>
spacingY:[[[sourceV imageView] curDCM] pixelSpacingY]<br> imageOrigin:NSMakePoint([[[sourceV imageView] curDCM] originX], [[[sourceV imageView] curDCM] originY])];<br> [theNewROI reduceTextureIfPossible];<br> [theNewROI setSliceThickness:[[[sourceV imageView] curDCM] sliceThickness]];<br> [[[sourceV roiList] objectAtIndex:slice] addObject:theNewROI];<br> [[sourceV imageView] roiSet];<br> [[NSNotificationCenter defaultCenter] postNotificationName: OsirixROIChangeNotification object:theNewROI userInfo: nil];<br>
<br> /*if( [newname isEqualToString: @"Segmentation Preview"])<br> {<br> NSLog(@"I am actually in a preview");<br> RGBColor color;<br> <br> color.red = 0.67*65535.;<br> color.green = 0.90*65535.;<br> color.blue = 0.58*65535.;<br> <br> [theNewROI setColor: color];<br> }*/<br> //else{<br> /*RGBColor roiColor;<br>
roiColor.red = 0.20 * 65535;<br> roiColor.blue = 0.50 * 65535;<br> roiColor.green = 0.50 * 65535;<br> [theNewROI setColor: roiColor];<br> //}<br> [theNewROI setROIMode: ROI_selected];<br> [[NSNotificationCenter defaultCenter] postNotificationName: OsirixROISelectedNotification object:theNewROI userInfo: nil];<br> <br> [theNewROI release];<br> }<br> [sourceV needsDisplayUpdate];*/ <br> <br>}<br><br>@end<br><br>Thanks,<br>Ella<br><br></td></tr></tbody></table><b><br></b></div></blockquote></td></tr></table><br>