public static int ApplyMaskPenaltyRule4(ByteMatrix matrix) {
int numDarkCells = 0;
sbyte[][] array = matrix.GetArray();
int width = matrix.GetWidth();
int height = matrix.GetHeight();
for (int y = 0; y < height; ++y) {
for (int x = 0; x < width; ++x) {
if (array[y][x] == 1) {
numDarkCells += 1;
}
}
}
int numTotalCells = matrix.GetHeight() * matrix.GetWidth();
double darkRatio = (double)numDarkCells / numTotalCells;
return Math.Abs((int)(darkRatio * 100 - 50)) / 5 * 10;
}