image arithmetic operations in matlab

Image arithmetic operations in matlab

% img add by constant factor

I = rgb2gray(imread(‘lena.bmp’));

J = imadd(I,50);

subplot(1,2,1), imshow(I)

subplot(1,2,2), imshow(J)

%%—————– Image Addition

close all;

I1=imread(‘back.bmp’);

I2=imresize(I1,[500 500]);

I3 = I2;I1=imread(‘car.bmp’);

I2=imresize(I1,[500 500]);

I4 = I2;

J = imadd(I3,I4);

subplot(1,3,1), imshow(I3)

subplot(1,3,2), imshow(I4)

subplot(1,3,3), imshow(J)

imwrite(J,’add.bmp’);

title(‘image addition’);

%%——————————————————————

% Image subtraction
close all;

I1=imread(‘church.bmp’);

I2=imresize(I1,[500 500]);

I3 = I2;%rgb2gray(I2);

I1=imread(‘mask.bmp’);

I2=imresize(I1,[500 500]);

I4 = I2;

J = imsubtract(I3,I4);

subplot(1,3,1), imshow(I3)

subplot(1,3,2), imshow(I4)

subplot(1,3,3), imshow(J)

title(‘image substraction’);

%%———————————————————-

% image multiply

close all;

I1=imread(‘church.bmp’);

I2=imresize(I1,[500 500]);

I3 = I2;%rgb2gray(I2);

I1=imread(‘car.bmp’);

I2=imresize(I1,[500 500]);

I4 = I2;

J = immultiply(I3,I4);

subplot(1,3,1), imshow(I3)

subplot(1,3,2), imshow(I4)

subplot(1,3,3), imshow(J)

title(‘image multiplication’);

%%———————————————————-

%% Image divide

close all;

I1=imread(‘church.bmp’);

I2=imresize(I1,[500 500]);

I3 = I2;%rgb2gray(I2);

I1=imread(‘car.bmp’);

I2=imresize(I1,[500 500]);

I4 = I2;

J = imdivide(I3,I4);

subplot(1,3,1), imshow(I3)

subplot(1,3,2), imshow(I4)

subplot(1,3,3), imshow(J)

title(‘image divide’);

button_download-code