## 3 The Lossless Image Compressor
### Proposed Lossless Algorithm
#### 3.2.1 RGB to YEF Conversion  
At this first stage of the algorithm, RGB pixels are converted to YEF color space [5], which is suitable for CE image compression and efficient for hardware implementation. The color space is designed by analyzing the unique properties of endoscopic images for better compression. The motivation for the YEF color space comes from the fact that, endoscopic images generally exhibit dominance in red color with the absence of significant green and blue components. Our experiments show that, in most cases, the intensity distribution of green in endoscopic images is very similar to that of blue component. Experiments have also shown that the intensity distribution of luminance (Y) has similar pattern of green and blue components - thus, subtracting green and blue components form the luminance will produce differential pixel values of almost equal numbers and will reduce the entropy of the chrominance planes. Reduced entropy will cause higher compression ratio in the chrominance planes. Conventional color spaces such as YUV and YCoCg do not exhibit such properties. In YEF, the luminance is stored in Y component, E stores the difference between luminance and green component, and F stores the difference between luminance and blue component. The relationships are shown in Equations (2)-(4). \[Y=\frac{R}{4}+\frac{G}{2}+\frac{B}{4} \tag{2}\]  
\[E=\frac{Y}{2}-\frac{G}{2}+128=\frac{R}{8}-\frac{G}{4}+\frac{B}{8}+128 \tag{3}\]  
\[F=\frac{Y}{2}-\left(\frac{3B}{8}+\frac{G}{8}\right)+128=\frac{R}{8}+\frac{G}{8 }-\frac{B}{4}+128 \tag{4}\]  
In Figure 3, two standard WLI and NBI endoscopic images are shown, taken from [19]. In Figure 4, the plots of all color component values of the WLI image (Figure 3a) are shown in grayscale with entropy (bits/pixel) mentioned. It can be seen from Figure 4 that, after converting to YEF, there is less change in pixel values in chrominance (E and F) components of YEF color space than RGB components, which indicates that less information or entropy is contained there and these two components can be compressed heavily. In Figure 5, the intensity distributions for the NBI image (Figure 3b) are shown and they also reveal that the chrominance components of YEF color space contain low information content or entropy. Figure 3: Sample endoscopy images: **(a)** WLI; **(b)** NBI. Note that, the YEF color space does not discard the chrominance information; in fact, it is another representation of the RGB color space which is more suitable for compression and theoretically lossless. The YEF color components can be converted back to RGB color components using Equations (5)-(7):  
\[R=Y+3.33\times\left(E-128\right)+2.67\times\left(F-128\right) \tag{5}\]  
\[G=Y-2\times\left(E-128\right) \tag{6}\]  
\[B=Y+0.67\times\left(E-128\right)-2.67\times\left(F-128\right) \tag{7}\]  
Figure 4: Intensity distribution of color components of a WLI image: (**a**) R, entropy: 6.15; (**b**) G, entropy: 6.74; (**c**) B, entropy: 6.53; (**d**) Y, entropy: 6.65; (**e**) E, entropy: 3.44; (**f**) F, entropy: 3.26. Figure 5: Intensity distribution of color components of an NBI image: (**a**) R, entropy: 6.80; (**b**) G, entropy: 6.73; (**c**) B, entropy: 6.68; (**d**) Y, entropy: 6.73; (**e**) E, entropy: 2.14; (**f**) F, entropy: 1.94. From Equations (2)-(4), it is observed that the conversion between color spaces involves only a few additions and divisions by numbers that are powers of 2, which can be implemented by shift operations in digital hardware. When Equations (2)-(4) are implemented in digital hardware as integers, minor variations in the pixel values may occur due to the rounding of fractions to integers. The YEF color space can be made fully reversible (_i.e._, reconstructed image is statistically identical with original image) by adding 3 more extra bits for storing fraction along with the 8 bits for integer. The average image quality of 100 endoscopic images (taken from [19]) are shown in Table 1 where the pixels are first converted from RGB to YEF and then converted back to RGB.