简体   繁体   English

比较两个数组并返回它们的余数

[英]Compare two arrays and return their remainder

I am doing an image comparer for learning purposes. 我正在做一个图像比较器用于学习目的。

I have done almost everything already and I am now improving it. 我已经做了几乎所有的事情,现在正在改进它。 To check for similarity, I have 2 jagged-multidimensional arrays ( byte[][,] ) where I access each element of each array using a triple for loop and store their remainder, like this: 为了检查相似性,我有2个交错的多维数组( byte[][,] ),在其中使用三重for循环访问每个数组的每个元素,并存储它们的余数,如下所示:

for (int dimension = 0; dimension < 8; dimension++)
{
    Parallel.For(0, 16, mycolumn =>
    {
        Parallel.For(0, 16, myrow =>
        {
            Diffs[dimension][mycolumn, myrow] =
                (byte)Math.Abs(Image1Bytes[dimension][mycolumn, myrow]
                - Image2Bytes[dimension][mycolumn, myrow]);
        });
    });
}

Now, I would like to check how much each dimension is equal to another in the other collection. 现在,我想检查每个维度与另一个集合中的另一个维度相等。

How could I compare the entire arrays in each array (like array1[i][,] == array2[j][,] )? 我如何比较每个数组中的整个数组(例如array1[i][,] == array2[j][,] )?

I think there are better ways to do these operations, but I have managed to do them pretty quickly. 我认为有更好的方法可以执行这些操作,但是我已经设法很快地完成了这些操作。

Here is an older thread on comparing two images that would be simple for you to adapt to your needs. 这是比较两个图像的较旧的线程,它很容易满足您的需求。

Compare Bitmaps 比较位图

Since Array supports the IStructuralEquatable interface, you can use structural comparison: 由于Array支持IStructuralEquatable接口,因此可以使用结构比较:

using System.Collections;

. . .

var areEqual = StructuralComparisons.StructuralEqualityComparer.Equals(array1[i], array2[j]);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM