Advertisement
makispaiktis

Tutorial - Image Channels

Aug 9th, 2021 (edited)
1,315
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.77 KB | None | 0 0
  1. clc
  2. clear all
  3.  
  4. % 1. Original Photo
  5. A = imread('lena.png');
  6. imageSize = size(A)
  7. figure(1);
  8. title('Original photo');
  9. imshow(A);
  10. % The 3rd dimension-number is: 1 = red channel, 2 = green, 3 = blue
  11.  
  12. % 2a. Display red channel - Red stays
  13. R = A;
  14. R(:, :, 2) = 0;     % Green = 0
  15. R(:, :, 3) = 0;     % Blue = 0
  16. figure(2);
  17. title('Red Lena');
  18. imshow(R);
  19.  
  20. % 2b. Display green channel - Green stays
  21. G = A;
  22. G(:, :, 1) = 0;     % Red = 0
  23. G(:, :, 3) = 0;     % Blue = 0
  24. figure(3);
  25. title('Green Lena');
  26. imshow(G);
  27.  
  28. % 2c. Display blue channel - Blue stays
  29. B = A;
  30. B(:, :, 1) = 0;     % Red = 0
  31. B(:, :, 2) = 0;     % Green = 0
  32. figure(4);
  33. title('Blue Lena');
  34. imshow(B);
  35. %{
  36. figure(5);
  37. imshow(B(:, :, 1));
  38. figure(6);
  39. imshow(B(:, :, 2));
  40. figure(7);
  41. imshow(B(:, :, 3));
  42. %}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement