本文介绍了PHP的 - 如何使用imagick或其他库找到图像中的边缘坐标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给定一个图像组成的一个简单的黑色领域与一个单一的白色矩形里面,我怎么能提取矩形的坐标?我搜索了谷歌搜索,并发现了许多关于使用霍夫线,卷积,形态学等边缘检测的文章,但所有这些实际上都会影响图像或以某种方式进行转换。我不想改变图像,我想要做的就是找到边缘。

显然,我可以简单地遍历整个宽度+高度图像和看像素颜色(如一些帖子的建议),但这似乎非常低效。有没有内置算法?似乎这一定是imagick某个地方的一部分,否则它怎么可能找到并画出内部图像的边缘?但我很难找到如何解决它。

=新的Imagick(realpath('./ trim.png'));
$ base-> trimImage(0);
//获取新图像大小
$ geometry = $ base-> getImageGeometry();
//检索修剪信息
$ pageInfo = $ base-> getImagePage();

一个类似的例子在手册页上:


given an image composed of a plain black field with a single white rectangle inside it somewhere, how can i extract the coordinates of the rectangle ? i've googled and googled and found numerous articles on edge detection using hough lines, convolution, morphology, etc., but all of these actually edge the image or convert it in some way. i don't want to change the image, all i want to do is find where the edges are.

obviously, i could simply iterate over the entire width+height of the image and look at the pixel colours (as some posts suggest), but that seems horribly inefficient. is there no built-in algorithm ? it seems like this must be part of imagick somewhere, otherwise how could it actually find and draw the edges of internal images ? but i'm having trouble finding out how to get at it.

解决方案
$base = new Imagick(realpath('./trim.png'));
$base->trimImage(0);
// get the new image size
$geometry = $base->getImageGeometry();
// Retrieve the trim info
$pageInfo = $base->getImagePage();

A similar example is on the manual page:http://php.net/manual/en/imagick.trimimage.php#111332

这篇关于PHP的 - 如何使用imagick或其他库找到图像中的边缘坐标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-15 21:43