/// <summary> /// Computes a confusion matrix using the soft values from the distributions in <paramref name="inferredLabels"/> based upon the ground truth /// pixel labels in <paramref name="groundTruth"/>, and adds them to <paramref name="matrix"/>. /// </summary> /// <param name="matrix">Matrix to add the confusion values of this image to</param> /// <param name="groundTruth">The ground truth labels of the image</param> /// <param name="inferredLabels">The inferred labels of the image</param> public static unsafe void ComputeConfusionMatrix(ConfusionMatrix matrix, LabelImage groundTruth, DistributionImage inferredLabels) { int rows = groundTruth.Rows; int columns = groundTruth.Columns; int channels = inferredLabels.Channels; fixed(short *labelsSrc = groundTruth.RawArray) { fixed(float *distSrc = inferredLabels.RawArray) { short *labelsPtr = labelsSrc; float *distPtr = distSrc; for (int r = 0; r < rows; r++) { for (int c = 0; c < columns; c++, labelsPtr++) { short trueLabel = *labelsPtr; for (short i = 0; i < channels; i++, distPtr++) { matrix.Add(trueLabel, i, *distPtr); } } } } } }
/// <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); } } }