Browse Source

Use tensor division for Gaussian kernels

pull/3161/head
James Jackson-South 3 weeks ago
parent
commit
41f17ba6b5
  1. 14
      src/ImageSharp/Processing/Processors/Convolution/ConvolutionProcessorHelpers.cs

14
src/ImageSharp/Processing/Processors/Convolution/ConvolutionProcessorHelpers.cs

@ -37,11 +37,8 @@ internal static class ConvolutionProcessorHelpers
kernel[i] = gx; kernel[i] = gx;
} }
// Normalize kernel so that the sum of all weights equals 1 // Divide every weight by the accumulated Gaussian sum so the kernel has unit response.
for (int i = 0; i < size; i++) TensorPrimitives_.Divide<float>(kernel, sum, kernel);
{
kernel[i] /= sum;
}
return kernel; return kernel;
} }
@ -76,11 +73,8 @@ internal static class ConvolutionProcessorHelpers
// center while adding twice the Gaussian sum so the complete kernel retains unit response. // center while adding twice the Gaussian sum so the complete kernel retains unit response.
kernel[midpointRounded] = (2F * sum) - midpointValue; kernel[midpointRounded] = (2F * sum) - midpointValue;
// Normalize kernel so that the sum of all weights equals 1 // Sharpening changes signs but preserves the Gaussian sum, so the same divisor produces unit response.
for (int i = 0; i < size; i++) TensorPrimitives_.Divide<float>(kernel, sum, kernel);
{
kernel[i] /= sum;
}
return kernel; return kernel;
} }

Loading…
Cancel
Save