The color distortion observed in the example of the previous section was caused by the high correlation between the R, G, and B channels in the case of the RGB image. This is another reason, why in many cases, a safer choice of color channel for color image processing tasks is CIE-L*a*b*. Let's try to alter the function written in the previous section, so that it converts the RGB input image to the CIE-L*a*b* color space, apply the chosen enhancement method only in the Lightness channel (so that the colors remain unaffected) and then transform the resulting image back to RGB:
function output = ColorContrastEnhanceLab(input, method) % Function for color contrast enhancement of input image in L*a*b* % Inputs: % input - Input image % method – Enhancement method selection (0: histeq % 1: adapthisteq % 2: imadjust) % Output: % output - Output image (enhanced) cform = makecform('srgb2lab'), % Make the transform structure img_lab = applycform(input,cform); % Apply transform to L*a*b* switch method % Apply chosen method in the Lightness channel (img_lab(:,:,1)) case 0 img_lab (:,:,1) = histeq(img_lab (:,:,1)); case 1 img_lab (:,:,1) = adapthisteq(img_lab (:,:,1)); case 2 img_lab (:,:,1) = imadjust(img_lab (:,:,1)); end cform = makecform('lab2srgb'), % Make the inverse transform structure output = applycform(img_lab, cform); % Apply transform to RGB
Now we can test our new function to see if our results have improved:
>> img = imread('Steps.bmp'), >> img1 = ColorContrastEnhanceLab(img, 0); >> img2 = ColorContrastEnhanceLab(img, 1); >> img3 = ColorContrastEnhanceLab(img, 2); >> subplot(1,4,1),imshow(img),title('Original image') >> subplot(1,4,2),imshow(img1),title('CIE – L*a*b* Color histeq') >> subplot(1,4,3),imshow(img2),title('CIE – L*a*b* Color adapthisteq') >> subplot(1,4,4),imshow(img3),title('CIE – L*a*b* Color imadjust')
Success! No color distortion this time. The adapthisteq
result also seems to have added more detail to the original photograph this time, enhancing the shadowed areas in a way that is quite pleasing to the eye.