49
F.9. CODE LISTINGS FOR CHAPTER 9
495
/************************************************
*
*
peak_threshold_segmentation(...
*
*
This function segments an image using
*
thresholding. It uses the histogram peaks
*
to find the hi and low values of the
*
threshold.
*
*
If the segment parameter is 0, you only
*
threshold the array - you do not segment.
*
*************************************************/
peak_threshold_segmentation(the_image, out_image,
value, segment,
rows, cols)
int
rows, cols, segment;
short **the_image, **out_image, value;
{
int
peak1, peak2;
short
hi, low;
unsigned long histogram[GRAY_LEVELS+1];
zero_histogram(histogram, GRAY_LEVELS+1);
calculate_histogram(the_image, histogram,
rows, cols);
smooth_histogram(histogram, GRAY_LEVELS+1);
find_peaks(histogram, &peak1, &peak2);
peaks_high_low(histogram, peak1, peak2,
&hi, &low);
threshold_image_array(the_image,
out_image,
hi, low, value,
rows, cols);
if(segment == 1)
grow(out_image, value, rows, cols);
} /* ends peak_threshold_segmentation */
/********************************************