영상처리

AutoThreshold (Mean) C++

park__ 2024. 12. 11. 10:42

Java -> C++

 

Code

int Mean(float* histo, int n_length) 
{
	// C. A. Glasbey, "An analysis of histogram-based thresholding algorithms,"
	// CVGIP: Graphical Models and Image Processing, vol. 55, pp. 532-537, 1993.
	//
	// The threshold is the mean of the greyscale data
	int threshold = -1;
	long tot = 0, sum = 0;
	
	for (int i = 0; i < n_length; i++) 
	{
		tot += histo[i];
		sum += ((long)i * (long)histo[i]);
	}

	threshold = (int)floor(sum / tot);

	return threshold;
}

 

imageJ 관련 문서 : https://imagej.net/plugins/auto-threshold

github link : https://github.com/fiji/Auto_Threshold/blob/master/src/main/java/fiji/threshold/Auto_Threshold.java