确定图像是否相同但大小不同
我目前正在处理大量图像(超过 3000 张),并且每张图像我都有两份;一大一小。问题是我没有任何类型的链接来说明哪个小图像映射到哪个大图像。
我大致知道哪个大图像到哪个小图像(我有一个数组,每个小图像最多包含 5 种可能性),并且我想循环该数组并将每个大图像与小图像进行比较,以查看如果它是相同的图像但调整了大小。
TLDR/不明白:PHP 中是否有任何简单的方法可以比较两个相同的图像,一个是(例如)200x200,另一个是(例如)500x500,并确定它们是否是同一事物的图像?
I'm currently dealing with a large number of images (over 3000), and I have two copies of each; one large, one small. The problem is I don't have any kind of link to say which small image maps to which large image.
I know roughly which large image goes to which small image (I have an array which contains up to 5 possibilities for each small image), and I'd like to loop round the array and compare each large image to the small image, to see if it's the same image but resized.
TLDR/Didn't Understand: Is there any easy way in PHP to compare two image that are the same, one being (say) 200x200 and the other being (say) 500x500, and determine if they're an image of the same thing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
最简单的方法是将两者调整为较小的尺寸(例如 16x16 或 32x32,具体取决于您想要使用多少 CPU 来跟踪整个过程中每个文件的名称。
然后使用 imagecolorat() 比较每行的像素颜色然后,您可以定义需要匹配的百分比才能被视为相同的图片
:这是一个实现的示例http://www.thismayhem.com/php/comparing-images-with- php-gd/
The easiest way would be resize both to a small size (16x16 or 32x32 for example depending on how much CPU you want to use keeping track of the names of each file throughout the process.
Then use imagecolorat() to compare pixel colours through each row/column. You can then define a percentage of which need to match to be considered the same picture.
Edit: here's an example of this implemented http://www.thismayhem.com/php/comparing-images-with-php-gd/
您是否尝试过调整大图像 1 的大小是否会创建与较小图像之一完全相同的图像(手动使用 Md5 来找出这一点)。
如果是这样,那么您的解决方案是将较大图像批量调整为 tmp 文件,并 md5 构建一个 bigimagemd5 数组,然后 md5 较小的图像。
仅当使用 php GD 算法生成小图像并且您具有与之前使用的相同的压缩级别和大小时,此方法才有效。
Have you tried if resizing 1 of the big image creates the exact same image as one of the smaller ones(manually use Md5 to find that out).
If it does, then your solution is to batch resize the bigger images to a tmp file and md5 it building an array of bigimagemd5s and then you md5 the smaller ones.
This method will only work if the small images were generated using the php GD algorithm and you have the same compression level and size that was used before.
您可以做的一件事是,拍摄大图片,将其缩放到小图片的大小,然后检查那里的一些随机像素区域。如果图片确实不同,您可以使用平均值之类的东西。两个图像的颜色。
但这种方式确实性能很糟糕......
A thing you could do is, take the big picture, scale it to the size of the small picture and check some random pixel-areas there. If the pictures are really different, you could use something like a avg. colour of both images.
But this way is really performance sucking...
我会使用 imagemagick 库来调整图像大小并比较图像。我会使用
exec()
调用它首先,使用
convert
命令调整大图像的大小http://www.imagemagick.org/script/convert.php然后,使用
compare
命令 http://www.imagemagick.org/script/compare.phpI would use the imagemagick library for resize and compare the images. I would call it using
exec()
First, resize the large image using the
convert
command http://www.imagemagick.org/script/convert.phpThen, compare the small image with the resized image using
compare
command http://www.imagemagick.org/script/compare.php手动对它们进行排序会花费你很多很多的时间。
to sort them manually will take you much, much less time.
请检查此链接:
比较 php 中的 2 个图像
似乎使用 ImageMagick 扩展是你最好的选择,尽管你可能必须先将较大的图像缩小到与较小的图像相同的尺寸。
Please check this link:
Compare 2 images in php
It seems that using ImageMagick extension is your best bet, although you'd probably have to scale down the larger image to the same size as your smaller one first.
不,不存在返回 true 或 false 的
same_image_but_in_ Different_sizes()
函数。如果我是你,我要么手动对它们进行排序,要么选择基于颜色直方图的方法。
我刚刚看到所有“图像都是 JPG,它们保存在两个文件夹中:大文件夹和小文件夹”。为什么你不把小的扔掉并重新创建它,但这一次你记得哪个属于哪个?
No, there is not a
same_image_but_in_different_sizes()
function that returns true or false.If I were you, I'd either sort them manually or choose a color histogram based approach.
I just saw that all "images are JPGs, and they're saved in two folders; large and small". Why don't you just throw small away and recreate it, but this time you remember which belongs to which?