overlapping skeletons of images

387 Views Asked by At

I did sketalization of images using morphology module of skimage. The output seems quite cool but I want the output to somehow be over my threshold/binary output so that I can confirm whether the output is accurate or not. I tried achieving this using PIL but in vain.

1

There are 1 best solutions below

5
Jeru Luke On

To keep things simple make a copy of the original image

result = img.copy()

Outline the skeleton as follows:

result[skeleton == 255] = (255,255,255)

Displaying result should give the expected output

UPDATE:

I have provided complete solution using OpenCV:

img = cv2.imread('object.jpg')

# convert to grayscale
g = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

# inverse binary image
th = cv2.threshold(g,0,255,cv2.THRESH_BINARY_INV+cv2.THRESH_OTSU)[1]

# obtain skeleton
sk = cv2.ximgproc.thinning(th, None, 1)  

enter image description here

# create copy of original image and superimpose the skeleton
result = img.copy()
result[sk == 255] = (255,255,255)

enter image description here

Result for an additional image shared recently:

enter image description here

Problems:

There are some problem as to why it doesn't work with your code:

  1. Your img is read as grayscale. The snippet result[sk == 255] = (255,255,255) expectes result to be 3-channel RGB/BGR image hence you face the value error.

  2. Another thing I noted is, using imread from skimage reads the image in float data type with pixel range 0 to 1.0. Later when you use skeleton = medial_axis(canny).astype(np.uint8) converts skeleton to int data type but also restricts pixel range from 0 to 1. As a result, even the portion expected to be in white is seen in black