frentzy

abominatie

Oct 31st, 2020
850
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #pastebin-ul de mai sus e versiunea cea buna (folosind codu profului)
  2. import matplotlib.pyplot as plt
  3. import glob
  4. import  os
  5. import cv2
  6. from PIL import Image, ImageOps
  7. import numpy as np
  8. import random
  9.  
  10. def nothing(x):
  11.     pass
  12.    
  13. def sp_noise(image,white_noise):
  14.     if white_noise <= 0.1:
  15.         output = np.zeros(image.shape,np.uint8)
  16.         thres = 1 - white_noise
  17.         for i in range(image.shape[0]):
  18.             for j in range(image.shape[1]):
  19.                 rdn = random.random()
  20.                 if rdn > thres:
  21.                     output[i][j] = 255
  22.                 else:
  23.                     output[i][j] = image[i][j]
  24.         return output
  25.  
  26. image = cv2.imread('C:/Users/Frentzy/Pictures/Mercy.jpg')  
  27. numeFereastra = 'Exemplu cu trackbar - ESC pentru inchidere'
  28. cv2.namedWindow(numeFereastra, cv2.WINDOW_NORMAL)
  29. cv2.createTrackbar('thresh', numeFereastra, 0, 100, nothing)
  30. while(1):
  31.     thresh = cv2.getTrackbarPos('thresh', numeFereastra)
  32.     noise_img = sp_noise(image,thresh/1000)
  33.     cv2.imshow(numeFereastra, noise_img)
  34.     if cv2.waitKey(1) == 27: #incheiem cu ESC
  35.         break
  36. cv2.destroyAllWindows()
  37.  
RAW Paste Data