I would say, if you image contains only 0s and 1s where the edges are.
You can put it in a convolution whole kernel size the the rectangular area you want. And all weights are 1 (no bias).
Every point of the output that has a non-zero value has it’s rectangle touching an edge.
Is that good for you?