Another area of image processing that has up to now been covered only for grayscale images is the one of contrast enhancement and handling of illumination problems. The basic method of generalization to color images is pretty much identical to all the other techniques presented in this chapter that is, repeating the grayscale process for all color channels. Since, the functions used in Chapter 2, Working with Pixels in Grayscale Images, for such tasks are used only for grayscale images (with an exception of imadjust
, which also does not work for color images without defining extra inputs), we will write a function that incorporates all the contrast enhancement techniques visited so far:
function output = ColorContrastEnhance(input, method) % Function for color contrast enhancement of input image % Inputs: % input - Input image % method – Enhancement method selection (0: histeq % 1: adapthisteq % 2: imadjust) % Output: % output - Output image (enhanced) output = input; switch method case 0 for i = 1:3 output(:,:,i) = histeq(output(:,:,i)); end case 1 for i = 1:3 output(:,:,i) = adapthisteq(output(:,:,i)); end case 2 for i = 1:3 output(:,:,i) = imadjust(output(:,:,i)); end end
Let's see if our function works as expected:
>> img = imread('Steps.bmp'), >> img1 = ColorContrastEnhance(img, 0); >> img2 = ColorContrastEnhance(img, 1); >> img3 = ColorContrastEnhance(img, 2); >> subplot(1,4,1),imshow(img),title('Original image') >> subplot(1,4,2),imshow(img1),title('Color histeq') >> subplot(1,4,3),imshow(img2),title('Color adapthisteq') >> subplot(1,4,4),imshow(img3),title('Color imadjust')
It is obvious that the histeq
and adapthisteq
functions lead to a color distortion in this case, so these methods should be very cautiously used in the case of per-channel processing of RGB color images. The imadjust
function, on the other hand, seems to work fine, producing an acceptable result.