加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

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

发布时间:2020-12-13 18:05:31 所属栏目:PHP教程 来源:网络整理
导读:概述: 第一张照片是我原来的照片.在这里,我想用另一个图像替换显示的白色矩形. 我的方法: 我使用floodfill创建了一个蒙版图像,它看起来像: 问题: 现在我想得到第二个图像中矩形的距离或坐标,这样我就可以使用这些坐标在这里的第一个(原始图像)上叠加新图
概述:

第一张照片是我原来的照片.在这里,我想用另一个图像替换显示的白色矩形.

我的方法:

我使用floodfill创建了一个蒙版图像,它看起来像:

问题:

现在我想得到第二个图像中矩形的距离或坐标,这样我就可以使用这些坐标在这里的第一个(原始图像)上叠加新图像.

我有点想法使用ImageMagick的chebyshev形态运算符,但不知道我该怎么做.

我认为您可以使用简单的阈值非常准确地定位形状,如下所示:
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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读