Skip to content

Instantly share code, notes, and snippets.

@Theverat
Created April 12, 2019 22:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Theverat/e5f82e70c07806316f4c84a916f7d021 to your computer and use it in GitHub Desktop.
Save Theverat/e5f82e70c07806316f4c84a916f7d021 to your computer and use it in GitHub Desktop.
float *luminance = new float[width * height];
float *blurredLuminance = new float[width * height];
float *tmpBuffer = new float[width * height];
for (int i = 0; i < pixelsCount; ++i) {
luminance[i] = Spectrum(img + i * 3).Y();
blurredLuminance[i] = luminance[i];
}
const float weight = 1.f;
GaussianBlur3x3FilterPlugin::ApplyBlurFilter<float>(width, height,
blurredLuminance, tmpBuffer, weight, 1.f, weight);
for (int i = 0; i < pixelsCount; ++i) {
// The heart of the algorithm
const float diff = fabsf(logf(blurredLuminance[i]) - logf(luminance[i]));
diffVector[i] = diff;
maxError = Max(maxError, diff);
if (diff > threshold) ++todoPixelsCount;
}
delete[] luminance;
delete[] blurredLuminance;
GaussianBlur3x3FilterPlugin::ApplyBlurFilter<float>(width, height,
&diffVector[0], tmpBuffer, weight, 1.f, weight);
delete[] tmpBuffer;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment