image - 使用 ImageMagick 进行连通分量标记

标签 image image-processing imagemagick imagemagick-convert

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

Connected-component labeling in Wikipedia

最佳答案

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

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

enter image description here

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

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)

enter image description here

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

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

enter image description here

关于image - 使用 ImageMagick 进行连通分量标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14377463/

相关文章:

ios - Autosize 和 UIImageView 无法正常工作

java - 如何将任务栏按钮上的图像更改为 Swing 应用程序上的自定义图像?

javascript - png在IE浏览器中的问题

Python - 在不使用内置旋转方法的情况下旋转图像

ffmpeg - 如何将 ffmpeg 输出传送到 ImageMagick 的转换工具?

algorithm - 使用 ImageMagick 裁剪具有焦点区域(面部)的图像

python - 将库尔德文本(从右到左)添加到图像会返回分隔的字符串

c++ - OpenCV中的段错误

matlab - 如何对齐图像 - Matlab

c - PostgreSQL Type 1 接口(interface)和 ImageMagick 代码 - 冲突的 StringInfo 定义?