You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
1.4 KiB
35 lines
1.4 KiB
import cv2
|
|
|
|
|
|
class morphology:
|
|
def __init__(self, img_path):
|
|
self.path = img_path
|
|
|
|
def corrode(self, struct_size):
|
|
struct_size = int(struct_size)
|
|
src = cv2.imread(self.path, cv2.IMREAD_UNCHANGED)
|
|
kernel = cv2.getStructuringElement(cv2.MORPH_CROSS, (struct_size, struct_size))
|
|
erosion = cv2.erode(src, kernel)
|
|
cv2.imwrite("saved Img/erosion.bmp", erosion)
|
|
|
|
def dilation(self, struct_size):
|
|
struct_size = int(struct_size)
|
|
src = cv2.imread(self.path, cv2.IMREAD_UNCHANGED)
|
|
kernel = cv2.getStructuringElement(cv2.MORPH_CROSS, (struct_size, struct_size))
|
|
dilation = cv2.dilate(src, kernel)
|
|
cv2.imwrite("saved Img/dilate.bmp", dilation)
|
|
|
|
def open(self, struct_size):
|
|
struct_size = int(struct_size)
|
|
src = cv2.imread(self.path, cv2.IMREAD_UNCHANGED)
|
|
kernel = cv2.getStructuringElement(cv2.MORPH_CROSS, (struct_size, struct_size))
|
|
open = cv2.morphologyEx(src, cv2.MORPH_OPEN, kernel)
|
|
cv2.imwrite("saved Img/open.bmp", open)
|
|
|
|
def close(self, struct_size):
|
|
struct_size = int(struct_size)
|
|
src = cv2.imread(self.path, cv2.IMREAD_UNCHANGED)
|
|
kernel = cv2.getStructuringElement(cv2.MORPH_CROSS, (struct_size, struct_size))
|
|
close = cv2.morphologyEx(src, cv2.MORPH_CLOSE, kernel)
|
|
cv2.imwrite("saved Img/close.bmp", close)
|