TEL AVIV UNIVERSITY FACULTY OF ENGINEERING SCHOOL OF ELECTRICAL ENGINEERING Computer Vision Final Project Balls recognition 2011 Blok Diagram Images RGB images uint8 RGB to HSV H/S double Calc Euclidean Dist for Red/Green/Yellow {Hue and Sat channels} R/G/Y double Apply Euclidean Dist Threshold R/G/Y logical Erosion R/G/Y logical Adaptive Color Filter R/G/Y logical OR Color Mask logical Filling Holes Color Mask logical Color Mask logical Val double Mult Val (ROI) double Erosion Of Artificial edges mask Edge Detection (Canny) Edge detection (ROI) double Radius of Max object double Edge detection (ROI) double Kernels Kernels logical Label Matrix double Mult Edge detection (ROI) double Loop Control Labeling Eroded Color Mask logical Adaptive XNormCorr (Run only on Kernels that less of radius of max object) Coor images double Find Coordinates of Max Corr value Find the best Kernel Flag Edge detection (ROI) double (After removing previous good candidate) Best Kernel Mask logical Pre-processing Flag Condition 1: Inside the kernel all 3 colors must present Bad candidate Pass Current Candidate Max Corr Val = 0 Flag Fail Bad candidate Condition 2: Inside the kernel must be only one object Pass Remove ROI of current candidate Bad candidate Flag Pass Plot Results Condition 2: Relative area of the Object to size of the kernel must be very high Good candidate Calc Radius of Max object Dilation Algorithm I will take one of the image as example for explanation my algorithm 1. Load original images Original 2. Load Ball Kernels Explanation: In my algorithm I use different size of Kernels to perform correlation with the image for reason to find the optimal ball looks like objects 3. Convert from RGB to HSV 4. Calculate Euclidean distance Explanation: Here I use Euclidean distance calculation for each color separately (Red, Green, and Yellow). The colors of the ball. As result I receive images where the darker pixel means that this pixel is closer to relative color 50 50 50 100 100 100 150 150 150 200 200 200 250 250 250 300 300 300 350 350 350 400 400 450 450 100 5. 200 300 500 600 400 450 100 200 300 400 500 600 100 200 300 400 500 600 Applying threshold on Euclidean distance images for each color separately Color Recognition RED 6. 400 Color Recognition GREEN Color Recognition YELLOW Erosion Explanation: Remove the noise after color recognition Color Recognition RED - eroded 7. Color Recognition GREEN - eroded Color Recognition YELLOW - eroded Adaptive color filter Explanation: Here I apply my adaptive color filter. The filter relates to all 3 colors and performs scanning on the window of 20 pixels. The filter scan each pixel in each color and looks if there is another colors in the window, if not – remove it. Color Recognition RED - eroded Color Recognition GREEN - eroded Color Recognition YELLOW - eroded 8. Combine all 3 colors together Color Recognition Adaptive 9. Fill the holes Filling the holes - adaptive 10. Dilation Explanation: Perform dilation to be sure that I’m not missing the borders of the object Dilation After filling - adaptive 11. Multiply Mask after color recognition with Gray level image (Val from HSV) Color Recognition ROI Fill+Dilate - adaptive 12. Erosion on {10} Explanation: In this step I perform erosion on dilated mask in the reason that in future step I will perform edge detection and all artificial edges of ROI I need to remove by applying this mask Color Recognition Erode on ROI 13. Edge detection (Canny) on {11} Edge of ROI 14. Multiplying {12} with {13} - removing artificial edges Edge of eroded ROI 15. Performing labeling of {12} Explanation: Here I perform labeling for future using and calculation the radius of max object 50 100 150 200 250 300 350 400 450 100 200 300 400 500 600 16. Performing adaptive xnormcorr with Ball Kernels {2} Explanation: Here I use the radius of the max object from {15} to determine the max kernel size that I need to apply, it reduces drastically time running of the code As output I receive vector of max corr values for each kernel MaxCorrVal = 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 58 58 61 67 63 60 102 93 97 99 93 94 87 94 80 94 89 81 78 80 83 78 93 87 73 98 120 95 85 76 81 77 75 76 72 72 71 77 Part of the values is zeros as result of applying adaptive algorithm 17. Find the best Kernel and find coordinates of the max corr val BallCoord = y: 297 x: 358 Correlation with Best kernel 18. Check 3 condition for valid candidate Explanation: Condition 1: Inside the kernel all 3colors must present Condition 2: Inside the kernel must be only one object Condition 2: Relative area of the Object to size of the Kernel must be very high If all conditions pass – save results and go to {19}, if fail – MaxCorrVal(i) = 0, take the next candidate. 19. After finding with success one ball remove the area of this ball and repeat from {16} to find another ball Edge of eroded ROI Before removing After removing 20. Plot/Save the results Explanation: After finding each ball I have few information about it: BallCoord – x,y coordinates of the balls BestKernelInd – index of best kernel for each ball BestKernel – best kernel for each ball I combine all those parameters for plotting Kernels on right position of the balls relative to founded coordinates Ball #1 - Kernel #43 Ball #2 - Kernel #47