<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def num_adjacent(self, i, j):
 """ Counts the number of adjacent nonzero pixels to a given pixel. Parameters i : int row index of query pixel j : int col index of query pixel Returns ------- int number of adjacent nonzero pixels """

        # check values
        if i < 1 or i > self.height - 2 or j < 1 and j > self.width - 2:
            raise ValueError('Pixels out of bounds')

        # count the number of blacks
        count = 0
        diffs = [[-1, 0], [1, 0], [0, -1], [0, 1]]
        for d in diffs:
            if self.data[i + d[0]][j + d[1]] > self._threshold:
                count += 1
        return count