To extract you can use OpenCV Grab Cut >
A example can be seen in the "Interactive Foreground Extraction using GrabCut Algorithm" tutorial
Code
Using the example code:
import numpy as np
import cv2
from matplotlib import pyplot as plt
img = cv2.imread('C:\Users\Desktop\teste\FHB9o.jpg')
mask = np.zeros(img.shape[:2],np.uint8)
bgdModel = np.zeros((1,65),np.float64)
fgdModel = np.zeros((1,65),np.float64)
rect = (10,10,45,45)
cv2.grabCut(img,mask,rect,bgdModel,fgdModel,5,cv2.GC_INIT_WITH_RECT)
mask2 = np.where((mask==2)|(mask==0),0,1).astype('uint8')
img = img*mask2[:,:,np.newaxis]
cv2.imshow('Imagem', img)
cv2.waitKey(0)
cv2.imwrite('C:\Users\Desktop\teste\resultado.jpg', img)
plt.imshow(img),plt.colorbar(),plt.show()
Result
Note
In this case, the rectangular ROI (Region of Interest) is fixed. If the images have variation in the location of the object that needs to be extracted, a dynamic ROI needs to be created, where the contours will be the points that will determine the coordinates of dynamic ROI.