public void AdaptiveThresholding() { Statistics statistics = new Statistics(this.Image); Configurator.Configurator configurator = new Configurator.Configurator(); int radius = configurator.GetIntProperty("photo_adaptivethresholdingradius"); if (radius == 0) { PlainThresholding(statistics); return; } int width = GetWidth(); int height = GetHeight(); float[,] source = BitmapToArray(Image, width, height); float[,] destination = BitmapToArray(Image, width, height); for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { int count = 0; var neighbourhood = 0.0f; for (int k = i - radius; k <= i + radius; k++) { for (int l = j - radius; l <= j + radius; l++) { if (k >= 0 && l >= 0 && k < width && l < height) { neighbourhood += source[k, l]; count++; } } } neighbourhood /= count; if (destination[i, j] < neighbourhood) { destination[i, j] = 0f; } else { destination[i, j] = 1f; } } } Image = ArrayToBitmap(destination, width, height); }
public ConfigurationController() { _config = Configurator.Configurator.Instanse; }