A Simple Portable Colour Identification and Matching Instrument Using AVR Microcontroller and a Provotech Sensor

The identification of colours of objects is a much felt need in textiles, paint industries, cosmetics and so on. The complexity of identifying colour and its matching among several objects has been a requirement for common consumer outlets also. The paper discusses the principles of identifying and matching coloured objects. It uses a multi photo diode array based white balanced sensor from Provotech (India). We have been able to identify among twenty three different colours based on the Chromaticity co-ordinates precisely. The apparatus described is based on a simple embedded controller and the unit has its LCD display to indicate colour, hue and purity so that exact matching of coloured objects can be easily done.


Introduction
Colour is a very important parameter for many applications in consumer, industrial, textile, pharmaceutical and food products. Cotton, paints, fabrics-all need a fast and instant colour identification and indicating instrument. Hunterlab spectrophotometric systems [1] are leading colour measuring instruments at the high end. For point of sale textile and consumer shops, a simple and decisive instrument is a long felt need. Today colour measurement is a vital requirement for textile fabric colouring, extent of bleaching and colour printing on fabrics. Industrial robots have also been developed for colour measurement as reported in car paint technology [2]. This paper is a expected to meet this requirement using an Light Emitting Diode (LED) based photodiode colour sensor module from Provotech [3]. Measurement of colour has long been an intriguing problem because what the eye perceives is the criterion. The International Commission on Illumination Engineering (CIE) Committee in 1937, after extensive laboratory experiments by a selected group of observers using colorimeter, had developed the so called chromaticity diagram [4]. This has formed a basis for assessing colour for a nearly eight decades. W. D. Wright has described on measurement of colour about the so called tri-stimulus values [5]. By combining three colours in a calorimeter the experiments done in those days arrived at the representation of various colours by two co-ordinates X and Y in the chromaticity diagram, evolved by the CIE in the year 1937. The use of this diagram is not quite simple because the horse shoe shaped profile of this diagram ( Figure 1) is obtained by standard observers using colour mixing from three colour light sources.

Colour Identification with a Simple Sensor
Identifying colour differences using La-b and LC-H coordinates has also been listed in literature [6]. When it comes to grading and matching colour of an object such as paints, films, coatings, fruits etc., even the use of artificial neural networks have found their place [7]. However, it is easier to use the Chromaticity coordinates.
Today light sources based on Light emitting Diodes (LEDs) have the capability to surpass incandescent, halogen, gas discharge tubes. Photo diodes with paint tinting are used in RGB colour sensing. The Provotech sensor [2] used in this work makes use of one such simple module with 4 white LEDs at its four corners. It houses on its printed circuit board, three tinted photo diodes to give three signals detected by the photo diodes. Michel Vik in his paper in the Journal of Natural fibres [8], has brought out the usefulness of white LEDs of white light having a wide spectrum as shown in figure 2 as a suitable source for color sensors. The spectrum of white LED has a peak at 465nm due to its GaN junction and one other broad peak from 500 to 700nm corresponding Phosphorus doped junction [9]. So, the outputs from the three photo diodes are balanced by resistor networks in the sensor for white colour balance. That is, if white object is kept, the three tri-stimulus R, G, B readings are all equal to 0.33. Any object kept over the sensor will reflect the LED light and based upon its colour, the three photo diode signals infer the Red, blue and green content of the light reflected from the object. The colour sensor provides with its 5V supply, signals from the photo diodes in the range of 0 -0.5V. These values are read by ADC in a microcontroller. The ATmega 328 is a fairly powerful chip with ADC channels and with a crystal of 16 MHz has a processing speed of 16 MIPs. The entire instrument is constructed so as to provide an instant display of the several colours classified in 23 categories as shown by the following indices. These are the colours noted in the C. I. E. figure 1. Since the C. I. E. diagram makes use of XY coordinates based upon the tri-stimulus red and green components, the microcontroller reads the R, G, B reflectance values and evaluates the object's chromaticity coordinate values [7] ro, go by the very simple formulae, The R, G, B values are the Analog to digital converter readings taken by the microprocessor from the sensor outputs. The r o and g o are the chromaticity co-ordinate values. Because the processor can make a large number of measurements in a second, the values are easily averaged to get the RGB and evaluate using the above formulae fairly accurately. Thus, keeping the coloured object above the sensor at a short distance of about 1cm is sufficient to get the reflected colour values for calculation in the equation above. Using the X and Y values, one can look up the figure 1, to get the colour of the object. In the instrument, however, this is done by the program itself. The program searches the least distance colour by numerically evaluating the distances to all the points in the coloured region and finding that which is the least distant one. We have the values of the marked points x i, y i as given in the table above.
calculates the index i. That point indicates the colour index.
Indices are used to mark the colours from 1 to 23 including white and the value of the index corresponds to the minimum distance region to the observed coordinates values with the CIE diagram's chosen co-ordinates. As seen from figure 3, the red crossed marks in the several coloured regions are chosen near the white light demarcating ellipse. This is because most of the reflected light from an actual object is mixed with a considerable amount of white light. In other words, they are not pure colours but have a high percentage of saturation with white light. It may be seen that the CIE figure (figure 1) that yellow colour (518nm) is a most difficult one to identify. For that matter, if the instrument is able to detect this colour correctly and display it on the LCD display, then it can be considered as a good proof of its usefulness in colour sensing.

Hue and Saturation Determination
When comparing two coloured objects, the measurement of distance between their XY coordinates x1y1 and x2, y2 may not suffice. That is because, even a unit change in any one value can shift the colour region in the C. I. E. diagram.
Hue and saturation are the two standard parameters that may be more useful for matching. Hue saturation and brightness are aspects of colour in the red, green blue schemes. Hue is the wavelength in the visible light region at which the energy output is maximum. This is shown as the peak of the curve in a graph of wavelength versus intensity.
Saturation is defined as the relative bandwidth of the visible output from a light source. So the chromaticity diagram is observed to be having marks of the hue as spectral wavelengths over its periphery, commencing from 415 nm in the purple blue region through 520nm in the green region and to 615 nm in the red region. There are about 17 marks of such wavelengths shown in figure 1.
Taking the centre point of the white light ellipse as a new origin (Figure 4), if one draws straight lines of the wavelength marking hue points, then, there would be 17 lines in the diagram. The co-ordinates of these points are listed in table 2 and used by the program. These lines indicate the regions of colours commencing from the pure spectral colour (such as a RED laser colour) to different white mixed colour gradations of more and more saturation. Supposing the X and Y coordinates of the measured object's chromaticity co-ordinate value is marked on the diagram, and the distances to all the 17 straight lines evaluated from it, then the line which is at the least distance is the line representing the colour of the object (figure 8). So, the foot of the perpendicular from the X, Y coordinates of the object to such a line will be indicating the relative saturation or whiteness of the colour, while the line itself will indicate the hue as so many nanometers. In the case of the co-ordinates of our object falling within the lower triangle shown in figure 5, the colour is the purplish colour which is the complement of the line's hue, as shown marked as 540c, to mean complement [5].
Therefore, a method to determine automatically if the point (r, g) falls within this purple triangle is needed. For this, three new p coordinates are formed as a linear combination of the corner points of the triangle, having the co-ordinates (x 1 , y 1 , x 2 , y 2 , x 3 , y 3 ) as (0.17, 0; 0.73, 0.25; 0.33, 0.33). If we define 3 scalars a, b, c such that we can express the point being checked (x, y) to be within the triangle, then three equations are got as: x = a * x1 + b * x2 + c * x3 y = a * y1 + b * y2 + c * y3 (4) a + b + c = 1 The (x1, y1), (x2, y2) and (x3, y3) are the corners of the lower triangle of the chromaticity diagram. (x, y) is the point under investigation for checking whether it lies within or outside this triangle.
The way to compute a, b, c is by solving the simultaneous equations. a = ((y2 -y3)*(x -x3) + (x3 -x2)*(y -y3)) / ((y2 -y3)*(x1 -x3) + (x3 -x2)*(y1 -y3)) b = ((y3 -y1)*(x -x3) + (x1 -x3)*(y -y3)) / ((y2 -y3)*(x1 -x3) + (x3 -x2)*(y1 -y3)) Since the denominator is a pre-determined value in the above equations, the pre-calculated values are: For instance, two fabric pieces, when viewed in sufficiently rich white light, may have different hue values., such as 500, 510, 520 or 530nm, though all of them come under the category of green colour. So, for exact matching of colours of two specimens, say cloth, the instrument is able to display the hue and the saturation values. This will help to sufficiently reasonably match within the same colour range. Next to green comes yellow green colour in the CIE diagram and the transition from yellowish green to yellow green occurs between 550 and 570 nm. So it is possible to display the line of the hue of the object in XY value fairly correctly and matching will mean nearness in hue and saturation, both [6]. The applications of such a compact portable stand alone colour monitoring instrument are many [7].
The color's saturation [9] and purity are given by the formulae where s is the distance as marked on the line near to the object's x, y coordinates and D is the total length of the line itself (vide figure 5). The foot of the perpendicular from P (x 0 , y 0 ) to the hue line (ax + by+ c)=0 has the co-ordinates as given by The distance s from the foot to the white point gives the purity of the colour. This can be calculated by the formula for the distance between two points as In this, w x and w y are the white centre co-ordinates (0.33, 0.33). So the program calculates, using the eqn. (7), and indicates the hue and saturation percentage from the two colour sensors on the two rows, providing a quick assessment of the matching.
The co-ordinate values of the several hue points shown in the chromaticity diagram are given in table 2. The several straight lines are calculated are shown in the values represented by the following equation (10) From eqn (3), the perpendicular distance d to the hue lines is to be found.

Description of the Circuit for Colour Identification and Matching
The circuit shown in figure 6 is apparently simple. It uses the AVR ATmega 328 chip. The colour sensor module outputs RGB values which are connected to ADC 0-2 and 3-5 of the chip. The V REF pin of the chip is left open because the program chooses the internal band gap voltage reference of 1.1V to be more precise in the ADC values. Thus, there is no need to amplify the color sensor signals. That is important because the output R, G, B values of the ADC are d. c. signals and amplification will be affected by drift. Since the voltages available form the sensor are within 1 Volts only, use has been made of the option of selecting the internal 1Volt ADC reference voltage in this software. Therefore, the readings are having sizable values without any amplification requirement from the sensor.
The two row character display module is interfaced to the chip using 4 bits for data and three other bits for the Register Select, Write and Enable signals. The LCD data is therefore written twice, 4 bits at a time, by the write commands for any command to the LCD module from the chip. The chip uses a 16MHz crystal as shown. The chip is programmed by an AVR programmer.
Further to the colour identification program, for colour matching applications, it might be required to compare two objects such as two pieces of fabrics or painted surfaces and the like.
So, a second colour sensor module of an identical type is needed. The second sensor is shown interfaced to the remaining ADCs in the chip (ADC3, ADC4 and ADC 5). The photographs shows the unit, which indicates the instrument displaying certain coloured objects for testing (figure 7). Photograph showing some objects and displaying their Hue and Purity in figure 8.
The code of the program is developed by us using high level Basic language in the OSHON simulator [10] for AVR microcontroller; the flow chart of the program is given in figure 9. Flow chart for hue and purity measurement is given in figure 10.

Conclusions
A portable, compact and economical multi colour sensor for colour identification and matching has been described. It was used to test samples of various objects described in the paper. The results were found to be satisfactory. The basic instrument which is a portable and battery operated one can be useful anywhere such matching of coloured objects have a purpose, as in textiles, paints and food products. Using the colour sensor cited before, with programs for fixing the colours on the CIE diagram from the measured outputs of the colour tinted photo diodes, it is possible to detect not merely industrial objects but also burn wounds under prophylaxis. Particular mention should be made about the simplicity, compactness and battery operability of this module. Ease of software development with IDE OSHON Software with Computer communication via serial communication interface. Thus, unattended identification in mass production can be achieved for so many colours, which is a novel and