Edge tracking. Usually a weak edge pixel caused from true edges will be connected to a strong edge pixel while noise responses are unconnected. As long as there is one strong edge pixel that is involved in its 8-connected neighborhood, that weak edge point can be identified as one t
(image_shape, destination, weak, strong)
| 92 | |
| 93 | |
| 94 | def track_edge(image_shape, destination, weak, strong): |
| 95 | """ |
| 96 | Edge tracking. Usually a weak edge pixel caused from true edges will be connected |
| 97 | to a strong edge pixel while noise responses are unconnected. As long as there is |
| 98 | one strong edge pixel that is involved in its 8-connected neighborhood, that weak |
| 99 | edge point can be identified as one that should be preserved. |
| 100 | """ |
| 101 | for row in range(1, image_shape[0]): |
| 102 | for col in range(1, image_shape[1]): |
| 103 | if destination[row, col] == weak: |
| 104 | if 255 in ( |
| 105 | destination[row, col + 1], |
| 106 | destination[row, col - 1], |
| 107 | destination[row - 1, col], |
| 108 | destination[row + 1, col], |
| 109 | destination[row - 1, col - 1], |
| 110 | destination[row + 1, col - 1], |
| 111 | destination[row - 1, col + 1], |
| 112 | destination[row + 1, col + 1], |
| 113 | ): |
| 114 | destination[row, col] = strong |
| 115 | else: |
| 116 | destination[row, col] = 0 |
| 117 | |
| 118 | |
| 119 | def canny(image, threshold_low=15, threshold_high=30, weak=128, strong=255): |