kossar

amipac 4

Oct 18th, 2021
697
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. %% Initialization
  2.  
  3. clc;clear ;
  4.  
  5. im1 = imread('winxp.jpg'); % reading image
  6. im2 = imread('winxojojo.png'); % reading image
  7.  
  8. %im1_gray = rgb2gray(im1); % converting RGB image to gray scale *
  9. %im2_gray = rgb2gray(im2); % converting RGB image to gray scale
  10. %im1_bw= im2bw(im1);       % converting RGB image to black and white **
  11. %im2_bw = im2bw(im1);      % converting RGB image to black and white
  12.  
  13.  
  14. %% performing the addition on the two images
  15.  
  16. addition_result = imadd(im1,im2);
  17. figure('Name','Addition operation','NumberTitle','on')
  18. subplot(2,2,1),
  19. imshow(im1);            %Display the image
  20. title('image 1');
  21.  
  22. subplot(2,2,2),
  23. imshow(im2); %Display the image
  24. title('image 2');
  25.  
  26. subplot(2,2,[3,4]),
  27. imshow(addition_result); %Display the result
  28. title('Operation : addition')
  29.  
  30.  
  31. %% performing the subtraction on the two images
  32.  
  33. subtract_result = imsubtract(im1,im2);
  34.  
  35. figure('Name','Subtraction operation','NumberTitle','on')
  36. subplot(2,2,1),
  37. imshow(im1);            %Display the image
  38. title('image 1');
  39.  
  40. subplot(2,2,2),
  41. imshow(im2);            %Display the image
  42. title('image 2');
  43.  
  44. subplot(2,2,[3,4]),
  45. imshow(subtract_result); %Display the result
  46. title('Operation : Subtraction ');
  47.  
  48.  
  49.  
  50. %% performing the absolute difference between the two images
  51.  
  52. abs_diff_result = imabsdiff(im1,im2);
  53. figure('Name','Absolute difference operation','NumberTitle','on')
  54. subplot(2,2,1),
  55. imshow(im1);            %Display the image
  56. title('image 1');
  57.  
  58. subplot(2,2,2),
  59. imshow(im2);            %Display the image
  60. title('image 2');
  61.  
  62. subplot(2,2,[3,4]),
  63. imshow(abs_diff_result); %Display the result
  64. title('Operation : Absolute difference');
  65.  
  66.  
  67. %% multiply image by 2.5
  68.  
  69. multiplication_result = immultiply(im1,2.5);
  70. figure('NAME','SUBTRACTION OPERATION','NUMBERTITLE','ON')
  71. subplot(2,2,[1,2]),
  72. imshow(im1);            %display the image
  73. title('image 1');
  74.  
  75. subplot(2,2,[3,4]),
  76. imshow(multiplication_result); %display the result
  77. title('operation : Multiplication')
  78.  
  79.  
  80. %% NOT (inversion):
  81.  
  82. im1_bw = im2bw(im1);
  83. incomplement_result_1 = imcomplement(im1); %Invert the RGB image
  84. incomplement_result_2 = imcomplement(im1_bw);  %Invert the B&W image
  85.  
  86. figure('Name','Logic operation "Incomplemet"','NumberTitle','on')    
  87. subplot(2,2,1),
  88. imshow(im1);            %Display the image
  89. title('image 1');
  90.  
  91. subplot(2,2,3),
  92. imshow(incomplement_result_1); %Display the result
  93. title('Operation : Incomplemet')  
  94.  
  95. subplot(2,2,2),
  96. imshow(im1_bw);            %Display the image
  97. title('image 1 B&W');
  98.  
  99. subplot(2,2,4),
  100. imshow(incomplement_result_2); %Display the result
  101. title('Operation : Incomplemet')
  102.  
  103.  
  104.  
  105. %% OR:
  106. im2_bw = im2bw(im2);      % converting RGB image to black and white
  107. Operation_or_result = or(im1_bw,im2_bw); % performing OR logic on the images
  108.  
  109. figure('Name','Logic operation "OR"','NumberTitle','on')
  110. subplot(4,4,1),
  111. imshow(im1);            %Display the image
  112. title('image 1');
  113.  
  114. subplot(4,4,2),
  115. imshow(im2);            %Display the image
  116. title('image 2');
  117.  
  118. subplot(4,4,3),
  119. imshow(im1_bw);            %Display the image
  120. title('image1 B&W');
  121.  
  122. subplot(4,4,4),
  123. imshow(im2_bw);            %Display the image
  124. title('image2 B&W');
  125.  
  126. subplot(2,2,[3,4]),
  127. imshow(Operation_or_result); %Display the result
  128. title('Logic Operation : OR')
  129.  
  130.  
  131. %% AND:
  132. Operation_AND_result = and(im1_bw,im2_bw);
  133.  
  134. figure('Name','Logic operation "AND"','NumberTitle','on')
  135. subplot(4,4,1),
  136. imshow(im1);            %Display the image
  137. title('image 1');
  138.  
  139. subplot(4,4,2),
  140. imshow(im2);            %Display the image
  141. title('image 2');
  142.  
  143. subplot(4,4,3),
  144. imshow(im1_bw);            %Display the image
  145. title('image1 B&W');
  146.  
  147. subplot(4,4,4),
  148. imshow(im2_bw);            %Display the image
  149. title('image2 B&W');
  150.  
  151. subplot(2,2,[3,4]),
  152. imshow(Operation_AND_result); %Display the result
  153. title('Logic Operation : AND')
  154.  
  155.  
  156. %% Thresholding:
  157.  
  158. thre_im1 = im2bw(im1,0.5);  % Perform thresholding
  159.  
  160. figure('Name','Thresholding','NumberTitle','on')
  161. subplot(1,2,1)
  162. imshow(im1);                %show original image
  163. title('image 1')
  164.  
  165. subplot(1,2,2)
  166. imshow(thre_im1);           %show image after thresholding
  167. title('threshold')
  168.  
RAW Paste Data