Рет қаралды 46,089
Often in machine vision we'd like to know how many objects are in our camera image. This video illustrates a popular algorithm that requires just two raster scans through the image, from Chapter 11 in "Robot Modeling and Control" by Spong, Hutchinson, & Vidyasagar. We first convert the image to greyscale, apply a threshold value chosen to minimize the within-group-variance, and then apply two raster scans to first assign labels to object pixels while generating an equivalency list, then a second raster scan to relabel all components according to the equivalency list.
Note: this video reveals that Fig. 11.3 is actually a dead dinosaur under a comet.
The image used is imRGB below, the thresholded values are imBW, the connected components are cc:
imRGB(:,:,1) =
153 153 153 153 153 153 153 153 153 153
153 127 127 93 153 153 152 153 153 153
153 127 108 69 153 152 156 152 153 153
153 93 69 93 153 153 152 153 153 153
153 153 153 153 153 153 153 153 153 153
153 153 153 153 0 153 153 0 0 153
153 153 153 153 0 153 153 34 0 153
153 153 153 153 34 185 185 34 0 153
153 34 34 34 34 34 34 34 0 153
153 34 0 34 34 0 0 0 0 153
181 181 198 181 198 181 181 181 181 181
imRGB(:,:,2) =
217 217 217 217 217 217 217 217 217 217
217 127 127 93 217 217 216 217 217 217
217 127 108 69 217 216 218 216 217 217
217 93 69 93 217 217 216 217 217 217
217 217 217 217 217 217 217 217 217 217
217 217 217 217 94 217 217 94 94 217
217 217 217 217 128 217 217 177 128 217
217 217 217 217 177 122 122 177 128 217
217 177 177 177 177 177 177 177 128 217
217 177 0 177 177 128 128 128 128 217
230 230 236 230 236 230 230 230 230 230
imRGB(:,:,3) =
234 234 234 234 234 234 234 234 234 234
234 127 127 93 234 234 233 234 234 234
234 127 108 69 234 233 234 233 234 234
234 93 69 93 234 234 233 234 234 234
234 234 234 234 234 234 234 234 234 234
234 234 234 234 47 234 234 47 47 234
234 234 234 234 64 234 234 76 64 234
234 234 234 234 76 87 87 76 64 234
234 76 76 76 76 76 76 76 64 234
234 76 0 76 76 64 64 64 64 234
29 29 81 29 81 29 29 29 29 29
imBW =
1 1 1 1 1 1 1 1 1 1
1 0 0 0 1 1 1 1 1 1
1 0 0 0 1 1 1 1 1 1
1 0 0 0 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 0 1 1 0 0 1
1 1 1 1 0 1 1 0 0 1
1 1 1 1 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 1
1 1 1 1 1 1 1 1 1 1
cc =
0 0 0 0 0 0 0 0 0 0
0 1 1 1 0 0 0 0 0 0
0 1 1 1 0 0 0 0 0 0
0 1 1 1 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 2 0 0 2 2 0
0 0 0 0 2 0 0 2 2 0
0 0 0 0 2 2 2 2 2 0
0 2 2 2 2 2 2 2 2 0
0 2 2 2 2 2 2 2 2 0
0 0 0 0 0 0 0 0 0 0