gpt4 book ai didi

image-processing - 反向(移除)抗混叠滤波器

转载 作者:行者123 更新时间:2023-12-04 08:29:18 29 4
gpt4 key购买 nike

我有一组抗锯齿灰度 PNG 图像。我需要知道如何以编程方式恢复抗锯齿效果并再次获得锐利的边缘。
我正在使用 GDI+,但我对代码不太感兴趣。我需要一个算法。
灰度图像(应该)只包含 6 种颜色(或不同深浅的灰色)。这样以后我就可以使用 Color-Lookup 过滤器为它们重新着色。但是,当保存图像时,Photoshop 会自动应用抗锯齿,因此边缘变得模糊(因为启用了双三次插值模式)。我需要恢复这种效果。
下面是一个例子:
enter image description here
这是 Photoshop 的截图
有人建议我应该应用锐化滤镜,所以我在photoshop上尝试了它。这是它的外观:
enter image description here
尽管外边缘很好,但 2 种不同颜色相遇的边缘会出现伪影。
编辑:
这就是我最终这样做的方式。这是非常即兴的,可能可以做得更好更快,但我找不到更好的解决方案。
这个想法是迭代每个像素,获取它的直接邻居并将其颜色与他们的颜色进行比较。如果它至少有 2 个相同颜色的像素作为后盾,它会检查相邻像素是否也有后盾。如果不是,它将用自己的像素替换相邻像素。
代码:

    private static void Resample(Bitmap bmp)
{
// First we look for the most prominent colors
// i.e. They make up at least 1% of the image
Hashtable stats = new Hashtable();

for (int x = 0; x < bmp.Width; x++)
{
for (int y = 0; y < bmp.Height; y++)
{
Color px = bmp.GetPixel(x, y);
if (px.A == 0)
continue;

Color pxS = Color.FromArgb(255, px);
if (stats.ContainsKey(pxS.ToArgb()))
stats[pxS.ToArgb()] = (int)stats[pxS.ToArgb()] + 1;
else
stats.Add(pxS.ToArgb(), 1);
}
}

float totalSize = bmp.Width*bmp.Height;
float minAccepted = 0.01f;
List<int> selectedColors = new List<int>();

// Make up a list with the selected colors
foreach (int key in stats.Keys)
{
int total = (int)stats[key];
if (((float)total / totalSize) > minAccepted)
selectedColors.Add(key);
}

// Keep growing the zones with the selected colors to cover the invalid colors created by the anti-aliasing
while (GrowSelected(bmp, selectedColors));
}

private static bool GrowSelected(Bitmap bmp, List<int> selectedColors)
{
bool flag = false;

for (int x = 0; x < bmp.Width; x++)
{
for (int y = 0; y < bmp.Height; y++)
{
Color px = bmp.GetPixel(x, y);
if (px.A == 0)
continue;

Color pxS = Color.FromArgb(255, px);

if (selectedColors.Contains(pxS.ToArgb()))
{
if (!isBackedByNeighbors(bmp, x, y))
continue;

List<Point> neighbors = GetNeighbors(bmp, x, y);
foreach(Point p in neighbors)
{
Color n = bmp.GetPixel(p.X, p.Y);
if (!isBackedByNeighbors(bmp, p.X, p.Y))
bmp.SetPixel(p.X, p.Y, Color.FromArgb(n.A, pxS));
}
}
else
{
flag = true;
}
}
}

return flag;
}

private static List<Point> GetNeighbors(Bitmap bmp, int x, int y)
{
List<Point> neighbors = new List<Point>();

for (int i = x - 1; i > 0 && i <= x + 1 && i < bmp.Width; i++)
for (int j = y - 1; j > 0 && j <= y + 1 && j < bmp.Height; j++)
neighbors.Add(new Point(i, j));
return neighbors;
}

private static bool isBackedByNeighbors(Bitmap bmp, int x, int y)
{
List<Point> neighbors = GetNeighbors(bmp, x, y);
Color px = bmp.GetPixel(x, y);
int similar = 0;
foreach (Point p in neighbors)
{
Color n = bmp.GetPixel(p.X, p.Y);
if (Color.FromArgb(255, px).ToArgb() == Color.FromArgb(255, n).ToArgb())
similar++;
}

return (similar > 2);
}
结果:
原图:
http://i.imgur.com/8foQwFe.png
去抗锯齿结果:
http://i.imgur.com/w6gELWJ.png

最佳答案

滤波器的反转过程称为反卷积(这是一般逆问题的一个特例)。
有两种类型的反卷积:

  • Non Blind Deconvolution - 在图像上的操作是已知的(例如应用的低通滤波器的系数是已知的)。
  • Blind Deconvolution - 在应用的滤波器未知的情况下,只假设一些关于它的假设(例如是 LPF 或空间不变等......)。

  • 这些通常是(其中任何一个)复杂的算法,需要时间(除非使用天真的“维纳滤波器”方法)。

    假设滤波器是某种 LPF,穷人的解决方案将是某种高通滤波器 (HPF)。
    其中任何一个都会给人一种“更清晰的图像”和“增强的边缘”的印象。
    这种类型的已知过滤器是 Unsharp Mask:
  • 在图像上应用 LPF(通常使用具有给定 STD 的高斯模糊)。我们称之为 lpfImage。
  • 计算差异图像:diffImage = originalImage - lpfImage。
  • “Unsharp Mask Image”由下式给出:usmImage = originalImage + (alpha * diffImage)
    哪里alpha是“锐化”级别的预定义比例因子。

  • 享受...

    关于image-processing - 反向(移除)抗混叠滤波器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24922839/

    29 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com