本帖最后由 aa77dd@163.com 于 2016-9-30 15:55 编辑
印刷书籍页面本身有空白边缘, 经过扫描得到的图片可能比在原始空白边缘基础上还有所增加, 阅读此类电子书籍时, 如果页面适应窗口, 实际内容就可能没有显示得足够大而影响辨识, 在移动设备的小屏幕上尤甚
ImageMagick 官方有详尽的命令行示例代码
http://www.imagemagick.org/Usage/crop/#trim
但对并不需要经常用此工具批处理图片者, 消化这个命令行用法, 还是很要点时间
用 blur 参数可以对噪点严重的空白边缘适应, 但处理速度也极大程度上减慢;
仅仅轻微的噪点时, 不用 blur 参数, 仍 可以用 fuzz 仍有一定处理噪点的能力, 而速度不会减少太多- REM 一次性裁剪掉四边空白
- %convert% "d:\test.png" -gravity SouthEast ^
- -background white -splice 0x0 -background black -splice 0x0 ^
- -fuzz 5%% -trim +repage -chop 0x0 "d:\test.png"
复制代码 图片处理前
|
图片处理后
|
- @echo off & chcp 936
- setlocal enabledelayedexpansion
-
-
- set "IM=D:\桌面\ImageMagick-7.0.3-0-portable-Q16-x86"
-
-
- for %%N in (identify convert) do for %%a in ("%IM%\%%N.exe") do set "%%N=%%~sa"
-
-
- set "imgTypes=png bmp jpg"
-
- set /a "cntPic=sumPic=0"
-
- for %%x in (%imgTypes%) do for /f "delims=" %%i in ('2^>nul dir /a-d /b /s "%~dp0*.%%x" ^| find /v /c ""') do ^
- set /a "sumPic += %%i"
-
-
- for %%x in (%imgTypes%) do for /f "delims=" %%i in ('2^>nul dir /a-d /b /s "%~dp0*.%%x"') do (
-
- for /f "tokens=1-2" %%b in ('%identify% -format "%%[fx:w] %%[fx:h]" "%%~i"') do (
-
- set /a "cntPic+=1, 原宽=%%b,原高=%%c"
- title 已完成 !cntPic!/!sumPic! %%~i %~nx0 & rem 在标题栏上显示处理进度
- REM echo;%%i
- REM echo;原尺寸:!原宽!,!原高!
-
-
- REM 适应边缘空白有噪点的方式, -blur 参数控制噪点大小过滤, -fuzz 控制色模糊过滤
- for /f delims^= %%a in ('%convert% "%%~i" -virtual-pixel edge -blur 0x4 -fuzz 5%% -trim ^
- -format '%%[fx:w+20]x%%[fx:h+20]+%%[fx:page.x-10]+%%[fx:page.y-10]' ^
- info:') do (
- echo;%%~i: %%a
- set "cropParam=%%a"
- %convert% "%%~i" -crop !cropParam:'=! +repage "%%~i"
- )
-
- REM 以下是对清晰图片 trim 的方式, 空白边缘无噪点
- REM 剪上部 和 左部 空白
- REM %convert% "%%~i" -gravity South ^
- REM -background white -splice 0x1 -background black -splice 0x1 ^
- REM -trim +repage -chop 0x1 ^
- REM -gravity East ^
- REM -background white -splice 1x0 -background black -splice 1x0 ^
- REM -trim +repage -chop 1x0 ^
- REM "%%~i"
-
-
- REM 一次性裁剪掉四边空白
- REM %convert% "%%~i" -gravity SouthEast ^
- REM -background white -splice 0x0 -background black -splice 0x0 ^
- REM -fuzz 5%% -trim +repage -chop 0x0 "%%~i"
-
-
- REM 剪下部和右部空白
- REM %convert% "%%~i" -gravity North ^
- REM -background white -splice 0x1 -background black -splice 0x1 ^
- REM -trim +repage -chop 0x1 ^
- REM -gravity West ^
- REM -background white -splice 1x0 -background black -splice 1x0 ^
- REM -trim +repage -chop 1x0 ^
- REM "%%~i"
-
- )
- )
- echo;!cntPic!/!sumPic! 已完成处理
-
- pause
- exit
-
-
-
- REM 一次性裁剪掉四边空白
- REM %convert% "d:\test.png" -gravity SouthEast ^
- REM -background white -splice 0x0 -background black -splice 0x0 ^
- REM -trim +repage -chop 0x0 "d:\test.png"
-
-
- REM 剪上部空白
- %convert% "D:\test.png" -gravity South ^
- -background white -splice 0x1 -background black -splice 0x1 ^
- -trim +repage -chop 0x1 "d:\trim_South.png"
-
- REM 剪左部空白
- %convert% "d:\trim_South.png" -gravity East ^
- -background white -splice 1x0 -background black -splice 1x0 ^
- -trim +repage -chop 1x0 "d:\trim_SouthEast.png"
复制代码
|