I am having difficulties contouring this type of low-contrast objects:
Where I aim for an output such as:
In the example above I used cv2.findContours with a code as the one below, but using a threshold value of 105 ret,thresh = cv.threshold(blur, 105, 255, 0). However, if I reproduce it for the low-contrast image, I fail to find an optimum threshold value:
import numpy as np
from PIL import Image
import requests
from io import BytesIO
import cv2 as cv
url = 'https://i.stack.imgur.com/OeZJ9.jpg'
response = requests.get(url)
img = Image.open(BytesIO(response.content)).convert('RGB')
img = np.array(img)
imgray = cv.cvtColor(img, cv.COLOR_BGR2GRAY)
blur = cv.GaussianBlur(imgray, (105, 105), 0)
ret,thresh = cv.threshold(blur, 205, 255, 0)
im2, cnts, hierarchy = cv.findContours(thresh,cv.RETR_TREE,cv.CHAIN_APPROX_SIMPLE)
cv.drawContours(img, cnts, -1, (0,0,255), 5)
plt.imshow(img, cmap = 'gray')
I understand that the problem is that the intensity of the background and the object overlap, but I can't find any other successful method. Other things I've tried include:
- Thresholding, in
skimagewithskimage.measure.find_contours. - Watershed algorithm, in
opencv. - Eroding and dilating in
opencv, which lowers too much the contour resolution.
I would appreciate help to contour, with as much resolution as possible, this object with low contrast respect to the background.







