我正在尝试实施Cohen-Daubechies-Feauveau-Wavelet 5/3高通和低通。
我现在正在坚持。我的输出图像始终为白色,因为在计算过程中所有值都变为255。很难找到这种小波的任何例子。有没有人在我的计算中看到我无法找到的错误。
static double[] lowpass = {1/8d, 2/8d, 6/8d, 2/8d, -1/8};
static double[] highpass = {1/2d, 1d, -1/2d };
public static void lowPassFilter(Bitmap img)
{
int index = 0;
double R = 0.0, G = 0.0, B = 0.0;
Bitmap filteredImg = img;
// Iterate over each pixel
for (int x = 0; x < filteredImg.Width; x++)
{
for (int y = 0; y < filteredImg.Height; y++)
{
// Apply filter in x direction
for (int i = 0; i < lowpass.Length; i++)
{
index = Math.Min(Math.Max(x - (lowpass.Length / 2) + i, 0), filteredImg.Width - 1);
R += img.GetPixel(index, y).R * lowpass[i];
G += img.GetPixel(index, y).G * lowpass[i];
B += img.GetPixel(index, y).B * lowpass[i];
}
R = Math.Min(Math.Max(R, 0), 255);
G = Math.Min(Math.Max(G, 0), 255);
B = Math.Min(Math.Max(B, 0), 255);
filteredImg.SetPixel(x, y, Color.FromArgb((int)R, (int)G, (int)B));
}
}