[Insight-users] Help with otsumultiplethresholdfilter

barbababa tonimuusimaki at gmail.com
Thu Jun 30 14:50:17 EDT 2011


Hello all!

Help needed! Why do i get an image with a value -4.316e8 everywhere?
It won't change no matter what i do! I am trying to make an image, with
different
values for  different thresholds. For example if the threshold is 5, then
all pixels in the
segmentated image below 5 is 1 and all above 5 is 2.

thanks,
toni



	typedef itk::Image<float, 2> ImageType;
		ImageType::Pointer sumimage = ImageType::New();
                ImageType::Pointer sumimage1 = ImageType::New();
		ImageType::SizeType size;

//THIS WORKS
		size[0]  = src_img_in.GetDimensionSize( 0 );
		size[1]  = src_img_in.GetDimensionSize( 1 );
//
		ImageType::IndexType start;
		start.Fill(0);

		ImageType::RegionType region;
		region.SetIndex( start );
		region.SetSize( size );
  
		sumimage->SetLargestPossibleRegion( region );
		sumimage->SetBufferedRegion( region );
		sumimage->SetRequestedRegion( region );
		sumimage->Allocate();

  
		sumimage1->SetLargestPossibleRegion( region );
		sumimage1->SetBufferedRegion( region );
		sumimage1->SetRequestedRegion( region );
		sumimage1->Allocate();
		typedef itk::Statistics::ScalarImageToHistogramGenerator<ImageType >
ScalarImageToHistogramGeneratorType; 
		typedef
itk::OtsuMultipleThresholdsCalculator<ScalarImageToHistogramGeneratorType::HistogramType
> CalculatorType;
		typedef itk::BinaryThresholdImageFilter< ImageType, ImageType >
FilterType;
		typedef itk::AddImageFilter< ImageType, ImageType ,ImageType>
AddFilterType;

		ScalarImageToHistogramGeneratorType::Pointer
scalarImageToHistogramGenerator =
ScalarImageToHistogramGeneratorType::New();
		CalculatorType::Pointer calculator = CalculatorType::New();
		FilterType::Pointer filter = FilterType::New();
		AddFilterType::Pointer addFilter = AddFilterType::New();

		scalarImageToHistogramGenerator->SetNumberOfBins(n_bins);
		calculator->SetNumberOfThresholds(n_trsh);
//THIS WORKS
		if(flag) scalarImageToHistogramGenerator->SetInput(dmtoitk2(src_img_in));
		else scalarImageToHistogramGenerator->SetInput(dmtoitk2(src_img));
	//
	
calculator->SetInputHistogram(scalarImageToHistogramGenerator->GetOutput());
		filter->SetInput(dmtoitk2(src_img_in) );

		scalarImageToHistogramGenerator->Compute();
		calculator->Update();

		const CalculatorType::OutputType &thresholdVector =
calculator->GetOutput();
		CalculatorType::OutputType::const_iterator itNum =
thresholdVector.begin();
		
//THIS WORKS
		DM::ImageCalculateMinMax( src_img_in,1, 1, &min, &max );
//
		const float outsideValue = 0;
		

		float lowerThreshold = min;
		float upperThreshold;

		filter->SetOutsideValue( outsideValue );

		for(; itNum < thresholdVector.end(); itNum++)
		{

		const float insideValue = count;
		filter->SetInsideValue( insideValue );

	    upperThreshold = static_cast<float>(*itNum);

		filter->SetLowerThreshold( lowerThreshold );
		filter->SetUpperThreshold( upperThreshold );
		filter->Update();

		lowerThreshold = upperThreshold;

		addFilter->SetInput1( filter->GetOutput() );
		addFilter->SetInput2(  sumimage );
		//sumimage = addFilter->GetOutput( );
		addFilter->Update();
		sumimage1 = addFilter->GetOutput() ;
		sumimage = sumimage1;

		count++;
		}
		const float insideValue = count;

	
		filter->SetInsideValue( count  );
		filter->SetLowerThreshold( lowerThreshold );
		filter->SetUpperThreshold( max );
		filter->Update();


		addFilter->SetInput1( filter->GetOutput() );
		addFilter->SetInput2(  sumimage );
		//sumimage = addFilter->GetOutput( );
		addFilter->Update();
		sumimage1 = addFilter->GetOutput() ;
	//THIS WORKS	
		l_deriv_img_out = itktodm2( sumimage1);
		l_deriv_img_out.SetName(( std::string("Segmentated ") + name ).c_str());

--
View this message in context: http://itk-insight-users.2283740.n2.nabble.com/Help-with-otsumultiplethresholdfilter-tp6534491p6534491.html
Sent from the ITK Insight Users mailing list archive at Nabble.com.


More information about the Insight-users mailing list