|
int MAX_LABEL_VALUE = 1000;
int NUM_VOXELS = 102297600;
int SIZE_Y = 480;
int SIZE_X = 640;
int REGION_MIN_X = 0;
int REGION_MAX_X = 383;
int[] SCORABLE_Z_SLICES = {0, 18, 34, 51, 68, 84, 101, 118, 134, 151, 167, 184, 201, 218, 234, 250, 268, 284, 301, 318, 332};
short[] answer = new short[NUM_VOXELS];
Set<Short> uniqueAnswer = new HashSet<Short>();
short[] groundTruth = new short[NUM_VOXELS];
Set<Short> uniqueGroundTruth = new HashSet<Short>();
// ... data loading not included ...
int[][] labelCountMatrix = new int[MAX_LABEL_VALUE + 1][MAX_LABEL_VALUE + 1];
int[] groundTruthLabelCounts = new int[MAX_LABEL_VALUE + 1];
int[] answerLabelCounts = new int[MAX_LABEL_VALUE + 1];
for (int sliceIndex = 0; sliceIndex < SCORABLE_Z_SLICES.length; sliceIndex++)
{
int z = SCORABLE_Z_SLICES[sliceIndex];
for (int x = REGION_MIN_X; x <= REGION_MAX_X; x++)
{
for (int y = 0; y < SIZE_Y; y++)
{
int voxelIndex = z * SIZE_Y * SIZE_X + y * SIZE_X + x;
labelCountMatrix[groundTruth[voxelIndex]][answer[voxelIndex]]++;
groundTruthLabelCounts[groundTruth[voxelIndex]]++;
if (groundTruth[voxelIndex] > 2)
{
answerLabelCounts[answer[voxelIndex]]++;
}
}
}
}
boolean[] groundTruthLabelMatched = new boolean[MAX_LABEL_VALUE + 1];
double TP = 0;
double FP = 0;
double FN = 0;
for (short answerLabel : uniqueAnswer)
{
if (answerLabel > 0 && answerLabelCounts[answerLabel] > 0)
{
for (short groundTruthLabel : uniqueGroundTruth)
{
if (groundTruthLabel > 2 && groundTruthLabelCounts[groundTruthLabel] > 0)
{
int intersection = labelCountMatrix[groundTruthLabel][answerLabel];
int union = groundTruthLabelCounts[groundTruthLabel] + answerLabelCounts[answerLabel] - intersection;
double jaccardIndex = (double) intersection / (double) union;
if (jaccardIndex > 0.5)
{
TP += jaccardIndex;
groundTruthLabelMatched[groundTruthLabel] = true;
}
else
{
FP += jaccardIndex;
}
}
}
}
}
for (short groundTruthLabel : uniqueGroundTruth)
{
if (groundTruthLabel > 2 && groundTruthLabelCounts[groundTruthLabel] > 0 && !groundTruthLabelMatched[groundTruthLabel])
{
FN++;
}
}
double fScore = 2.0 * TP / (2.0 * TP + FN + FP);
double score = 1000000 * fScore;
|