如何删除 imagemagick 中图像中经常出现的黑带
how to remove black bands that occur regularly in an image in imagemagick
我拍摄了一张图像,图像拍摄扩展程序留下了定期出现的规则黑带(参见下面的示例)
是否有一个 imagemagick 命令可以一次删除所有波段?我尝试使用下面的伪代码递归地 运行 它,但没有成功:
for i=1 to height of image/1000
split image at 1000 pixels * i
crop 10 pixels, top
stitch image with cropped image
编辑:将示例图像更改为全分辨率图像
以下是如何在 Unix 中的 ImageMagick 6 中裁剪幻灯片的每个白色部分。
#
# threshold image
# use morphology to close up small black or white regions
# convert to bilevel
# do connected-component processing to find all regions larger than 1000 pixels in area
# keep only gray(255) i.e. white regions and get the bounding box and color and replace WxH+X+Y with W H X Y.
# sort by Y (rather than area) and put the x and +s back to re-form WxH+X+Y
# loop over data to get the bounding box and crop the image
#
OLD_IFS=$IFS
IFS=$'\n'
arr=(`convert slides.jpg -threshold 25% \
-morphology close rectangle:5 +write x1.png \
-morphology open rectangle:5 +write x2.png \
-type bilevel \
-define connected-components:verbose=true \
-define connected-components:exclude-header=true \
-define connected-components:area-threshold=1000 \
-define connected-components:mean-color=true \
-connected-components 8 y.png | grep "gray(255)" | sed 's/[x+]/ /g' | awk '{print , , , }'`)
IFS=$OLD_IFS
num=${#arr[*]}
echo $num
echo "${arr[*]}"
# sort array by Y value
sortArr=(`echo "${arr[*]}" | sort -n -t " " -k4,4 | sed -n 's/^\(.*\) \(.*\) \(.*\) \(.*\)$/x++/p'`)
echo "${sortArr[*]}"
for ((i=0; i<num; i++)); do
bbox="${sortArr[$i]}"
convert slides.jpg -crop $bbox +repage slides_section_$i.jpg
done
对于 Imagemagick 7,将“转换”更改为“magick”
我拍摄了一张图像,图像拍摄扩展程序留下了定期出现的规则黑带(参见下面的示例)
是否有一个 imagemagick 命令可以一次删除所有波段?我尝试使用下面的伪代码递归地 运行 它,但没有成功:
for i=1 to height of image/1000
split image at 1000 pixels * i
crop 10 pixels, top
stitch image with cropped image
编辑:将示例图像更改为全分辨率图像
以下是如何在 Unix 中的 ImageMagick 6 中裁剪幻灯片的每个白色部分。
#
# threshold image
# use morphology to close up small black or white regions
# convert to bilevel
# do connected-component processing to find all regions larger than 1000 pixels in area
# keep only gray(255) i.e. white regions and get the bounding box and color and replace WxH+X+Y with W H X Y.
# sort by Y (rather than area) and put the x and +s back to re-form WxH+X+Y
# loop over data to get the bounding box and crop the image
#
OLD_IFS=$IFS
IFS=$'\n'
arr=(`convert slides.jpg -threshold 25% \
-morphology close rectangle:5 +write x1.png \
-morphology open rectangle:5 +write x2.png \
-type bilevel \
-define connected-components:verbose=true \
-define connected-components:exclude-header=true \
-define connected-components:area-threshold=1000 \
-define connected-components:mean-color=true \
-connected-components 8 y.png | grep "gray(255)" | sed 's/[x+]/ /g' | awk '{print , , , }'`)
IFS=$OLD_IFS
num=${#arr[*]}
echo $num
echo "${arr[*]}"
# sort array by Y value
sortArr=(`echo "${arr[*]}" | sort -n -t " " -k4,4 | sed -n 's/^\(.*\) \(.*\) \(.*\) \(.*\)$/x++/p'`)
echo "${sortArr[*]}"
for ((i=0; i<num; i++)); do
bbox="${sortArr[$i]}"
convert slides.jpg -crop $bbox +repage slides_section_$i.jpg
done
对于 Imagemagick 7,将“转换”更改为“magick”