Normalization of rgb images
07:00 22 May 2015

I am trying to remove the variation of illumination in two images. One of my approach is:

    1) There are two images im1 and im2. Extract the R G B content of im1.
    2)Calculate the normalized value for each content
    3)Reform a color image.
    4)Repeat the process for im2
    5)Compare each pixel and replace the content of im2 with im1.

Image_rgb = imread('aswathy_33_crop.jpg');
Image_rgb = double(Image_rgb);
figure;imshow(uint8(Image_rgb));

Image_red = Image_rgb(:,:,1);
Image_green = Image_rgb(:,:,2);
Image_blue = Image_rgb(:,:,3);


[row,col] = size(Image_rgb(:,:,1));

for y = 1:row 
for x = 1:col 
   Red = Image_red(y,x);
   Green = Image_green(y,x);
   Blue = Image_blue(y,x);


    if(Red == 0 && Green==0 && Blue==0)
        Red = 1;
        Green = 1;
        Blue = 1;
    end

      NormalizedRed = Red/(Red + Green + Blue);
      NormalizedGreen = Green/(Red + Green + Blue);
      NormalizedBlue = Blue/(Red + Green + Blue);

 Image_red(y,x) = NormalizedRed;
 Image_green(y,x) = NormalizedGreen;
 Image_blue(y,x) = NormalizedBlue;
   end
end
Image_rgb(:,:,1) = Image_red;
Image_rgb(:,:,2) = Image_green;
Image_rgb(:,:,3) = Image_blue;

new_image1 = cat(3, Image_rgb(:,:,1) ,Image_rgb(:,:,2), Image_rgb(:,:,3));

figure; imshow(uint8(255*new_image1));

This is just normalization of single image, which at the end crashes with a completely distorted image.Can anyone suggest where I am going wrong and whether my approach to this issue is right or not?

enter image description here

input1

enter image description here

input2

image matlab image-processing