0

Imagemagick在 Windows 10 的命令行 Ubuntu 终端上运行 - 使用 Windows 10 中的内置工具 - Ubuntu App。

我是一个完整的linux新手,但已经安装imagemagick在上述环境中。

我的任务 - 自动移除黑色(ish)边框并歪斜数千张扫描的 35 毫米幻灯片的图像。

我可以成功运行诸如

mogrify -fuzz 35% -deskew 80% -trim +repage *.tif

问题是:-

  • 边界没有清晰定义,也不是完全黑色,因此 -fuzz。有些图像在某个模糊处被过度修剪,而另一些则修剪得不够。

所以我想要做的是有两次通过,不同的模糊百分比,原因如下: -

  • 第一次通过,Fuzz% 低。许多图像根本不会被修剪,但我发现那些容易过度修剪的图像会以低 % 修剪 Ok
  • 由于所有图像都以相同的文件大小开始,因此修剪 Ok 的图像将具有较小的文件大小(注意这些是 tifs 而不是 jpgs)
  • 所以我需要做的是在更高的 fuzz% 下为第二遍设置文件大小条件,忽略低于某个值的文件大小并且不执行任何操作。

这样,几乎没有错误,所有图像都将被正确修剪。

所以问题 - 我如何调整命令行以进行 2 次传递并在第二次传递时忽略较小的文件大小?

我有一种可怕的感觉,答案将是一个脚本。我不知道如何构建或设置 Ubuntu 来运行它,所以如果是这样,请你也指点我帮忙!!

4

1 回答 1

1

在 ImageMagick 中,您可以执行以下操作:

获取输入文件大小

Use convert to deskew and trim. 

Then find the new file 

Then compare the new to the old to compute the percentdifference to some percent threshold

If the percent difference is less than some threshold, then the processing did not trim enough 

So reprocess with a higher fuzz value and write over the input; otherwise keep the first one only and do not write over the old one.


Unix 语法。

选择两个模糊值

选择百分比变化阈值

创建一个新的空目录来保存输出(结果)

cd
cd desktop/Originals
fuzz1=20
fuzz2=40
threshpct=10
list=`ls`
for img in $list; do
filesize=`convert -ping $img -precision 16 -format "%b" info: | sed 's/[B]*$//'`
echo "filesize=$filesize"
convert $img -background black -deskew 40% -fuzz $fuzz1% ../results/$img
newfilesize=`convert -ping ../results/$img -precision 16 -format "%b" info: | sed 's/[B]*$//'`
test=`convert xc: -format "%[fx:100*($filesize-$newfilesize)/$filesize<$threshpct?1:0]" info:`
echo "newfilesize=$newfilesize; test=$test;"
[ $test -eq 1 ] && convert $img -background black -deskew 40% -fuzz $fuzz2% ../results/$img
done


问题是您需要确保将输出的 TIFF 压缩设置为与输入相同,以便文件大小相等,并且可能新大小不会像 JPG 那样大于旧大小。

请注意,sed 用于从文件大小中删除字母 B(字节),因此可以将它们作为数字而不是字符串进行比较。-precision 16 强制“%b”报告为 B 而不是 KB 或 MB。

于 2018-06-12T05:21:17.050 回答