This article gives an approach to identify basic geometric shapes and primary RGB colours in a 2 dimensional image using image processing techniques with the help of MATLAB. The basic shapes included are square, circle, triangle and rectangle. The algorithm involves conversion of RGB image to grey scale image and then to black and white image.
This is achieved by thresholding concept, The area of the minimum bounding rectangle is calculated irrespective of the angle of rotation of the object and ratio of this area to area of the object is calculated and compared to the predefined ratio to determine the shape of the given object. The dominant colour pixels present helps to determine the colour of the object. The practical aspects of this include reducing the manual labour in industries used to segregate the products and providing real time vision to the robots.
Table of Contents
Introduction to Colour Detection using Image Processing
As we progress and develop technology changes rapidly. New methods are being employed in industrial manufacture and inspection every day. There was a time when manual labour was in much demand in the industries for jobs like packaging inspection etc. which are a repetitive process. Now it is time for automated machines to take over these simple jobs and make them more efficient.
The sensors are one of the most important part of automation. They provide inputs for the controllers to take action based upon the inputs received. Various kinds of sensors like temperature sensor, humidity sensor, infrared, ultrasonic sensor, camera etc. are easily available in market. High precision is required for better feedback.
Cameras are used for Image Processing which finds huge application in the field of automation industry. It captures the images or streams live video and then they are processed as per the needs of the application. This project attempts at demonstrating the shape and colour recognition of an object using an algorithm which will be explained in detail. This algorithm is realized with the help of matlab.
Literature Survey about Image Processing
There are many ways for detecting shapes and colour of objects which has been introduced previously. The procedure which is followed in this process are explained in detail in [1]. It tells regarding conversion of RGB image to grey scale image and then to black and white (binary) image and much more. Moreover the study of shape recognition can be found in [2]. Shape recognition consists of methods like thresholding, segmentation, bounding box calculation can be referred through [3]. Detailed algorithm and flowchart are referred from [4]. Colour recognition involves comparison of each pixel in the metric and results in the dominant colour as the colour of the given object which is very well explained in [5].
Flowchart of Colour Detection

Flowchart of Shape Detection

Algorithm
Step 1: Read the input Image
Any RGB Image is captured and loaded in matlab Each pixel of the RGB image is in the form of element of the matrix.Fig.1 shows the input image.


Step 2: Conversion of RGB image to gray scale and then to binary image using Thresholding process.
RGB image is converted to gray scale using the instruction “rgb2gray (A)”, where A is the input matrix.Fig.2 shows gray scale image.
Gray scale image is converted to binary using Thresholding process which is as follows:-
Each pixel value is compared with the preset Threshold value. If it is greater than the Threshold value then the value is replaced by “1” which represents white, else replaced by ”0” which represents black.Fig3.shows black & white image.


Step 3: Detection of the boundary of the object The 3D input image which has already been converted into 2D array. One of the pixel is taken as a reference and moving in a fixed direction to detect other object pixels. Hence the boundary of the object is detected.
Step 4: Finding bounding box of the given object. Bounding box is an imaginary rectangle enclosing the given object. Because of inclination of the object, the size of the bounding box changes. If the object is inclined at some angle the box is rotated by angle of inclination and made parallel to the object axis.Fig.4 shows the bounding box of the shapes.
Step 5: Area of the object The area of the object can be calculated by the summation of pixels within the boundary of the object.
Step 6: Ratio The ratio of area of the object to the area of bounding box is calculated.
Ratio = area of object/area of bounding box
Step 7: Comparison of the calculated ratio The calculated ratio is compared with the predefined values to determine the shape of the given object.Fig.5 shows shape detection.


Step 8: Colour detection
Read the image and construct the matrices for Red, Green and Blue. All the pixels are compared with each other. If the red color matrix have positive value and others are zero then that object is detected as red. Similarly the procedure is repeated for Green and Blue objects. Finally each color Image is displayed separately.Fig.6,7&8 shows Red, Green & Blue objects respectively.


Conclusion
Number of images are tested and proved to be 95% accurate. Image should be clear and shadows must be avoided, in order to avoid changes in threshold value.
This can be used in any field where shape or colour recognition comes into picture.eg: medical science, traffic signals etc. It has got many future scopes using many other advance methods. Overlapped object detection is also possible.
References
[1]. Digital image processing using Matlab -Gonzalez woods & Eddins.
[2]. M.Hagedoom,”Pattern matching using similarity measures”, PhD thesis, Universiteit Utrecht, 2000.
[3]. Shalinee Patel,Pinal Trivedi and Vrundali Gandhi,”2D Basic Shape Detection Using Region Properties”,International Journal of Engineering Research & Technology, Vol.2,no.5,pp.1147-1153,May 2013.
[4]. 2D geometric shape and color recognition using digital image processing,International Journal of Advanced Research in Electrical,Electronics and Instrumentation Engineering Vol 2,Issue 6,June 2013.
[5] Color image processing using principle component analysis by Arash Abadpour.
If you have any questions about this, Please Contact Us.