Image Blending

 

START

 

  • Image blending is the process to blend (mixing) two images.
  • One of the important application of image blending is to remove the artifacts while creating the panorama or stitching the images.
  • Image blending also used to add the object in background or fore ground in images/scenes.

 

Lets take the two images which we want to blend…..

input_image1
Input image 1
input_image2
Input image 2

 

Following are some of the image blending process :

Suppose first image is a and second image is b

1. Multiply  (darken) image blending:

darker
Figure. 1 Darken blending result

             

F_blend (a,b) = a *b 

Darken image blending is multiplication of  two images pixel by pixel. Result of blending will be darker compared to both input images as shown in above  figure .1

2. Screen or brighter image blending:

brighter
Figure.2 Screen image blending result

 

 F_blend (a, b) = 1 – (1-a)* (1-b)

Screen image blending is reverse process of darken image blending its make the image much brighter as shown in figure.2 so if in case we want dark area also be brighter we can use screen image blending .

3. Overlay Image blending :

overlay.JPG
Figure. 3 Overlay blending result

 

F_blend (a, b)   =          1 – 2* (1-a) * (1-b)  if  (a > .5)   else   2* a * b  

Overlay blending provide the results in which darker area will become more darker and brighter area becomes brighter on the basis of base image as shown in figure 3. The image in which we check condition is called the base image here we checked the condition on image a .

4. Weightage image blending : 

weightage

Figure. 4 Weightage image blending.

F_blend (a,b) =  (weight * a + (1-weight)*b ) /2

Weightage blending provide the weights to images and take the average of them. Figure 4 shows the weightage blending where the weight value is 0.5. Range of weight is 0 to 1.

5. Cross fading blending:

Cross fading is one of the most important blending used to smooth panorama images.

ramp1
Figure. 5 Ramp function for image

Figure. 5 shows we create the ramp function for input images where ramp intensity is 0 to 1 and width of the ramp is the part of image we want to blend.

ramp2
figure. 6 Blending with ramp function

We take two ramp images according to figure. 5 ad add them to get the result.

cross_fading
Figure.7 Cross fading blending result

We took full ramp to blend the image as shown in figure. 7 . In left most side image 1 effect is dominant and in right most side image 2 is dominant. In middle it will be average.

image_feathering.JPG
Figure.8

ramp2

Figure. 8  shows the image feathering by step function . Figure 8 we can apply the cross fading in  middle strip window to remove the sharp line you can see the result in Figure 9.

cross_fading2
Figure. 9 Cross fading to remove the artifacts

In some applications we create image pyramid and apply the cross fading in each gaussian and laplacian level and reconstruct the result. That is known as pyramid blending process.

 %%%%%%%%%%%%%%%%%%%% CODE START %%%%%%%%%%%%%%%%%%

clc % clear screen
clear all % clear all variable
close all % close all open window

img1 = imread(‘blend_image1.jpg’);
img2 = imread(‘blend_image2.jpg’);

img1 = imresize(img1,[480,640]);
img2 = imresize(img2,[480,640]);
figure, imshow(img1)
title(‘input imag1’)
figure, imshow(img2)
title(‘input imag2’)

img1 = im2double(img1);
img2 = im2double(img2);

[row,col,channel] = size(img1);

%% multiply darken image blending
darken_blend = img1.*img2;

figure, imshow(darken_blend,[])
title(‘darken blending result’)

%% screen brighter image blending.

brighter_blend = 1 – ((1-img1).*(1-img2));
figure, imshow(brighter_blend,[])
title(‘brighter blending result’)

%% weightage blending. weight 1 rang is (0 to 1)

weight1 = .5;
weight2 = 1 – weight1;

weightage_blend = (weight1.*img1 + weight2.*img2)/2;

figure,
imshow(weightage_blend);
title(‘weightage blending result’)

% overlay blending

%% initialize image
overlay_blending = zeros(row,col,channel);

%% assign the value only on index where img1 < .5
overlay_blending(img1<.5) = 2.*img1(img1<.5).*img2(img1<.5);
%% assign the value only on index where img1 > .5

overlay_blending(img1>.5) = 1 – (2.*(1-img1(img1>.5)).*(1-img2(img1>.5)));

figure, imshow(overlay_blending,[])
title(‘overlay blending result’)

%% cross fading blending

%% genrate ramp function which size is widt of image ( full ramp function)
ramp1 = (0:1/col:1);
ramp2 = (1:-1/col:0);

cross_fading = zeros(row,col,channel);

for cols = 1: col

%%% multiply the ramp function with image to get ramp image 1 and ramp image 2 and %%add them to get result
cross_fading(:,cols,:) = (ramp2(cols).*img1(:,cols,:) + ramp1(cols).*img2(:,cols,:));

end

figure, imshow(cross_fading)
title(‘cross fading blending’)

feathering = zeros(row,col,channel);

%% genrate step images and add them
feathering(:,1:col/2,:) = img1(:,1:col/2,:);
feathering(:,col/2:end,:) = img2(:,col/2:end,:);

imshow(feathering)
title(‘image feathering’)

ramp3 = (0:1/100:1);
ramp4 = (1:-1/100:0);

ground = zeros(1,(col/2)-50);
one = ones(1, (col/2)-50);

%% generate the ramp function for cross fading in middle of image with 100 pixel width.
function3 = [ground ramp3 one];
function4 = [one ramp4 ground];

feathering1 = zeros(row,col,channel);

%apply cross fading
for cols = 1: col

feathering1(:,cols,:) = (function4(cols).*img1(:,cols,:) + function3(cols).*img2(:,cols,:));

end

figure,
imshow(feathering1)
title(‘cross fadind result’)

%%% %%%%%%%%%%%%%%%% CODE END %%%%%%%%%%%%%%%%%%%%%

the_end1

happy_learning

Happy Learning

Cheers

 

 

 

 

lication

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s