OpenCV:图像的开运算与闭运算

导包:

import numpy as np
import cv2
import matplotlib.pyplot as plt
def show(image):
    plt.imshow(image)
    plt.axis('off')
    plt.show()
def imread(image):
    image=cv2.imread(image)
    image=cv2.cvtColor(image,cv2.COLOR_BGR2RGB)
    return image

开运算代码:

kernel=cv2.getStructuringElement(cv2.MORPH_RECT,(10,10))
opening=cv2.morphologyEx(image,cv2.MORPH_OPEN,kernel)
show(opening)

闭运算代码:#下面开始闭运算,膨胀之后再腐蚀,用于去除黑点

kernel=cv2.getStructuringElement(cv2.MORPH_RECT,(10,10))
opening=cv2.morphologyEx(image,cv2.MORPH_OPEN,kernel)
show(opening)

 

posted @ 2019-06-30 20:23  Geeksongs  阅读(4064)  评论(0编辑  收藏  举报

Coded by Geeksongs on Linux

All rights reserved, no one is allowed to pirate or use the document for other purposes.