(image, size, structuring=cv2.MORPH_RECT)
| 94 | return resized |
| 95 | |
| 96 | def skeletonize(image, size, structuring=cv2.MORPH_RECT): |
| 97 | # determine the area (i.e. total number of pixels in the image), |
| 98 | # initialize the output skeletonized image, and construct the |
| 99 | # morphological structuring element |
| 100 | area = image.shape[0] * image.shape[1] |
| 101 | skeleton = np.zeros(image.shape, dtype="uint8") |
| 102 | elem = cv2.getStructuringElement(structuring, size) |
| 103 | |
| 104 | # keep looping until the erosions remove all pixels from the |
| 105 | # image |
| 106 | while True: |
| 107 | # erode and dilate the image using the structuring element |
| 108 | eroded = cv2.erode(image, elem) |
| 109 | temp = cv2.dilate(eroded, elem) |
| 110 | |
| 111 | # subtract the temporary image from the original, eroded |
| 112 | # image, then take the bitwise 'or' between the skeleton |
| 113 | # and the temporary image |
| 114 | temp = cv2.subtract(image, temp) |
| 115 | skeleton = cv2.bitwise_or(skeleton, temp) |
| 116 | image = eroded.copy() |
| 117 | |
| 118 | # if there are no more 'white' pixels in the image, then |
| 119 | # break from the loop |
| 120 | if area == area - cv2.countNonZero(image): |
| 121 | break |
| 122 | |
| 123 | # return the skeletonized image |
| 124 | return skeleton |
| 125 | |
| 126 | def opencv2matplotlib(image): |
| 127 | # OpenCV represents images in BGR order; however, Matplotlib |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…