You are on page 1of 3

Image arithmetic applies one of the standard arithmetic operations or a logical operator to two or

more images. The operators are applied in a pixel-by-pixel way, i.e. the value of a pixel in the
output image depends only on the values of the corresponding pixels in the input images. Hence,
the images must be of the same size. Although image arithmetic is the most simple form of
image processing, there is a wide range of applications. A main advantage of arithmetic
operators is that the process is very simple and therefore fast.

Logical operators are often used to combine two (mostly binary) images. In the case of integer
images, the logical operator is normally applied in a bitwise way.

clear all;
close all
img1=imread('image1.jpg');
img2=imread('image2.jpg');

% displaying images

subplot(1,2,1);
imshow(img1);
title('image 1');
subplot(1,2,2);
imshow(img2);
title('image 2');

% adding scalar value to the image%


figure
addimg1=imadd(img1,200);
addimg2=imadd(img1,55);
subplot(1,2,1);
imshow(addimg1);
title('200 added to image');
subplot(1,2,2);
imshow(addimg2);
title('55 added to image');
figure
% adding two images
imadd=imadd(img1,img2);
subplot(1,2,1);
imshow(imadd);
title('adding two image');

% normalized image addition

W=uint16(img1)+uint16(img2);
Wmax=max(W(:));
Wmin=min(W(:));

normaziled=uint8(255*double(W-Wmin)/double(Wmax-Wmin));
subplot(1,2,2);
imshow(normaziled);
title('Normalized Image Addition');
2.
clear all;
close all
img1=imread('image1.jpg');
img2=imread('image2.jpg');

% substracting scalar value to the image%


figure
subimg1=imadd(img1,-200);
subimg2=imadd(img1,-55);
subplot(1,2,1);
imshow(subimg1);
title('200 substracted from image');
subplot(1,2,2);
imshow(subimg2);
title('55 substracted from image');
figure
% substraction of two images
imsub=imsubtract(img1,img2);
subplot(1,2,1);
imshow(imsub);
title('substraction of two image');

% Absolute Difference technique to overcome overflow


abimg=imabsdiff(img1,img2);
subplot(1,2,2);
imshow(abimg);
title('Absolute Difference');

3. clear all;
close all
img1=imread('image1.jpg');
img2=imread('image2.jpg');

% multiplying image by scalar value%


figure
multimg1=immultiply(img1,.5);
multimg2=immultiply(img1,2);
subplot(1,2,1);
imshow(multimg1);
title('image1 multiplied by 0.5');
subplot(1,2,2);
imshow(multimg2);
title('image1 multiplied by 2');
figure
% multiplication of two images
immulti=immultiply(img1,img2);
subplot(1,2,1);
imshow(immulti);
title('multiplication of two image');
% Normalization to overcome overflow
W=immultiply(uint16(img1),uint16(img2));
Wmax=max(W(:));
Wmin=min(W(:));
normalized=uint8(255*double(W-Wmin)/double(Wmax-Wmin));
subplot(1,2,2);
imshow(normalized);
title('Normalized Image');

You might also like