Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to skeletonize an image after adaptive gaussian thresholding

Hi,

I would like to skeletonize an image after applying adaptive gaussian threshold. I have searched "How to skeletonize an image" and I have found a solution in this link. However, this solution is applying global threshold on an image. I want to apply adaptive gaussian threshold and after that, I want to get skeletonized image. Is there a solution, link or an article about my question?

Best regards, Ender.

How to skeletonize an image after adaptive gaussian thresholding

Hi,

I would like to skeletonize an image after applying adaptive gaussian threshold. I have searched "How to skeletonize an image" and I have found a solution in this link. However, this solution is applying global threshold on an image. I want to apply adaptive gaussian threshold and after that, I want to get skeletonized image. Is there a solution, link or an article about my question?

Here is my code;

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

image = cv2.imread('maze.png')
plt.hist(image.ravel(),256,[0,256]); plt.show()
img_gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
img_gray_histeq = cv2.equalizeHist(img_gray)

binarized_image = cv2.adaptiveThreshold(img_gray_histeq,255,cv2.ADAPTIVE_THRESH_GAUSSIAN_C,\ cv2.THRESH_BINARY,11,2)

"""
PLOTS
"""
cv2.imshow('Gray Scale Image', img_gray)
cv2.imshow('Histogram Equalized Image', img_gray_histeq)
cv2.imshow('Binarized Image', binarized_image)

cv2.waitKey(0)
cv2.destroyAllWindows()

Best regards, Ender. Ender.

How to skeletonize an image after adaptive gaussian thresholding

Hi,

I would like to skeletonize an image after applying adaptive gaussian threshold. I have searched "How to skeletonize an image" and I have found a solution in this link. However, this solution is applying global threshold on an image. I want to apply adaptive gaussian threshold and after that, I want to get skeletonized image. Is there a solution, link or an article about my question?

Here is my EDITTED code;

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

image = cv2.imread('maze.png')
plt.hist(image.ravel(),256,[0,256]); plt.show()
img_gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
img_gray_histeq = cv2.equalizeHist(img_gray)

size = np.size(img_gray_histeq)
skel = np.zeros(img_gray_histeq.shape,np.uint8)

binarized_image = cv2.adaptiveThreshold(img_gray_histeq,255,cv2.ADAPTIVE_THRESH_GAUSSIAN_C,\ cv2.adaptiveThreshold(img_gray_histeq,255,cv2.ADAPTIVE_THRESH_GAUSSIAN_C,\
            cv2.THRESH_BINARY,11,2)

element = cv2.getStructuringElement(cv2.MORPH_CROSS,(3,3))
done = False

while( not done):
    eroded = cv2.erode(binarized_image,element)
    temp1 = cv2.dilate(eroded,element)
    temp2 = cv2.subtract(binarized_image,temp1)
    skel = cv2.bitwise_or(skel,temp2)
    img = eroded.copy()

    zeros = size - cv2.countNonZero(binarized_image)
    if zeros==size:
        done = True

"""
PLOTS
"""
cv2.imshow('Gray Scale Image', img_gray)
cv2.imshow('Histogram Equalized Image', img_gray_histeq)
cv2.imshow('Binarized Image', binarized_image)
cv2.imshow("skel",skel)

cv2.waitKey(0)
cv2.destroyAllWindows()

Best regards, Ender.