private static boolean isPointBelongsToContour(int matrix[][], int x, int y) {
        int p2 = matrix[y - 1][x];
        int p3 = matrix[y - 1][x + 1];
        int p4 = matrix[y][x + 1];
        int p5 = matrix[y + 1][x + 1];
        int p6 = matrix[y + 1][x];
        int p7 = matrix[y + 1][x - 1];
        int p8 = matrix[y][x - 1];
        int p9 = matrix[y - 1][x - 1];
        boolean result = (p2 == 0)
                || (p3 == 0)
                || (p4 == 0)
                || (p5 == 0)
                || (p6 == 0)
                || (p7 == 0)
                || (p8 == 0)
                || (p9 == 0);
        return result;
    }