Advertisement
makispaiktis

Tutorial Thomas - Create Random Images

Aug 10th, 2021 (edited)
464
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.65 KB | None | 0 0
  1. clc
  2. clear all
  3.  
  4. % MAIN FUNCTION
  5. M = 512;
  6. N = 512;
  7. times = 100;
  8. figure(1);
  9. createImage(M, N);
  10. figure(2);
  11. createLayersImage(M, N);
  12.  
  13.  
  14. % Function 1 - Create Image
  15. function createImage(M, N)
  16.     for i = 1:M
  17.         for j = 1:N
  18.             red = randi([0 255]);
  19.             green = randi([0 155]);
  20.             blue = randi([0 255]);
  21.             A(i, j, 1) = red;
  22.             A(i, j, 2) = green;
  23.             A(i, j, 3) = blue;
  24.         end
  25.     end
  26.     imshow(A);
  27. end
  28.  
  29. % Function 2 - Create Layers Image
  30. function createLayersImage(M,N)
  31.     for i = 1:M
  32.         for j = 1:N
  33.             if i < M/4
  34.                 red = randi([0 55]);
  35.                 green = randi([100 155]);
  36.                 blue = randi([200 255]);
  37.                 A(i, j, 1) = red;
  38.                 A(i, j, 2) = green;
  39.                 A(i, j, 3) = blue;
  40.             elseif i < M / 2
  41.                 red = randi([100 155]);
  42.                 green = randi([0 55]);
  43.                 blue = randi([200 255]);
  44.                 A(i, j, 1) = red;
  45.                 A(i, j, 2) = green;
  46.                 A(i, j, 3) = blue;
  47.             elseif i < 3*M / 4
  48.                 red = randi([200 255]);
  49.                 green = randi([100 155]);
  50.                 blue = randi([0 55]);
  51.                 A(i, j, 1) = red;
  52.                 A(i, j, 2) = green;
  53.                 A(i, j, 3) = blue;
  54.             else
  55.                 red = randi([0 255]);
  56.                 green = randi([0 155]);
  57.                 blue = randi([0 255]);
  58.                 A(i, j, 1) = red;
  59.                 A(i, j, 2) = green;
  60.                 A(i, j, 3) = blue;
  61.             end
  62.         end
  63.     end
  64.  
  65.     imshow(A);
  66.     hold on
  67. end
  68.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement