Geometric kernels

I would like to define some sort of geometric kernels for a convolutional layer and I am wondering which is the most efficient way to do it.

For example, I would like to define a binary kernel whose lit pixels are all in a straight line passing for the center of the kernel. The trainable parameters are therefore the angular coefficient and the width of the line.

The only way I found was to use cv2.line, but I feel it’s very convoluted and not efficient. Do you know some better way?