如何裁剪两个图像的差异? [英] How to crop the difference of two images?

查看:70
本文介绍了如何裁剪两个图像的差异?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想拍摄这两张照片:

基本上就是这样:

我已经尽可能地将 compare fuzz 结合使用来定义已更改的部分.然后可以获取该区域的边界框并裁剪第二帧吗?

I've gotten as far as using compare with fuzz to define the part that has changed. Is it possible to then get the bounding box of this area and crop the second frame?

推荐答案

我会按照以下方式进行操作:

I would do something along these lines:

convert a.jpg b.jpg -colorspace gray -blur 0x2 \
       -compose difference -composite          \
       -threshold 20% out.jpg

转换为灰度并稍微模糊以隐藏小的差异,然后计算差异和阈值以制作二进制图像,如下所示:

Convert to greyscale and blur a little to hide small differences, then calculate the difference and threshold to make a binarised image like this:

然后我要进行连接组件分析,以找到图像中最大的对象,如下所示:

Then I would go for a Connected Components Analysis to find the biggest object in the image, like this:

convert a.jpg b.jpg -colorspace gray -blur 0x2     \
   -compose difference -composite -threshold 20%   \
   -define connected-components:verbose=true       \
   -define connected-components:area-threshold=100 \
   -connected-components 8 out.jpg

Objects (id: bounding-box centroid area mean-color):
  0: 1029x1079+0+0 515.0,538.4 1102870 srgb(0,0,0)
  17: 76x147+326+564 366.5,641.4 5827 srgb(252,252,252)
  22: 18x50+358+612 365.1,635.3 568 srgb(0,0,0)
  11: 34x31+810+345 825.5,361.1 317 srgb(255,255,255)
  16: 57x97+25+539 52.3,587.2 286 srgb(255,255,255)
  14: 46x65+120+414 144.0,444.3 203 srgb(255,255,255)
  18: 27x49+23+579 36.9,601.0 118 srgb(255,255,255)
  24: 16x8+703+641 710.6,644.5 102 srgb(255,255,255)

-define connected-components:verbose = true 导致各个blob作为文本输出以进行解析.

The -define connected-components:verbose=true causes the individual blobs to be output as text for parsing.

-define connected-components:area-threshold = 100 表示仅输出面积大于100像素的斑点.

The -define connected-components:area-threshold=100 says to only output blobs larger than 100 pixels in area.

-connected-components 8 说,允许8个连接的像素被视为属于同一对象.8连通表示除了正常的北,东,南和西外,还包括东北,东南,西南和东北邻国.默认情况下, ImageMagick 仅将4个连接的像素视为属于同一对象-更快;-)

The -connected-components 8 says to allow pixels that are 8-connected to be considered as belonging to the same object. 8-connected means North-East, South-East, South-West and North-East neighbours in addition to the normal North, East, South and West. By default, ImageMagick only considers 4-connected pixels as belonging to the same object - it's faster ;-)

您的播放器是项 id 17 -第二行,您可以看到边界框,并使用

And your player is item id 17 - the second row and you can see the bounding box, and cut that out of the orignal with

convert b.jpg -crop 76x147+326+564 player.jpg

注意:您需要ImageMagick 6.8.9-10或更高版本才能进行连接组件分析.

Note: You will need ImageMagick 6.8.9-10 or better for Connected Components Analysis.

这篇关于如何裁剪两个图像的差异?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆