3

是否可以使用 ImageMagick 对图像执行连接组件标记?

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

4

1 回答 1

5

是的,现在可以使用 ImageMagick 6.8.9-10 及更高版本,请参阅此处

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

在此处输入图像描述

我们可以得到标记的组件以及每个的边界框、质心和其他统计信息,blob或者component像这样:

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)

在此处输入图像描述

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

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

在此处输入图像描述

于 2015-02-10T10:15:19.530 回答