[ITK-users] How to get the image intensity with the highest frequency count from the histogram of a single-channel grayscale image

donelron donelron at web.de
Fri Jul 11 12:26:17 EDT 2014


Hi everybody,

I have a simple question with regard to histograms:

Consider the following lines of code that calculate the histogram of an ITK
grayscale image:
-------------------------------------------------------------------------------------------------
		const unsigned int MeasurementVectorSize = 1; // Grayscale
		const unsigned int binsPerDimension = 255;

		typedef itk::Statistics::ImageToHistogramFilter< GrayscaleImageType >
			ImageToHistogramFilterType;

		ImageToHistogramFilterType::HistogramType::MeasurementVectorType
			lowerBound(binsPerDimension);
		lowerBound.Fill(0);

		ImageToHistogramFilterType::HistogramType::MeasurementVectorType
			upperBound(binsPerDimension);
		upperBound.Fill(255) ;

		ImageToHistogramFilterType::HistogramType::SizeType
			size(MeasurementVectorSize);
		size.Fill(binsPerDimension);

		ImageToHistogramFilterType::Pointer imageToHistogramFilter =
			ImageToHistogramFilterType::New();
		imageToHistogramFilter->SetInput( pConnectedComponentFilter->GetOutput()
);
		imageToHistogramFilter->SetHistogramBinMinimum( lowerBound );
		imageToHistogramFilter->SetHistogramBinMaximum( upperBound );
		imageToHistogramFilter->SetHistogramSize( size );

		try
		{
			imageToHistogramFilter->Update();
		}
		catch( itk::ExceptionObject & error )
		{
			std::cerr << "Error: " << error << std::endl;
			system("pause");
		}


		ImageToHistogramFilterType::HistogramType* histogram =
			imageToHistogramFilter->GetOutput();

		std::cout << "Frequency = [ ";
		for(unsigned int i = 0; i < histogram->GetSize()[0]; ++i)
		{
			std::cout << histogram->GetFrequency(i);

			if( i != histogram->GetSize()[0] - 1 )
			{
				std::cout << "," << std::endl;
			}
		}

		std::cout << " ]" << std::endl;
-------------------------------------------------------------------------------------------------

Is there a way to get the intensity with the highest frequency count from
the histogram?
I am aware that this is probably included in the Doxygen documentation, but
since I am neither an experienced ITK user nor C++ programmer, I couldn't
figure it out from the documentation how to do it.
Also, none of the code snippets I found, could answer my question or give me
a hint.

So, if someone could please provide a short code snippet that solves my
problem, that would be really nice:)
Or else, all hints / clues are also very very welcome.
Thank you for your help in advance!!!



--
View this message in context: http://itk-users.7.n7.nabble.com/How-to-get-the-image-intensity-with-the-highest-frequency-count-from-the-histogram-of-a-single-channe-tp34222.html
Sent from the ITK - Users mailing list archive at Nabble.com.


More information about the Insight-users mailing list