I am looking for a way to remove the black dots around the image border using OpenCV.
Image:
Expected solution:
import cv2
def get_img(img_name):
lower = (0, 0, 0)
upper = (75, 75, 75)
img = cv2.imread(img_name)
#print(img)
img_rgb_inrange = cv2.inRange(img, lower, upper)
neg_rgb_image = ~img_rgb_inrange
w = cv2.cvtColor(neg_rgb_image,cv2.COLOR_GRAY2RGB)
image3 = img-w
cv2.imwrite('img.png', image3)
get_img('address of the img')
I used the above code that I saw in link. The results are below:
output mask I got after running the code:
Final Output:
Wondering, is there any dynamic way (instead of initializing upper and lower bounds) where I can remove the noise from the image but still maintain my foreground and background?