批量修剪噪声图像

时间:2017-04-12 17:35:31

标签: imagemagick

我有一大堆人们创造的图画嘈杂图像。我希望有一些功能可以将它们修剪为仅绘图。

以下是一些例子:

banana cherry

由于噪音-trim不起作用

我也尝试使用此处链接的示例(www.imagemagick.org/Usage/crop/#trim_blur),但由于图像内部和图像之间的噪声级别不同而无效。

最后,我尝试增加对比度以增加识别实际绘图线条的可能性,但由于上述类似的原因(不同的噪声级别),它只会锐化每个图像的部分线条。 / p>

如果有人有任何想法,我很乐意听到他们的声音!

1 个答案:

答案 0 :(得分:0)

不确定这是否适用于所有图片,因为它们存在很多问题:

  • 边缘的人工制品
  • 不均匀照明或阴影
  • 噪声
  • 低对比度

但你应该对解决一些问题有所了解。

为了摆脱边缘周围的人工制品,你可以将图像的范围减少2.5% - 基本上是一个居中的作物,如下所示:

convert noisy1.jpg -gravity center -extent 95x95% trimmed.png

enter image description here

要查看阴影/不均匀照明,我会将图像标准化为一系列纯黑色到纯白色,您将看到左下角的阴影:

convert noisy1.jpg -normalize result.png

enter image description here

要删除它,我会克隆你的图像并计算较大区域的低频平均值,然后减去它,以便删除缓慢变化的东西:

convert noisy1.jpg \( +clone -statistic mean 25x25 \) -compose difference -composite -negate result.png

这给了这个,然后你可以尝试自己标准化,看看阴影消失了:

enter image description here

如果我现在应用Canny Edge Detection,我会得到:

convert noisy1.jpg \( +clone -statistic mean 25x25 \) -compose difference -composite -normalize -negate -canny 0x1+10%+30%  result.png

enter image description here

这是一个非常粗糙,但希望有效的小脚本来完成这一切。它不会检查参数。保存为$HOME/cropper

#!/bin/bash
src=$1
dst=cropped-$1
tmp="tmp-$$.mpc"
trimbox=$(convert "$1" -extent 95x95% -write "$tmp" \( +clone -statistic mean 25x25 \) -compose difference -composite -normalize -negate -canny 0x1+10%+30%  -format %@ info:)

convert "$tmp" -crop $trimbox "$dst"
rm tmp-$$.*

使用以下命令使脚本可执行:

chmod +x $HOME/cropper

使用这样的单个图像运行:

cd /path/to/some/images
$HOME/cropper OneImage.jpg

如果您有数百张图片,我会先备份,然后与 GNU Parallel

并行完成
parallel $HOME/cropper {} ::: *.jpg
相关问题