计算机视觉知识点|OpenCV滤镜效果

计算机视觉知识点|OpenCV滤镜效果
文章图片

在medium上看到一篇介绍opencv滤镜效果的博客,这里做一下记录和分享.
卷积操作
计算机视觉知识点|OpenCV滤镜效果
文章图片

【计算机视觉知识点|OpenCV滤镜效果】高斯模糊

pip3 install opencv-python pip3 install scipydef gaussianBlur(image): return cv2.GaussianBlur(image, (35, 35), 0)initialImage = cv2.imread("image1.jpg") blurredImage = gaussianBlur(copy.deepcopy(initialImage)) cv2.imwrite("blurred.jpg", blurredImage)

计算机视觉知识点|OpenCV滤镜效果
文章图片


锐化
def sharpen(image): kernel = np.array([[-1, -1, -1], [-1, 9, -1], [-1, -1, -1]]) return cv2.filter2D(image, -1, kernel)

计算机视觉知识点|OpenCV滤镜效果
文章图片


Sepia
def sepia(image): kernel = np.array([[0.272, 0.534, 0.131], [0.349, 0.686, 0.168], [0.393, 0.769, 0.189]]) return cv2.filter2D(image, -1, kernel)


计算机视觉知识点|OpenCV滤镜效果
文章图片

emboss
def emboss(image): kernel = np.array([[0,-1,-1], [1,0,-1], [1,1,0]]) return cv2.filter2D(image, -1, kernel)


计算机视觉知识点|OpenCV滤镜效果
文章图片

像素操作
def brightnessControl(image, level): return cv2.convertScaleAbs(image, beta=level)

计算机视觉知识点|OpenCV滤镜效果
文章图片


查找表操作
def spreadLookupTable(x, y): spline = UnivariateSpline(x, y) return spline(range(256)) def warmImage(image): increaseLookupTable = spreadLookupTable([0, 64, 128, 256], [0, 80, 160, 256]) decreaseLookupTable = spreadLookupTable([0, 64, 128, 256], [0, 50, 100, 256]) red_channel, green_channel, blue_channel = cv2.split(image) red_channel = cv2.LUT(red_channel, increaseLookupTable).astype(np.uint8) blue_channel = cv2.LUT(blue_channel, decreaseLookupTable).astype(np.uint8) return cv2.merge((red_channel, green_channel, blue_channel)) def coldImage(image): increaseLookupTable = spreadLookupTable([0, 64, 128, 256], [0, 80, 160, 256]) decreaseLookupTable = spreadLookupTable([0, 64, 128, 256], [0, 50, 100, 256]) red_channel, green_channel, blue_channel = cv2.split(image) red_channel = cv2.LUT(red_channel, decreaseLookupTable).astype(np.uint8) blue_channel = cv2.LUT(blue_channel, increaseLookupTable).astype(np.uint8) return cv2.merge((red_channel, green_channel, blue_channel))

暖色调效果
计算机视觉知识点|OpenCV滤镜效果
文章图片

冷色调
计算机视觉知识点|OpenCV滤镜效果
文章图片


    推荐阅读