Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %% Initialization
- clc;clear ;
- im1 = imread('winxp.jpg'); % reading image
- im2 = imread('winxojojo.png'); % reading image
- %im1_gray = rgb2gray(im1); % converting RGB image to gray scale *
- %im2_gray = rgb2gray(im2); % converting RGB image to gray scale
- %im1_bw= im2bw(im1); % converting RGB image to black and white **
- %im2_bw = im2bw(im1); % converting RGB image to black and white
- %% performing the addition on the two images
- addition_result = imadd(im1,im2);
- figure('Name','Addition operation','NumberTitle','on')
- subplot(2,2,1),
- imshow(im1); %Display the image
- title('image 1');
- subplot(2,2,2),
- imshow(im2); %Display the image
- title('image 2');
- subplot(2,2,[3,4]),
- imshow(addition_result); %Display the result
- title('Operation : addition')
- %% performing the subtraction on the two images
- subtract_result = imsubtract(im1,im2);
- figure('Name','Subtraction operation','NumberTitle','on')
- subplot(2,2,1),
- imshow(im1); %Display the image
- title('image 1');
- subplot(2,2,2),
- imshow(im2); %Display the image
- title('image 2');
- subplot(2,2,[3,4]),
- imshow(subtract_result); %Display the result
- title('Operation : Subtraction ');
- %% performing the absolute difference between the two images
- abs_diff_result = imabsdiff(im1,im2);
- figure('Name','Absolute difference operation','NumberTitle','on')
- subplot(2,2,1),
- imshow(im1); %Display the image
- title('image 1');
- subplot(2,2,2),
- imshow(im2); %Display the image
- title('image 2');
- subplot(2,2,[3,4]),
- imshow(abs_diff_result); %Display the result
- title('Operation : Absolute difference');
- %% multiply image by 2.5
- multiplication_result = immultiply(im1,2.5);
- figure('NAME','SUBTRACTION OPERATION','NUMBERTITLE','ON')
- subplot(2,2,[1,2]),
- imshow(im1); %display the image
- title('image 1');
- subplot(2,2,[3,4]),
- imshow(multiplication_result); %display the result
- title('operation : Multiplication')
- %% NOT (inversion):
- im1_bw = im2bw(im1);
- incomplement_result_1 = imcomplement(im1); %Invert the RGB image
- incomplement_result_2 = imcomplement(im1_bw); %Invert the B&W image
- figure('Name','Logic operation "Incomplemet"','NumberTitle','on')
- subplot(2,2,1),
- imshow(im1); %Display the image
- title('image 1');
- subplot(2,2,3),
- imshow(incomplement_result_1); %Display the result
- title('Operation : Incomplemet')
- subplot(2,2,2),
- imshow(im1_bw); %Display the image
- title('image 1 B&W');
- subplot(2,2,4),
- imshow(incomplement_result_2); %Display the result
- title('Operation : Incomplemet')
- %% OR:
- im2_bw = im2bw(im2); % converting RGB image to black and white
- Operation_or_result = or(im1_bw,im2_bw); % performing OR logic on the images
- figure('Name','Logic operation "OR"','NumberTitle','on')
- subplot(4,4,1),
- imshow(im1); %Display the image
- title('image 1');
- subplot(4,4,2),
- imshow(im2); %Display the image
- title('image 2');
- subplot(4,4,3),
- imshow(im1_bw); %Display the image
- title('image1 B&W');
- subplot(4,4,4),
- imshow(im2_bw); %Display the image
- title('image2 B&W');
- subplot(2,2,[3,4]),
- imshow(Operation_or_result); %Display the result
- title('Logic Operation : OR')
- %% AND:
- Operation_AND_result = and(im1_bw,im2_bw);
- figure('Name','Logic operation "AND"','NumberTitle','on')
- subplot(4,4,1),
- imshow(im1); %Display the image
- title('image 1');
- subplot(4,4,2),
- imshow(im2); %Display the image
- title('image 2');
- subplot(4,4,3),
- imshow(im1_bw); %Display the image
- title('image1 B&W');
- subplot(4,4,4),
- imshow(im2_bw); %Display the image
- title('image2 B&W');
- subplot(2,2,[3,4]),
- imshow(Operation_AND_result); %Display the result
- title('Logic Operation : AND')
- %% Thresholding:
- thre_im1 = im2bw(im1,0.5); % Perform thresholding
- figure('Name','Thresholding','NumberTitle','on')
- subplot(1,2,1)
- imshow(im1); %show original image
- title('image 1')
- subplot(1,2,2)
- imshow(thre_im1); %show image after thresholding
- title('threshold')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement