图像增强解决方案

时间:2015-01-25 12:37:27

标签: image image-processing imagemagick imagemagick-convert

我有以下类型/质量的大量图像:

enter image description here

我想做的是:

  • 消除噪音(不影响图像的其余部分)
  • 增强线路工作

使用画笔/橡皮擦手动执行此操作不是一种选择,因为图像太多。 可以使用哪些操作/过滤器来增强这些图像?

1 个答案:

答案 0 :(得分:3)

最简单的方法是使用ImageMagick。由于您需要对大量图像应用操作,因此您可以编写脚本来执行此操作。

您可以开始使用以下适用于ImageMagick的convert命令的图像操作符

  • <强> -threshold
    此运算符将同时黑/白阈值应用于输入图像。

  • <强> -blur
    此运算符可降低输入图像的噪声和细节级别。

  • <强> -sharpen
    此运算符锐化输入图像。

  • <强> -black-threshold
    此操作符强制将所有像素 低于 的阈值设为黑色,同时使所有像素保持在阈值或高于阈值。

  • <强> -white-threshold
    此操作符强制将所有像素 高于 的阈值置为白色,同时使所有像素保持在阈值或高于阈值。

  • <强> -morphology
    此运算符可以使用各种'方法'修改图像。以下是方法dilateerode的示例(有超过24种不同的方法可用)。每种方法都可以应用不同的'内核'。以下是内核diamondkirsch的示例(有大约3个不同的内核可用)。

您可以在一个命令行中应用其中一个或其中几个的合适组合。玩一些变化,看看哪个最适合你。

'阈值'

以下是一些带有输出的命令示例:

convert                              \
  http://i.stack.imgur.com/15lOG.png \
 -threshold 50%                      \
  50pc-threshold.png

convert                              \
  http://i.stack.imgur.com/15lOG.png \
 -threshold 85%                      \
  85pc-threshold.png

第一个图像(左侧)显示第一个命令的输出。第二个图像是第二个命令的结果:

'门槛'加上'模糊'

为了减少锐利的黑/白边框,您可能希望“让眼睛更容易”并对输出应用一些额外的模糊效果:

convert                              \
  http://i.stack.imgur.com/15lOG.png \
 -threshold 85%                      \
 -blur 2x1                           \
  85pc-threshold+blur-2x1.png

'阈值'加上'模糊'加上'锐化'

输出请参见下一张图片(左侧)。模糊后,您可以应用另一轮(或两个)处理:再次锐化。这是一个命令:

convert                              \
  http://i.stack.imgur.com/15lOG.png \
 -threshold 85%                      \
 -blur 2x1                           \
 -sharpen 0x3                        \
 -sharpen 0x3                        \
  85pc-threshold+blur-2x1+sharpen-0x3+sharpen-0x3.png

相应的输出是最后一张图像(右侧)。

'white-threshold''black-threshold'

以下两个命令演示了-white-threshold 50%-black-threshold 50%的使用:

convert                              \
  http://i.stack.imgur.com/15lOG.png \
 -white-threshold 50%                \
  white-threshold-50pc.png

convert                              \
  http://i.stack.imgur.com/15lOG.png \
 -black-threshold 50%                \
  black-threshold-50pc.png

以下两张图片显示了生成的图像:

与上述相同,但具有不同的阈值:

convert                              \
  http://i.stack.imgur.com/15lOG.png \
 -white-threshold 85%                \
  white-threshold-85pc.png

convert                              \
  http://i.stack.imgur.com/15lOG.png \
 -black-threshold 85%                \
  black-threshold-85pc.png

'black-threshold'加上'black-threshold'

结合两个阈值操作:

convert                              \
  http://i.stack.imgur.com/15lOG.png \
 -black-threshold 85%                \
 -white-threshold 85%                \
  black-threshold-85pc+white-threshold-85pc.png


convert                              \
  http://i.stack.imgur.com/15lOG.png \
 -white-threshold 85%                \
 -black-threshold 85%                \
  white-threshold-85pc+black-threshold-85pc.png

如果你仔细观察,你会很容易看到最后两个示例命令的输出没有不同(它们也与第二个命令的输出相同)。

为了获得比上述命令更好的结果,您必须使用相应参数的一些变体(不要总是使用85% ...)。

使用-morphology

的其他'细化'

我们可以将一些'细化'应用于当前结果之一。我将从顶部选择第四个图像/命令:

convert                              \
  http://i.stack.imgur.com/15lOG.png \
 -threshold 85%                      \
 -blur 2x1                           \
 -sharpen 0x3                        \
 -sharpen 0x3                        \
 -morphology erode diamond           \
  85pc-threshold+blur-2x1+sharpen-0x3+sharpen-0x3+erode+diamond.png

添加的-morphology erode diamond使用'钻石'形'内核'来侵蚀白色区域 - 这意味着黑色线条会变粗。您可以在下面的第一张图片中看到这一点。但这不是我们想要的效果。这就是为什么我们在-negate之前应用-morphology操作,之后应用另一个-negate

convert                              \
  http://i.stack.imgur.com/15lOG.png \
 -threshold 85%                      \
 -blur 2x1                           \
 -sharpen 0x3                        \
 -sharpen 0x3                        \
 -negate                             \
 -morphology erode diamond           \
 -negate                             \
  85pc-threshold+blur-2x1+sharpen-0x3+sharpen-0x3+negate+erode+diamond.png

两个输出图像如下:

我们可以使用erode(扩展白色),而不是使用dilate(侵蚀白色):

convert                              \
  http://i.stack.imgur.com/15lOG.png \
 -threshold 85%                      \
 -blur 2x1                           \
 -sharpen 0x3                        \
 -sharpen 0x3                        \
 -morphology dilate diamond          \
  85pc-threshold+blur-2x1+sharpen-0x3+sharpen-0x3+dilate+diamond.png

要查看所有内置内核形状的列表,请运行convert -list kernel。我们可以尝试使用'kirsch'来代替菱形形态核:

convert                              \
  http://i.stack.imgur.com/15lOG.png \
 -threshold 85%                      \
 -blur 2x1                           \
 -sharpen 0x3                        \
 -sharpen 0x3                        \
 -morphology dilate kirsch           \
  85pc-threshold+blur-2x1+sharpen-0x3+sharpen-0x3+dilate+kirsch.png

要获得所有可用内核可以完成的所有内容,您可以尝试这样做:

for i in $(convert -list kernel); do    \
   convert                              \
     http://i.stack.imgur.com/15lOG.png  \
    -threshold 85%                       \
    -blur 2x1                            \
    -sharpen 0x3                         \
    -sharpen 0x3                         \
    -morphology dilate ${i}              \
     85pc-threshold+blur-2x1+sharpen-0x3+sharpen-0x3+dilate+${i}-kernel.png \
done

要详细了解各种-morphology操作,请参阅此处:ImageMagick Examples -- Morphology of Shapes。要获得完整的形态学内核列表,请运行convert -list morphology



ImageMagick中还有更多处理选项。你应该自己探索它们......从这里开始了解它们:

  1. <子> ImageMagick Command-Line Options
  2. <子> ImageMagick Usage Examples
  3. <子> ImageMagick Usage Examples -- Reference Index