Skip to content
DeepForgeby svx
All problems
MediumComputer Visioncv-098

LBP 3x3 Pattern

Problem

Compute the 3x3 Local Binary Pattern for every interior pixel.

Visit neighbors clockwise starting from the top-left: (-1, -1), (-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1). Set bit i when neighbor i >= center and return sum(bit_i * 2^i). The output shape is (H - 2) x (W - 2).

Hint

Bit 0 is the top-left neighbor and bit 7 the left neighbor.

Test cases

case 1
in: [[[1,2,3],[4,5,6],[7,8,9]]]
expected: [[120]]
case 2
in: [[[1,2,3],[4,5,6],[7,8,9],[10,11,12]]]
expected: [[120],[120]]
case 3
in: [[[5,5,5],[5,5,5],[5,5,5]]]
expected: [[255]]
case 4
in: [[[1,1,1],[1,9,1],[1,1,1]]]
expected: [[0]]
Starter codePython
def lbp_pattern(image):
    # Your code here
    pass

4 test cases · run your code against them in the editor