作为一种快速,简单的算法,我建议迭代每个图像中大约1%的像素,并将它们直接相互比较或保持运行平均值,然后比较最后的两个平均颜色值.
您可以查看此答案,了解如何确定图像中给定位置的像素颜色.您可能希望稍微优化它以更好地适应您的用例(反复查询相同的图像),但它应该提供一个良好的起点.
然后您可以使用大致类似的算法:
float numDifferences = 0.0f;
float totalCompares = width * height / 100.0f;
for (int yCoord = 0; yCoord < height; yCoord += 10) {
for (int xCoord = 0; xCoord < width; xCoord += 10) {
int img1RGB[] = [image1 getRGBForX:xCoord andY: yCoord];
int img2RGB[] = [image2 getRGBForX:xCoord andY: yCoord];
if (abs(img1RGB[0] - img2RGB[0]) > 25 || abs(img1RGB[1] - img2RGB[1]) > 25 || abs(img1RGB[2] - img2RGB[2]) > 25) {
//one or more pixel components differs by 10% or more
numDifferences++;
}
}
}
if (numDifferences / totalCompares <= 0.1f) {
//images are at least 90% identical 90% of the time
}
else {
//images are less than 90% identical 90% of the time
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
13335 次 |
最近记录: |