0

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

Wayne Lin
  • 45
  • 7
  • Could you show some code? – Tarik Nov 04 '20 at 15:28
  • @Tarik, thanks for the reply! The images from case B are taken from Google search, and both of them are products of image processing softwares, so I don't have code for them. https://sites.google.com/site/qingzongtseng/adaptivethreshold http://www.roborealm.com/help/Adaptive_Threshold.php The code for case A is just a simple call to the function of cv2.adaptiveThreshold in Python. I'm in office now, and the Python script is in my personal PC, I will add it later. – Wayne Lin Nov 05 '20 at 01:48

1 Answers1

0

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.