Using OpenCV for Python, I am trying to get a mask of the noise elements in a image to be later used as input for the cv.inpaint()
function.
I am given a greyscale image (2D matrix with values from 0 to 255) in the input_mtx_8u
variable, with noise (isolated polygons of very low values).
So far what I did was:
- get the edges in which the gradient is above 25:
laplacian = cv2.Laplacian(input_mtx_8u, cv2.CV_8UC1)
lapl_bin, lapl_bin_val = cv2.threshold(laplacian, 25, 255, cv2.THRESH_BINARY)
- get the contours of the artifacts
contours, _ = cv2.findContours(lapl_bin_val, cv2.RETR_TREE, cv2.CHAIN_APPROX_NONE)
- fill the contours identified
filled_mtx = input_mtx_8u.copy()
cv2.fillPoly(filled_mtx, contours, (255, 255, 0), 4)
For some reason, my 'filled polygons' are not completely filled (see figure). What can I be doing wrong?