如何删除在ImageMagick中经常发生在图像中的黑色带

发布于 2025-01-19 21:53:09 字数 408 浏览 1 评论 0原文

我已经捕获了图像,并且图像捕获扩展留下了定期出现的黑色条带(请参见下面的示例)

是否有 imagemagick 命令可以一次删除所有条带?我尝试使用下面的伪代码递归运行它,但没有成功:

for i=1 to height of image/1000
split image at 1000 pixels * i
crop 10 pixels, top
stitch image with cropped image

编辑:将示例图像更改为全分辨率

在此处输入图像描述

I've captured an image, and the image capture extension have left regular black bands that occur at regular intervals (see example below)

Is there an imagemagick command to remove all bands at once? I've tried to run it recursively, using the below pseudo-code, without success:

for i=1 to height of image/1000
split image at 1000 pixels * i
crop 10 pixels, top
stitch image with cropped image

EDIT: changed example image to a full resolution one

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

白色秋天 2025-01-26 21:53:09

以下是如何在 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=

对于 Imagemagick 7,将“convert”更改为“magick”

\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 $2, $3, $4, $5}'`) 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/^\(.*\) \(.*\) \(.*\) \(.*\)$/\1x\2+\3+\4/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,将“convert”更改为“magick”

Here is how to crop each white section of your slides in ImageMagick 6 in Unix.

#
# 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=

For Imagemagick 7, change "convert" to "magick"

\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 $2, $3, $4, $5}'`) 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/^\(.*\) \(.*\) \(.*\) \(.*\)$/\1x\2+\3+\4/p'`) echo "${sortArr[*]}" for ((i=0; i<num; i++)); do bbox="${sortArr[$i]}" convert slides.jpg -crop $bbox +repage slides_section_$i.jpg done

For Imagemagick 7, change "convert" to "magick"

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文