admin管理员组文章数量:1287878
Below is a bash script I have written to correct a certain type of skew produced in some scanned images of text.
The script works fine except for the final command, intended to change white background to the original background color. Varying the fuzz factor in this command shows it is working, except it has no effect on the white triangles introduced by the preceding -distort command when $2 is negative. They remain unaffected by any variation in -fuzz.
Included are images before and after the script, but the white triangles at top and bottom of the right hand image do not show against the background
str(){ # stretch/compress text trapezoid to rectangle, str %f [pixels, def 5]
# NB pixels + stretches right hand side, pixels - compresses it
a=($(identify $1|cut -d ' ' -f 3|tr 'x' ' '))
pxl=$(convert $1 -format "%[pixel:s.p{0,0}]" info:)
c=${2:-5} # pixels to stretch, default 5
let b=a[1]-c
exp='0,0 0,0, '${a[0]}','$2' '${a[0]}',0, 0,'${a[1]}' 0,'${a[1]}', '${a[0]}','$b' '${a[0]}','${a[1]}
convert $1 -alpha set -virtual-pixel transparent -distort Perspective "$exp" +repage q.png
convert +repage q.png -fuzz 10% -fill $pxl -opaque white -| xv -
}
Below is a bash script I have written to correct a certain type of skew produced in some scanned images of text.
The script works fine except for the final command, intended to change white background to the original background color. Varying the fuzz factor in this command shows it is working, except it has no effect on the white triangles introduced by the preceding -distort command when $2 is negative. They remain unaffected by any variation in -fuzz.
Included are images before and after the script, but the white triangles at top and bottom of the right hand image do not show against the background
str(){ # stretch/compress text trapezoid to rectangle, str %f [pixels, def 5]
# NB pixels + stretches right hand side, pixels - compresses it
a=($(identify $1|cut -d ' ' -f 3|tr 'x' ' '))
pxl=$(convert $1 -format "%[pixel:s.p{0,0}]" info:)
c=${2:-5} # pixels to stretch, default 5
let b=a[1]-c
exp='0,0 0,0, '${a[0]}','$2' '${a[0]}',0, 0,'${a[1]}' 0,'${a[1]}', '${a[0]}','$b' '${a[0]}','${a[1]}
convert $1 -alpha set -virtual-pixel transparent -distort Perspective "$exp" +repage q.png
convert +repage q.png -fuzz 10% -fill $pxl -opaque white -| xv -
}
Share Improve this question asked Feb 23 at 0:35 user985675user985675 2913 silver badges10 bronze badges 3 |
1 Answer
Reset to default 0My thanks to all who responded. The solution turned out to be quite simple. I replaced the 2 'convert' commands at the end with this one.
convert $1 -alpha set -virtual-pixel transparent -distort Perspective "$exp" -background $pxl -| xv -
版权声明:本文标题:bash - Cannot fill white triangles generated by 'Imagemagick -distort' with background color - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741323275a2372329.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
set -x
to see what's happening – Diego Torres Milano Commented Feb 24 at 2:03