从图像中提取包含更多信息的固定高度水平条纹

2024-06-01 13:24:31 发布

您现在位置:Python中文网/ 问答频道 /正文

我想创建标题横幅从各种图像来说明博客文章

目前我有:

# Use IM based script http://www.fmwconcepts.com/imagemagick/aspectcrop/index.php 
subprocess.call('aspectcrop.sh -a 7:2 %s %s' % (out_image, out_image), shell=True)

。。。以7:2的比例提取中心水平条纹
适用于大多数图像,但有时图像主题不居中。你知道吗

如何检测哪个水平条带是最聚焦的(类似于计算不同可能条带的FFT标准)。你知道吗

  • 对当前技术的一个改进是能够给一个值(center (c), north (n), south (s))aspectcrop.sh版本gravity选项。
    我可以生成3条条纹并保留最大的条纹(~有更多细节的那条?)形象。但它并不优雅,3条条纹之间的选择似乎过于有限。你知道吗
  • 如果解不涉及像PIL这样的附加依赖,则为brownie点。理想情况下,依赖IM子进程调用最适合我。你知道吗

更新: 考虑一下https://dl.dropboxusercontent.com/u/1026715/screenshots/eggs.jpg 如何自动提取 enter image description here

而不是(当前实施):

enter image description here


Tags: 图像imagecom标题usesh文章水平
1条回答
网友
1楼 · 发布于 2024-06-01 13:24:31

也许不是最好的答案,但是一些想法和技巧。。。你知道吗

如果执行此操作,可以将图像分割为20个相等水平条纹的平铺集:

convert eggs.jpg -crop x20@ miff:- | montage -tile 1x -geometry +0+5 - montage.jpg

enter image description here

然后,您可以为集合中的每个图块计算一些统计信息,并查看哪些图块具有较高的熵,例如,这可能是明显聚焦的图块,或者具有较高方差的图块-这意味着存在大量细节/颜色变化。然后你可以根据价值观选择一些。。。。也许你能想出其他的统计数字。你知道吗

convert eggs.jpg -crop x20@ -format "%s:%[entropy]:%[standard_deviation]\n" info:

0:0.879802:11026.6
1:0.899478:9334.69
2:0.932645:8009.17
3:0.931683:8206.57
4:0.916827:7005.17
5:0.950524:11547.2
6:0.926702:9338.89
7:0.896852:13487
8:0.950969:20682.1
9:0.938144:20332.6
10:0.922911:13527.2
11:0.932364:15022.7
12:0.915607:12373.9
13:0.921873:12796
14:0.922808:11978.2
15:0.962032:14310.3  < - high-ish entropy and variance
16:0.952019:15031.2  < - high-ish entropy and variance
17:0.974847:15504.4  < - high-ish entropy and variance
18:0.952463:14456.9  < - high-ish entropy and variance
19:0.927006:13945.5

注意,上面-format语句中的%s指的是“场景号”。你知道吗

相关问题 更多 >