Sobel Operator || Pixel Constraint
This is not a limitation of the Sobel operator, if the boundaries are clear, even a single pixel wide rectangle should be detectable.

I ran your code, but just used an empty image as the "im" image and it worked fine for me.

Here is my code (similar to yours, just without 'Test.png' and without saving the images):

from PIL import Image
import numpy as np
from scipy import ndimage

im = Image.fromarray(np.zeros((81,91)).astype(np.uint8))
pix_val = np.array(list(im.getdata())).reshape(81,91)
for i in range(12,14):
    for j in range(12,78):
        pix_val[i,j]=255      
for i in range(63,65):
    for j in range(12,78):
        pix_val[i,j]=255
for i in range(14,63):
    for j in range(12,14):
        pix_val[i,j]=255
for i in range(14,63):
    for j in range(76,78):
        pix_val[i,j]=255

Oim1 = Image.fromarray(pix_val.astype(np.uint8))
pix_val2 = np.delete(pix_val,range(16,75), 1)
Oim1.show()

Oim2 = Image.fromarray(pix_val2.astype(np.uint8))
Oim2.show()

dy1 = ndimage.sobel(Oim1, 1)
Oim3 = Image.fromarray(dy1.astype(np.uint8))
Oim3.show()

dy2 = ndimage.sobel(Oim2, 1)
Oim4 = Image.fromarray(dy2.astype(np.uint8))
Oim4.show()


This is what I get: