**3.2 Image acquisition and processing**

A digital image can be acquired either as monochrome (black and white) or color image using electronic equipment utilizing charge-coupled device (CCD) or complementary metal oxide semiconductor (CMOS) sensors.

These sensors use a two-dimensional array of millions of tiny light pixels to capture an image. These pixels collect photons and store them as an electrical signal after the shutter button of the camera is pressed which leads to the beginning of the exposure. The pixels are closed after the exposure finishes, and intensity value in the pixel is quantified as digital values by measuring the strength of the electrical signal, which is directly related with the number of photons stored in the pixel. However, this approach would only create a monochrome or gray scale image as the pixels are unable to distinguish photons in terms of color. A color filter needs to be placed over the pixel to capture a color image. This filter allows only one of the primary colors, that is red (R), green (G), or blue (B), to pass into the pixel, so that it stores only filtered photons for the respective color. In other words, the intensity of each pixel gives single color information which leads to a RAW image. Here, each pixel has only one of R, G, or B information while all R, G, and B values need to be known for each pixel. Therefore, demosaicing is applied to determine other two missing color values by interpolating from nearby pixels where those colors are known. After demosaicing, other methods such as white-balance, gamma correction, color space correction, and compression are applied to convert the image from RAW to a common format like JPEG.

JPEG images have a small size and they can be displayable instantly. However, there are some concerns because of the methods that are applied to convert an image from RAW to JPEG. In the conversion process, the image is compressed resulting in providing a non-linear RGB color space with only 8-bit color depth [43, 53]. However, RAW images contain original image data with 10–14 bits of color information. The conversion process corrupts the linearity of the image. A linear image conserves the relation between the intensity value and the number of photons which maintains the linearity with scene radiance. This linearity is required for quantitative scientific data acquisition in many applications [6, 30, 36, 37, 54]. As a linear image, the RAW format is therefore generally chosen. The main issue is

**75**

**4. Assay preparation**

*From Sophisticated Analysis to Colorimetric Determination: Smartphone Spectrometers…*

how to reach a RAW image in smartphones. Although most semi-professional and professional cameras have access to reach the images in a RAW format, it is unconventional for smartphones. With recent developments, the latest smartphones offer access to images in the RAW format [55]. The RAW images could be found in three extensions such as ".NEF" (Nikon), "CR2" (Canon), and ".DNG." The most used format is ".DNG" as it has a common open format. Currently, no app is available to process the ".DNG" images in a smartphone yet. Therefore, free DCRAW software [18] can be used to convert ".DNG" image to tagged image file format (TIFF) for

RGB is the most commonly used color model in image processing. However, it can be converted to other models such as hue, saturation, and value (HSV); hue, saturation, and lightness (HSL); hue, saturation, and intensity (HSI); and lightness, green-red, and blue-yellow (L\*a\*b\*). Hue is defined with the color portion of the color model and described with a number from 0 to 360°. Saturation is defined with the amount of gray in the color, from 0 to 100%. Value, lightness, or intensity is the brightness or intensity of the color, from 0 to 100% where black is represented with 0 while 100 is the brightest. After the image acquisition, numerous image processing methods can be employed to improve the image visualization so that better features can be extracted from the image. The feature extraction plays a critical role in some methods like PCA, convolutional neural network, and machine learning, which interpret multiple types of information contained in an image using these features [46]. The performance of these methods was investigated with RAW and JPEG image formats with different color spaces such as RGB, HSV, and L\*a\*b\*. RAW and JPEG image formats were studied in [6, 29] after converting images from RGB to HSV. Absorbance experiments were employed based on V components of HSV and it was reported that RAW format outperforms the JPEG formats in absorbance measurements. On the other hand, [41] showed that JPEG images gave a similar performance with RAM image if least-squares support-vector machine (LS-SVM) was employed in creating the learning model. Based on this conclusion, RGB, HSV, and L\*a\*b\* color spaces were investigated using JPEG formats for quantifying peroxide content based on machine learning classifiers [28]. JPEG images were also used in [45] where the images were converted from RGB to L\*a\*b\* color space. Instead of machine learning algorithms, color matching algorithms such as deltaE and color correlation methods were employed due to their simplicity. It was reported that deltaE showed superior performance with L\*a\*b color space for colorimetric water quality detection.

In previous sections, various hardware and software designs were introduced for smartphone-based spectrometer and colorimetry. These designs need to be tested under the conditions that users may encounter in real life. In this section, strip and assay preparations are introduced, which are commonly used for water quality and field tests. Colorimetric detection of pH values was studied in [41], which used pH strips to test their proposed system. First, solutions were prepared by mixing deionized water with sodium hydroxide (NaOH) and nitric acid (HNO3) to ensure the pH values in the range of 0–14.0. During the preparations, pH values were checked with a pH meter (HI 2223, Hanna Instruments, RI, USA) calibrated with standard buffers, pH 4.0 (HI 7004) and 7.0 (HI 7007) prior to using pH indicator strips (Merck, Germany). In addition, dual-illumination tests were performed with buffer solutions (4.0–9.0, Sigma-Aldrich, USA). Before imaging pH strips, they were immersed into the pH solutions for 5 s and wiped gently with tissue paper, so that

light refraction caused by the liquid drops could be minimized.

*DOI: http://dx.doi.org/10.5772/intechopen.82227*

easier extraction of the R, G, and B values of the image.
