def colored_pixels(img, thresh):
    """
    Find the positions of all pixels in the image that are considered dark
    enough for text.

    The image is assumed to be grayscale.

    Args:
        img (numpy.ndarray): Image to check.
        thresh (int): Background threshold up to which a pixel is considered
            colored.

    Returns:
        list[tuple[int, int]]: List of coordinates for all colored pixels.
    """
    assert len(img.shape) == 2  # 2D matrix
    return [(x, y) for y, row in enumerate(img) for x, pixel in enumerate(row)
            if pixel <= thresh]