Example #1
0
        /// <summary>
        /// Adds the raw values of the two confusion matrices together.
        /// </summary>
        /// <param name="lhs">The first matrix</param>
        /// <param name="rhs">The second matrix</param>
        /// <returns>A new matrix with the sums of the values of the two matrices</returns>
        public static ConfusionMatrix Add(ConfusionMatrix lhs, ConfusionMatrix rhs)
        {
            if (lhs._size != rhs._size)
            {
                throw new ArgumentException("Matrixes must be the same size");
            }

            int             size   = lhs._size;
            ConfusionMatrix result = new ConfusionMatrix(size);

            for (int r = 0; r < size; r++)
            {
                for (int c = 0; c < size; c++)
                {
                    result._matrix[r, c] = lhs._matrix[r, c] + rhs._matrix[r, c];
                }
            }
            result.computeAccuracies();
            return(result);
        }
Example #2
0
        /// <summary>
        /// Computes a confusion matrix from <paramref name="inferredLabels"/> using <paramref name="trueLabels"/> as a reference, and adds
        /// the information into <paramref name="matrix"/>.
        /// </summary>
        /// <param name="matrix">The matrix that will hold the results</param>
        /// <param name="trueLabels">The true labels of an image</param>
        /// <param name="inferredLabels">The inferred labels of an image</param>
        public static unsafe void ComputeConfusionMatrix(ConfusionMatrix matrix, LabelImage trueLabels, LabelImage inferredLabels)
        {
            fixed(short *trueLabelsSrc = trueLabels.RawArray, inferredLabelsSrc = inferredLabels.RawArray)
            {
                short *trueLabelsPtr     = trueLabelsSrc;
                short *inferredLabelsPtr = inferredLabelsSrc;

                int count = trueLabels.Rows * trueLabels.Columns;

                while (count-- > 0)
                {
                    short row    = *trueLabelsPtr++;
                    short column = *inferredLabelsPtr++;
                    if (row == BackgroundLabel)
                    {
                        continue;
                    }
                    matrix.Add(row, column);
                }
            }
        }