SOFTWARE DEVELOPMENT FOR COLOURIMETRIC AND SPECTRAL DATA PROCESSING: PYCOLOURIMETRY

: Archaeological documentation is a complex process where the technical measurement and specification of colour is a key aspect. In the last years heritage documentation processes have largely benefited from the application of digital recording methods, imagery analysis software and technologies that offers great advantages over the traditional methods. The rigorous processing of colourimetric data requires software packages with specific colourimetric technical characteristics. In this paper we report on our in-house pyColourimetry software that was developed and tested taking into account the recommendations of the Commission Internationale de l'Éclairage (CIE). The objective is to apply a rigorous procedure for the characterisation of cameras based a priori on polynomial models. Most of the digital cameras capture colour information in the well-known RGB format, but the signals generated by the digital camera are device dependent. By means of the characterisation we establish the relationship between device dependent RGB values and the tristimulus coordinates defined by the CIE standard colourimetric observer. Once the camera is characterised, users have the potential to obtain output images in the sRGB space that is independent of the sensor of the camera. pyColourimetry software allows users to control the entire digital image processing and the colourimetric data workflow proposed. We applied the methodology on a set of pictures targeting Levantine rock art motifs in Cova dels Cavalls (Castellón, Spain) which is considered part of a UNESCO World Heritage Site. The outcomes obtained are satisfactory and very promising for proper colour documentation in cultural heritage estudies.


Introduction
Colour is a fundamental feature for proper cultural heritage documentation.The correct colour definition allows a more comprehensive graphic definition, a better understanding of the scene, and provides relevant technical information especially for study and preservation work (Ruiz and Pereira 2014).The problem is that colour is a matter of perception.Colour vision depends on the observer.A rigorous colourimetric technique is necessary to properly support rock art research (Korytkowski and Olejnik-Krugly 2017;Ohta and Robertson 2005).
More and more it is becoming frequent to combine classical documentation techniques based on perceptual procedures with rigorous procedures, supported by colourimetric measurements and digital images (Apollonio et al. 2014;Palomar-Vazquez et al. 2017).
Moreover, given the characteristics of archaeological rock art and the singularity of Levantine rock art in particular, a correct analysis of iron-based pigments is of great importance, where the colour is decisive.Such pigments show spectral properties that allow for their discrimination in the visible wavelengths (Hunt et al. 1971;Clark 1999).
A correct calibration of the imaging system, geometrically as well as radiometrically, is important in order to obtain reliable data and analyse the corresponding information.This fact is important for instance while documenting rock art (Sebastián et al. 2013).
The problem is that RGB signals generated by digital cameras are not colourimetrically sound, specifically, the output RGB values are device-dependent and do not directly correspond to the device independent tristimulus values based on the CIE standard colorimetric observer (CIE 2004).
An approach to transform RGB dependent values into a independent colour space (such CIE XYZ or sRGB which is somehow based on CIE XYZ), is the digital camera characterisation by polynomial regression with least squares fitting (Balasubramanian 2003;Westland et al. 2012;Malacara 2011).Once the RGB to CIE XYZ transformation equations are obtained, a conventional digital camera could be used for rigorous colour determination as if it were a colourimeter (Martínez-Verdú et al. 2003).
A final transformation from CIE XYZ to sRGB space is still necessary though.As a result, we obtain sRGB images in a well-known physically based colour space which can be rendered in compatible sRGB devices (International Electrotechnical Commission 1998).
Software systems with very specific characteristics are required to apply the methodological process exposed.There are different software options for the processing of colourimetric samples and digital image processing.One considerable limitation is that they generally do not allow the user to have absolute control on the methodological process, raw data management or output postprocessing.
We have developed our own software for the processing of colourimetric and spectral data, named pyColourimetry, which allows us to achieve a full control of the established methodological process.

Main features
The computer software pyColourimetry consists of a set of modules (based on the main CIE colourimetric technical recommendations) that allows users to process colourimetric data, obtain the transformation equations for the characterisation of the camera, and apply the equations on the image to yield images in the final sRGB space (Fig. 1).
The programming language used was Python, which has become a mature language and has all the features required for scientific computing (Oliphant 2007;Van Rossum and Drake 2010).
Python is an interpreted, multiplatform programming language and has a GNU general public license that guarantees end users the freedom to use, study, share and modify the software.The main functionalities of each module are listed in Table 1.Using the serialPort.pymodule, we can connect the CS-100A colourimeter according to the communication specifications of the manufacturer to retrieve colourimetric data.
Although there are Python libraries for colorimetric data processing, a module called myColour.pyhas been implemented to handle the main CIE colour spaces for the 2° standard observer and the D65 illuminant such as CIE XYZ, Yxy, RGB, CIELAB and CIELCH (CIE, 2004).
The camera characterisation process is carried out in two steps.First, nonlinearity correction of the pixel values is computed (linearity.py).In the second step, the coefficients of the RGB to CIE XYZ transformation equations are obtained from the selected patches of the colour chart (characterisation.py).
Once the characterisation is finished, we apply the RGB to CIE XYZ transformation equations on the input image.

Graphical User Interface
The main module of the pyColourimetry software is undoubtedly the graphical user interface (GUI) called gui.py.It allows the user to apply the methodological process in a controlled manner to collect colourimetric data, to extract RGB data (in different fimage formats, RAW, JPEG and TIF), to characterise digital cameras and finally to apply the polynomial equations to obtain images in the device independent colour system sRGB.
The GUI has been designed from the PyQt library, a multiplatform binding of the Qt graphical library for Python.It has been intended that the interface be simple, intuitive, easy-to-use and attractive with technical and professional appearance (Fig. 2).

Digital camera characterisation process
The standard way to correctly describe colours with digital cameras is by processing images after the colourimetric camera characterisation.In pyColourimetry we implemented the polynomial method because it gives substantially the same results as other methods and offers lower pre-processing and computational cost.
Results from previous experiences show that good results can be obtained using second order polynomial transformation equations (Westland et al. 2012;Balasubramanian 2003).
By means of the camera characterisation we establish the relationship between the device dependent RGB data and the tristimulus values defined by the CIE standard colourimetric observer.
In this process, we need several sets of samples with RGB data from the selected colour patches.A training sample will serve as reference for setting the characterisation parameter, which establishes the relationship between the RGB data and the CIE XYZ tristimulus coordinates.Additionally, a testing sample to evaluate the quality of the applied adjustments is required (Fig. 3).
In this study, we used the CIE XYZ colour space to set the transformation parameters RGB-CIE XYZ, and the CIELAB colour space for the analysis of the accuracy achieved with the polynomial adjustments.
Finally, once the transformation equations are determined, we can represent the output image in the sRGB colour space.

Case study
We applied the methodology on a picture shot on a rock art site, called Cova dels Cavalls (Tirig, Castellón), one of the most singular rock art caves of the Mediterranean Basin on the Iberian Peninsula (Fig. 4).This site was included in the UNESCO World Heritage list in 1998.The picture contained a colour chart which acts as colour reference.In this case study we used the X-write ColorChecker SG Digital Colour Chart with 140 colour patches.From the image of the rock art scene with the colour chart we need to extract the raw RGB data and obtain the polynomial parameters for the camera characterisation (Fig. 5).Once the parameters are calculated, we apply the RGB to CIE XYZ transformation equations on the input image.
A final transformation from CIE XYZ to sRGB space is still necessary to obtain the output image in a device independent, physically based colour space, which can be rendered in all devices compatible with the sRGB colour space.
Three polynomial models were considered: linear, second and third order (Westland et al. 2012).The number of coefficients to be determined is 3, 10 and 19, respectively, depending on the degree of the polynomial (Table 2).The pyColourimetry software provides statistical estimators and residuals to analyse the quality assessment of the applied adjustments.It allows users to select the optimum coefficients for the device characterisation as well.

Results
In order to evaluate the results obtained after characterisation, we analysed both the root mean square errors (RMSE) and ∆E #$ * mean colour differences for the three least squares adjustments using first, second and third order polynomials.The results obtained for each adjustment applied are shown in Table 3.
The lowest RMSE were found in the second order polynomial adjustment.Considering the RMSE values only, we could conclude that both the first and second order transformations offered similar results.On the other hand, the adjustment with the major RMSE errors is found in the third order transformation.
In addition to the RMSE errors it is required to analyse the values obtained for the colour differences.Values of ∆E #$ * colour differences less than 4 CIELAB units, can be considered to be hardly perceptible by the human eye (Mahy et al. 1994).In accordance with this last criterion, the optimal fit for the RGB to CIE XYZ transformation is the second order polynomial, where the mean colour difference is less than four CIELAB units (3.3 units).The third order transformation must be rejected due to the high value obtained in the RMSE errors (up to 6.3 in Z) and the ∆2 34 * colour differences (10.5 units).
Once the camera was characterised, we obtained output images in the sRGB space (Fig. 6).We can visually compare the results obtained for the three adjustments applied in a specimen of the original image corresponding to a deer (Fig. 7).The visual differences between the first and second order with third order transformations are clearly perceived.
The best results were obtained with the second order polynomial, where the mean colour difference was less than four CIELAB units.The pigment is clearly distinguished from the support.The third order polynomial is the one that offers the worst results.

Discussion
Given the importance of an accurate colour recording in rock art, it is necessary to perform the digital camera characterisation to register colours as close as possible to understand the true cultural heritage site conditions.
Different methods can be used to characterise digital devices, such as polynomial transformation, principal component analysis or artificial neural networks (Cheung et al. 2004;Vrhel and Trussell 1992).However, it is not Molada-Tebar, Lerma, Marqués-Mateu, 2017.This work is licensed under a Creative Commons 4.0 International License (CC BY-NC-ND 4.0) EDITORIAL UNIVERSITAT POLITÈCNICA DE VALÈNCIA usual to find software that simultaneously allows capturing raw RGB data, characterising digital cameras, and specially applying it on images to obtain output sRGB characterised images.
The results obtained in this case study showed that the proposed workflow for digital camera characterisation is adequate and takes into account the most important technical colourimetric aspects.The exposed methodology combines the direct method based on colourimetric measurements, and the indirect method using raw images with RGB information (Westland et al. 2012;Martínez-Verdú et al. 2003).The software developed in this study (pyColourimetry) covers each of the steps required for proper camera characterisation, and gives the user full control on the overall computation process.It also facilitates the data acquisition and measurement tasks as well as processing of colourimetric samples, setting the polynomial parameters, and applying them to finally obtain the output image in the sRGB space (International Electrotechnical Commission, 1998).We can calculate the numerical relationships between the RGB device dependent colour space and the standard CIE XYZ colour space.Once transformations parameters are determined a conventional digital camera can be used to determine rigorous object colours simulating a colourimeter.
With a second order polynomial characterisation, users can obtain accurate colour information, regardless the camera or sensor used in the data acquisition from welldefined colourimetric data using the pyColourimetry software.

Conclusion
The accurate description of colour is a key aspect in heritage documentation.In recent decades, the use of digital images in heritage documentation with tradicional methods has become more frequent.Its use is widely justified since it is a low-cost, non-invasive technique, and a fast method to record data.
In this paper, we showed that camera characterisation process whith pyColourimetry software allows the correct colour definition in a non-subjective way, following a low-cost solution for colour communication and dissemination.
The results are satisfactory and very promising for proper colour documentation in archaeological rock art studies.The colour registration in rock art scenes was considered correct, as well as the comparison of sets of pictures acquired under different lighting conditions by means of a physically based sRGB colour space.
Colour accuracy is measured by computing the CIE76 colour difference formula ∆E #$ * (CIE 2004) between the imaged results of the standard target patches and their theoretical colour values through Eq. (1):

Figure 4 :
Figure 4: Example of data acquisition on site in Cova dels Cavalls.Partial view of Shelter II.A single lens reflex (SLR) camera SIGMA SD15 was used to capture raw images.The main advantage of this camera is its three-layer Foveon®X3 direct image sensor.It directly collects all three primary RGB colours for each pixel without interpolation (Sigma Corporation 2010).

Figure 7 :
Figure 7: sRGB output images targetting a detail of an animal.

Table 1 :
Functionalities of the pyColourimetry software.

Table 2 :
Transformation coefficients matrix (first, second and third order).