Calculate probability density.
*/
for (i=0; i <= (ssize_t) MaxIntensity; i++)
- probability[i]=histogram[i]/(double) (image->columns*image->rows);
+ probability[i]=histogram[i];
/*
Generate probability of graylevels and mean value for separation.
*/
property[MagickPathExtent];
double
+ gamma,
*histogram,
+ sum,
threshold;
MagickBooleanType
status;
+ register ssize_t
+ i;
+
ssize_t
y;
}
}
image_view=DestroyCacheView(image_view);
+ /*
+ Normalize histogram.
+ */
+ sum=0.0;
+ for (i=0; i <= (ssize_t) MaxIntensity; i++)
+ sum+=histogram[i];
+ gamma=PerceptibleReciprocal(sum);
+ for (i=0; i <= (ssize_t) MaxIntensity; i++)
+ histogram[i]=gamma*histogram[i];
+ /*
+ Discover threshold from histogram.
+ */
switch (method)
{
case KapurThresholdMethod:
status=MagickFalse;
if (status == MagickFalse)
return(MagickFalse);
+ /*
+ Threshold image.
+ */
(void) FormatLocaleString(property,MagickPathExtent,"%g%%",threshold);
(void) SetImageProperty(image,"auto-threshold:threshold",property,exception);
return(BilevelImage(image,QuantumRange*threshold/100.0,exception));