def crop_image_only_outside(gray_img, raw_img, threshold=128, padding=3):
    mask = (gray_img > threshold)
    (m, n) = gray_img.shape
    (mask0, mask1) = (mask.any(0), mask.any(1))
    (col_start, col_end) = (mask0.argmax(), (n - mask0[::(- 1)].argmax()))
    (row_start, row_end) = (mask1.argmax(), (m - mask1[::(- 1)].argmax()))
    return raw_img[(row_start - padding):(row_end + padding), (col_start - padding):(col_end + padding)]
def crop_image_only_outside(gray_img, raw_img, threshold=128, padding=3):
    mask = (gray_img > threshold)
    (m, n) = gray_img.shape
    (mask0, mask1) = (mask.any(0), mask.any(1))
    (col_start, col_end) = (mask0.argmax(), (n - mask0[::(- 1)].argmax()))
    (row_start, row_end) = (mask1.argmax(), (m - mask1[::(- 1)].argmax()))
    return raw_img[(row_start - padding):(row_end + padding), (col_start - padding):(col_end + padding)]