自动从漫画中提取图块

问题描述

是否可以使用ImageMagick这样的现有工具自动从漫画中提取图块,还是我应该自己编写一个工具?

我已经看到使用ImageMagick(Using imagemagick how can i slice up an image into several separate images?https://superuser.com/questions/1308928/how-to-automatically-crop-and-cut-an-image-into-several-images-using-imagemagick/1308953#1308953)的答案,但是在我的情况下,图块的大小可以不同(高度可以改变)。

始终在彼此下方有1个图块(仅1列),并且每个图块之间都用相同颜色的某些空间隔开(图像中可以使用黑色,灰色或白色的水平颜色梯度来分隔图块),因此通过查看具有相同像素颜色的水平线,应该可以检测出何时有新的图块并提取出来。

理想情况下,如果漫画有两列或更多列具有不同高度的图块,则也应该有可能提取图块(这可能会更加复杂,因为不一定会有具有相同像素颜色的完整水平线)。

更新:您可以根据要求找到以下我提供的快速样本。一些漫画中有些字符和文本气泡从拼贴中消失,因此无法比较水平线上的像素,因此我故意在样本中添加了此字符。我还添加了另一列和宽度或高度不同的图块,以提供一个示例,其中概述了漫画中可以找到的内容。

comics sample

解决方法

这是在ImageMagick中执行此操作的方法。但我注意到您的图纸可能不具有代表性。首先,我期望垂直框架堆叠,而不是随机排列。其次,图形的某些部分在X或Y中重叠,因此边界框将重叠。我使用连接的组件提取边界框。然后,我简单地在边界框上循环并裁剪图像。

输入:

enter image description here

Unix语法:

bboxArr=(`convert -quiet boxes.png +repage -threshold 50% \
-morphology open square:3 -type bilevel \
-define connected-components:exclude-header=true \
-define connected-components:verbose=true \
-define connected-components:area-threshold=1500 \
-define connected-components:mean-color=true \
-connected-components 4 null: | grep "gray(0)" | awk '{print $2}'`)
num=${#bboxArr[*]}
for ((i=0; i<num; i++)); do
bbox="${bboxArr[$i]}"
echo "$bbox;"
convert -quiet boxes.png +repage -crop "$bbox" +repage boxes_$i.png
done

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

以下是一个更好的示例:

enter image description here

bboxArr=(`convert -quiet DoomPatrol1.jpg +repage -negate -threshold 25% -type bilevel \
-define connected-components:exclude-header=true \
-define connected-components:verbose=true \
-define connected-components:area-threshold=20000 \
-define connected-components:mean-color=true \
-connected-components 8 null: | grep "gray(255)" | awk '{print $2}'`)
num=${#bboxArr}
for ((i=0; i<num; i++)); do
bbox="${bboxArr[$i]}"
echo "$bbox;"
convert -quiet DoomPatrol1.jpg +repage -crop "$bbox" +repage boxes_$i.png
done

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...