php使用imagemagick,php – 如何使用ImageMagick替换图像中的白色矩形?

我认为您可以使用简单的阈值非常准确地定位形状,如下所示:

convert image.jpg -threshold 90% result.jpg

然后你可以像这样做一个Canny边缘检测:

convert image.jpg -threshold 90% -canny 0x1+10%+30% result.jpg

接下来我要看的是,使用-trim函数找到修剪框坐标,如下所示:

convert result.jpg -format "%@" info:

320x248+152+40

我在下面用红色标记了.

如果你真的想做修剪,请使用:

convert result.jpg -trim result.jpg

而且,偏斜角度

convert result.jpg -deskew 40 -format "%[deskew:angle]" info:

-0.111906

霍夫线检测也可能对您有效:

convert image.jpg -threshold 90% -canny 0x1+10%+30% \

\( +clone -background none \

-fill red -stroke red -strokewidth 2 \

-hough-lines 5x5+80 -write lines.mvg \

\) -composite hough.png

而文件lines.mvg包含您要查找的4行

# Hough line transform: 5x5+80

viewBox 0 0 640 360

line 449.259,0 474.432,360 # 90

line 0,72.5604 640,27.8072 # 143

line 0,293.098 640,248.344 # 187

line 153.538,0 178.712,360 # 153

有点懒,我不想解决这些线的交叉点,所以我想我也让ImageMagick这样做 – 通过使用Morphology来寻找像这样的Line Junction:

convert image.jpg -threshold 90% -canny 0x1+10%+30% \

\( +clone -background none -fill red -stroke red -hough-lines 5x5+80 \) \

-composite -fuzz 50% -fill black -opaque white \

-morphology HMT LineJunctions hough.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值