How to obtain solid shape with adaptive threshold

275 Views Asked by At

Is it possible to get solid shape with adaptive threshold? In my case (A) I can only get hollow shape, but it seems like in some cases (B) it is possible to get solid shape. (see picture below) enter image description here What is the requirement of the input to achieve solid shape?

Below is my code for A

import cv2 as cv
import numpy as np
from matplotlib import pyplot as plt

img_path = 'F:\\Coding Stuff\\Python\\Projects\\Open CV\\'
img = cv.imread(img_path + 'test_1.jpg')
img_gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY)
thresh = cv.adaptiveThreshold(img_gray, 255, cv.ADAPTIVE_THRESH_GAUSSIAN_C, cv.THRESH_BINARY, 11,2)
cv.imwrite('output.jpg', thresh)

Here is the input picture
enter image description here

1

There are 1 best solutions below

0
Martin Pedersen On

I see this is an old post, but I think you can just detect the contours of the hollow shape and use polyfill to create a filled version of the detected shape.