In this example, we will use a photograph of me, to try and reduce the red eye effect. In order to be able to use this tool in other photographs as well, we should make it as generic as possible.
First, we should write the following function in our editor (we'll call it
RedEyeReduction.m
):function output = RedEyeReduction(input, thresh) % Function for red eye reduction in input image % Inputs: % input - Input image % thresh – Threshold value in channel a* % Output: % output - Output image (after red-eye reduction) cform = makecform('srgb2lab'); % Make the transform structureimg_lab = applycform(input,cform); % Apply transform to L*a*b* eyes = roipoly(input); % Select area of eyes mask = (img_lab(:,:,2) > thresh) & (eyes > 0); % Red pixels in eyes % Split the three color channels R=input(:,:,1); G=input(:,:,2); B=input(:,:,3); R(mask) = round((G(mask)+B(mask))/2); % Replace R value with (G+B)/2 output = cat(3...