Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import cv2
- import os
- import numpy as np
- imgs = [cv2.imread('1.jpg'), cv2.imread('2.jpg'), cv2.imread('3.jpg'), cv2.imread('4.jpg')]
- def erode(img, x, it):
- wzorzec = np.ones((x,x), np.uint8)
- return cv2.erode(img, wzorzec, iterations = it)
- def dilate(img, x, it):
- wzorzec = np.ones((x,x), np.uint8)
- return cv2.dilate(img, wzorzec, iterations = it)
- def open(img, x, it):
- return erode(dilate(img, x, it), x, it)
- def close(img, x, it):
- return dilate(erode(img, x, it), x, it)
- def saveImg(img, op, x, it):
- if not os.path.isdir(op):
- os.mkdir(op)
- cv2.imwrite(os.path.join(op,`x`+'x'+`x`+'it='+`it`+'.jpg'), img)
- for idx, img in enumerate(imgs):
- for iteration in [1,5,10]:
- for matrix in [3,5,7,9]:
- saveImg(dilate(img, matrix, iteration), 'dilate'+`idx+1`, matrix, iteration)
- saveImg(erode(img, matrix, iteration), 'erode'+`idx+1`, matrix, iteration)
- saveImg(open(img, matrix, iteration), 'open'+`idx+1`, matrix, iteration)
- saveImg(close(img, matrix, iteration), 'close'+`idx+1`, matrix, iteration)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement