- 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…..
Following are some of the image blending process :
Suppose first image is a and second image is b
1. Multiply (darken) image blending:
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:
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 :
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 :
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.
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.
We take two ramp images according to figure. 5 ad add them to get the 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.
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.
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]);
img1 = im2double(img1);
img2 = im2double(img2);
[row,col,channel] = size(img1);
%% multiply darken image blending
darken_blend = img1.*img2;
title(‘darken blending result’)
%% screen brighter image blending.
brighter_blend = 1 – ((1-img1).*(1-img2));
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;
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)));
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,:));
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,:);
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,:));
title(‘cross fadind result’)
%%% %%%%%%%%%%%%%%%% CODE END %%%%%%%%%%%%%%%%%%%%%