Advertisement
makispaiktis

Changing some pixel colors in an image

Oct 22nd, 2023
924
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.89 KB | None | 0 0
  1. clear all
  2. close all
  3. clc
  4.  
  5. % 1. Basics
  6. I = imread("IMG_01.jpeg");
  7. I2 = I;     I3 = I;
  8. [rows, cols, channels] = size(I);
  9. pixels = rows * cols;
  10.  
  11. % 2. Coordinates to be altered
  12. pososto = 0.2;
  13. converted = floor(pososto * pixels);
  14. coords = zeros(converted, 2);
  15. coords(:, 1) = randi([1 rows], converted, 1);
  16. coords(:, 2) = randi([1 cols], converted, 1);
  17.  
  18. % 3. Convertions
  19. desired = [255, 255, 255];                  % White
  20. for i = 1 : converted
  21.     row = coords(i, 1);
  22.     col = coords(i, 2);
  23.     I2(row, col, :) = desired;
  24. end
  25.  
  26. for i = 1 : converted
  27.     row = coords(i, 1);
  28.     col = coords(i, 2);
  29.     I3(row, col, :) = randi([0 255], 1, 3);
  30. end
  31.  
  32.  
  33. % 4. Plots
  34. figure();
  35. imshowpair(I, I2, "montage");
  36. title(num2str(100*pososto) + "% of pixels changed to " + mat2str(desired))
  37. figure();
  38. imshowpair(I, I3, "montage");
  39. title(num2str(100*pososto) + "% of pixels changed to random colors")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement