Is it possible to find exact contours?

Hi there!
Is it possible to find exact contours of 4 rectangles on this image?

I use code like this:
ret, thresh = cv2.threshold(gray, 243, 255, cv2.THRESH_BINARY)
contours, hierarchy = cv2.findContours(image=thresh, mode=cv2.RETR_TREE, method=cv2.CHAIN_APPROX_NONE)
And in top of top-left image:

extra line at the top:


I’d recommend presenting a few more pictures that express the anticipated variation in those pictures.

for that specific picture, you could just hardcode the regions.

for some variation, you could take the min() of each pixel row and column, and analyze that, so you can see where there is only background.

of course, JPEGs are lossy, so that’ll be annoying.