The following is an example of your example, although adjustments may need to be made for a wider range of images.
import numpy as np import cv2 image_src = cv2.imread("input.png") gray = cv2.cvtColor(image_src, cv2.COLOR_BGR2GRAY) ret, gray = cv2.threshold(gray, 250,255,0) image, contours, hierarchy = cv2.findContours(gray, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE) largest_area = sorted(contours, key=cv2.contourArea)[-1] mask = np.zeros(image_src.shape, np.uint8) cv2.drawContours(mask, [largest_area], 0, (255,255,255,255), -1) dst = cv2.bitwise_and(image_src, mask) mask = 255 - mask roi = cv2.add(dst, mask) roi_gray = cv2.cvtColor(roi, cv2.COLOR_BGR2GRAY) ret, gray = cv2.threshold(roi_gray, 250,255,0) image, contours, hierarchy = cv2.findContours(gray, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE) max_x = 0 max_y = 0 min_x = image_src.shape[1] min_y = image_src.shape[0] for c in contours: if 150 < cv2.contourArea(c) < 100000: x, y, w, h = cv2.boundingRect(c) min_x = min(x, min_x) min_y = min(y, min_y) max_x = max(x+w, max_x) max_y = max(y+h, max_y) roi = roi[min_y:max_y, min_x:max_x] cv2.imwrite("roi.png", roi)
Providing you with the following types of output images:

A...

The code works by first determining the largest contour area. A mask is created from this, which is used for the first selection of only the area inside, that is, the text. Then the inverse of the mask is added to the image to convert the area outside the mask to white.
Finally, outlines are again found for this new image. Any areas of the contour outside a suitable size range are discarded (this is used to ignore any small noise areas), and a bounding box is defined for each of them. With each of these rectangles, the outer bounding box for all other paths is calculated, and these values ββare cropped to give the final image.
Refresh . To get the rest of the image, i.e. with a remote scope, you can use the following:
image_src = cv2.imread("input.png") gray = cv2.cvtColor(image_src, cv2.COLOR_BGR2GRAY) ret, gray = cv2.threshold(gray, 10, 255,0) image, contours, hierarchy = cv2.findContours(gray, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE) largest_area = sorted(contours, key=cv2.contourArea)[-1] mask = np.zeros(image_src.shape, np.uint8) cv2.drawContours(mask, [largest_area], 0, (255,255,255,255), -1) image_remainder = cv2.bitwise_and(image_src, 255 - mask) cv2.imwrite("remainder.png", image_remainder)