使用 ImageMagick 进行连接组件标记 [英] Connected-component labeling with ImageMagick

查看:23
本文介绍了使用 ImageMagick 进行连接组件标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用 ImageMagick 对图像执行连通分量标记?

Is it possible to perform a connected-component labeling on a image with ImageMagick?

维基百科中的连接组件标签

推荐答案

是的,现在可以使用 ImageMagick 6.8.9-10 和更新版本,请参阅 这里.

Yes, it is now possible with ImageMagick 6.8.9-10 and newer, see here.

所以,如果我们从这张图片开始:

So, if we start with this image:

我们可以获得每个blobcomponent的标记组件以及边界框、质心和其他统计信息,如下所示:

we can get the components labelled and also the bounding boxes, centroids and other statistics for each blob or component like this:

convert input.png                                    
    -colorspace gray -negate -threshold 10%          
    -define connected-components:verbose=true        
    -define connected-components:area-threshold=100  
    -connected-components 8 -auto-level output.png

Objects (id: bounding-box centroid area mean-color):
  0: 600x600+0+0 296.9,299.6 260033 srgb(0,0,0)
  2: 467x345+70+211 350.1,398.1 53563 srgb(255,255,255)
  1: 422x105+56+81 266.5,133.0 34814 srgb(255,255,255)
  4: 105x90+112+310 164.0,354.5 9450 srgb(255,255,255)
  3: 178x73+393+246 481.5,282.0 2140 srgb(255,255,255)

然后您可以像这样在边界框中绘制:

You can then draw in the bounding box like this:

convert output.png -fill none -stroke red 
  -draw "rectangle 70,211 537,556"        
  -draw "rectangle 56,81 478,186"         
  -draw "rectangle 112,310 217,400"       
  -draw "rectangle 393,246 571,319"       
  x.png

这篇关于使用 ImageMagick 进行连接组件标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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