Advertisement
Guest User

Untitled

a guest
May 20th, 2019
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. import cv2
  2. import os
  3. import numpy as np
  4.  
  5. imgs = [cv2.imread('1.jpg'), cv2.imread('2.jpg'), cv2.imread('3.jpg'), cv2.imread('4.jpg')]
  6.  
  7.  
  8. def erode(img, x, it):
  9. wzorzec = np.ones((x,x), np.uint8)
  10. return cv2.erode(img, wzorzec, iterations = it)
  11.  
  12. def dilate(img, x, it):
  13. wzorzec = np.ones((x,x), np.uint8)
  14. return cv2.dilate(img, wzorzec, iterations = it)
  15.  
  16. def open(img, x, it):
  17. return erode(dilate(img, x, it), x, it)
  18.  
  19. def close(img, x, it):
  20. return dilate(erode(img, x, it), x, it)
  21.  
  22. def saveImg(img, op, x, it):
  23. if not os.path.isdir(op):
  24. os.mkdir(op)
  25. cv2.imwrite(os.path.join(op,`x`+'x'+`x`+'it='+`it`+'.jpg'), img)
  26.  
  27. for idx, img in enumerate(imgs):
  28. for iteration in [1,5,10]:
  29. for matrix in [3,5,7,9]:
  30. saveImg(dilate(img, matrix, iteration), 'dilate'+`idx+1`, matrix, iteration)
  31. saveImg(erode(img, matrix, iteration), 'erode'+`idx+1`, matrix, iteration)
  32. saveImg(open(img, matrix, iteration), 'open'+`idx+1`, matrix, iteration)
  33. saveImg(close(img, matrix, iteration), 'close'+`idx+1`, matrix, iteration)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement