This is our image processing homework, I know that we have to use morphological methods,and some cv2 methods like threshold , and we have to work on it as a colorful picture cause in Gray scale we will lose some information which we need. We have to work on the attached photo input pic so we will have output photo this in output.
I'll appreciate any help
import cv2
import numpy as np
import matplotlib.pyplot as plt
img=cv2.imread('shapes.jpg')
img= cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
hist=cv2.calcHist(img,[0],None,[256],[0,256])
ret,img=cv2.threshold(img,110,255,cv2.THRESH_BINARY_INV)
#th=cv2.adaptiveThreshold(img,100,cv2.ADAPTIVE_THRESH_MEAN_C,cv2.THRESH_BINARY_INV,16,5)
se=np.uint8([[-1,0,1],[-1,0,1],[-1,0,1]])
se=np.ones(5*5)
se=cv2.getStructuringElement(cv2.MORPH_RECT,(15,5))
img=cv2.morphologyEx(img,cv2.MORPH_CLOSE,se)
img=cv2.erode(img,se)
#plt.plot(hist)
plt.gray()
plt.imshow(img)
plt.show()