我应该使用哪些处理步骤来清洁线条图的照片? [英] What processing steps should I use to clean photos of line drawings?

查看:26
本文介绍了我应该使用哪些处理步骤来清洁线条图的照片?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通常使用 100% 对比度和一些亮度调整来调整截止点的方法通常可以很好地清理小型子电路或方程式的照片,以便在 E&R.SE 上发布,但有时并不是那么好,就像这张图片:

My usual method of 100% contrast and some brightness adjusting to tweak the cutoff point usually works reasonably well to clean up photos of small sub-circuits or equations for posting on E&R.SE, however sometimes it's not quite that great, like with this image:

除了对比(或代替)之外,我还可以使用哪些其他方法来提供更一致的输出?

What other methods besides contrast (or instead of) can I use to give me a more consistent output?

我期待一个相当笼统的答案,但我可能会使用 ImageMagick 和/或 PIL (Python) 在脚本中实现它(我可以将文件转储到其中)所以如果你有任何特定于它们的东西它会不客气.

I'm expecting a fairly general answer, but I'll probably implement it in a script (that I can just dump files into) using ImageMagick and/or PIL (Python) so if you have anything specific to them it would be welcome.

理想情况下,更好的源图像会很好,但我偶尔会在其他人的图像上使用它来添加一些润色.

Ideally a better source image would be nice, but I occasionally use this on other folk's images to add some polish.

推荐答案

第一步是均衡图像中的照度差异,同时考虑白平衡问题.这里的理论是有限区域内图像的最亮部分代表白色.通过预先对图像进行模糊处理,我们消除了图像中噪声的影响.

The first step is to equalize the illumination differences in the image while taking into account the white balance issues. The theory here is that the brightest part of the image within a limited area represents white. By blurring the image beforehand we eliminate the influence of noise in the image.

from PIL import Image
from PIL import ImageFilter
im = Image.open(r'c:	emp	emp.png')
white = im.filter(ImageFilter.BLUR).filter(ImageFilter.MaxFilter(15))

下一步是从 RGB 输入创建灰度图像.通过缩放到白点,我们可以纠正白平衡问题.通过取 R、G、B 的最大值,我们不再强调任何不是纯灰色的颜色,例如网格的蓝线.此处显示的第一行代码是一个虚拟代码,用于创建大小和格式正确的图像.

The next step is to create a grey-scale image from the RGB input. By scaling to the white point we correct for white balance issues. By taking the max of R,G,B we de-emphasize any color that isn't a pure grey such as the blue lines of the grid. The first line of code presented here is a dummy, to create an image of the correct size and format.

grey = im.convert('L')
width,height = im.size
impix = im.load()
whitepix = white.load()
greypix = grey.load()
for y in range(height):
    for x in range(width):
        greypix[x,y] = min(255, max(255 * impix[x,y][0] / whitepix[x,y][0], 255 * impix[x,y][1] / whitepix[x,y][1], 255 * impix[x,y][2] / whitepix[x,y][2]))

这些操作的结果是一个图像具有大部分一致的值,并且可以通过一个简单的阈值转换为黑白.

The result of these operations is an image that has mostly consistent values and can be converted to black and white via a simple threshold.

很高兴看到一些竞争.nikie 提出了一种非常相似的方法,使用减法而不是缩放来消除白电平的变化.我的方法会增加光线不足区域的对比度,而 nikie 的方法不会 - 您更喜欢哪种方法取决于您希望保留的光线不足区域的信息.

It's nice to see a little competition. nikie has proposed a very similar approach, using subtraction instead of scaling to remove the variations in the white level. My method increases the contrast in the regions with poor lighting, and nikie's method does not - which method you prefer will depend on whether there is information in the poorly lighted areas which you wish to retain.

我尝试重新创建这种方法的结果是:

My attempt to recreate this approach resulted in this:

for y in range(height):
    for x in range(width):
        greypix[x,y] = min(255, max(255 + impix[x,y][0] - whitepix[x,y][0], 255 + impix[x,y][1] - whitepix[x,y][1], 255 + impix[x,y][2] - whitepix[x,y][2]))

我正在研究多种技术的组合以提供更好的结果,但还没有完全准备好.

I'm working on a combination of techniques to deliver an even better result, but it's not quite ready yet.

这篇关于我应该使用哪些处理步骤来清洁线条图的照片?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆