本文整理汇总了C#中Filter.SampleBox方法的典型用法代码示例。如果您正苦于以下问题:C# Filter.SampleBox方法的具体用法?C# Filter.SampleBox怎么用?C# Filter.SampleBox使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Filter
的用法示例。
在下文中一共展示了Filter.SampleBox方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PolyphaseKernel
/// <summary>
/// Initializes a new instance of the <see cref="PolyphaseKernel"/> class.
/// </summary>
/// <param name="filter">The filter function.</param>
/// <param name="srcLength">The length of the input image.</param>
/// <param name="dstLength">The length of the output image.</param>
/// <param name="numberOfSamples">The number of samples.</param>
/// <exception cref="ArgumentNullException">
/// <paramref name="filter"/> is <see langword="null"/>.
/// </exception>
/// <exception cref="ArgumentOutOfRangeException">
/// <paramref name="srcLength"/>, <paramref name="dstLength"/>, or
/// <paramref name="numberOfSamples"/> is invalid.
/// </exception>
public PolyphaseKernel(Filter filter, int srcLength, int dstLength, int numberOfSamples = 32)
{
if (filter == null)
throw new ArgumentNullException("filter");
if (srcLength <= 0)
throw new ArgumentOutOfRangeException("srcLength");
if (dstLength <= 0)
throw new ArgumentOutOfRangeException("dstLength");
if (numberOfSamples <= 0)
throw new ArgumentOutOfRangeException("numberOfSamples");
// scale < 1 ... Downsampling
// scale > 1 ... Upsampling
float scale = (float)dstLength / srcLength;
float inverseScale = 1.0f / scale;
if (scale > 1)
{
// Upsampling
numberOfSamples = 1;
scale = 1;
}
// filter.Width ... filter width in output image.
// Width ... filter width in input image.
Width = filter.Width * inverseScale;
int windowSize = (int)Math.Ceiling(Width * 2) + 1;
// Each pixel in the output image uses its own set of filter weights.
Weights = new float[dstLength, windowSize];
for (int i = 0; i < dstLength; i++)
{
// i ... pixel index in output image.
// i + 0.5 ... kernel center in output image.
// (i + 0.5f) * inverseScale ... kernel center in input image.
float center = (i + 0.5f) * inverseScale;
// Kernel range in input image.
int left = (int)Math.Floor(center - Width);
int right = (int)Math.Ceiling(center + Width);
Debug.Assert(right - left <= windowSize);
// Calculate filter weights for pixel i in output image.
float total = 0.0f;
for (int j = 0; j < windowSize; j++)
{
float sample = filter.SampleBox(left + j - center, scale, numberOfSamples);
Weights[i, j] = sample;
total += sample;
}
// Normalize weights.
float inverseTotal = 1.0f / total;
for (int j = 0; j < windowSize; j++)
Weights[i, j] *= inverseTotal;
}
}