Emboss滤波器

一. Emboss 滤波器介绍:

        Emboss滤波器常用于检测图像的边缘和轮廓,能够有效地增强图像的高频信息(边缘和轮廓),并保留图像的低频信息(图像内容)。

Emboss滤波器_第1张图片

Emboss 滤波器卷积核 ↑


二. 实验:实现Emboss滤波器,使用Emboss滤波器增强图像轮廓

import cv2

import numpy as np

# Gray scale

def BGR2GRAY(img):

    b = img[:, :, 0].copy()

    g = img[:, :, 1].copy()

    r = img[:, :, 2].copy()

    # Gray scale

    out = 0.2126 * r + 0.7152 * g + 0.0722 * b

    out = out.astype(np.uint8)

    return out

# emboss filter

def emboss_filter(img, K_size=3):

    H, W = img.shape

    # zero padding

    pad = K_size // 2

    out = np.zeros((H + pad * 2, W + pad * 2), dtype=np.float)

    out[pad: pad + H, pad: pad + W] = img.copy().astype(np.float)

    tmp = out.copy()

    # emboss kernel

    K = [[-2., -1., 0.],[-1., 1., 1.], [0., 1., 2.]]

    # filtering

    for y in range(H):

        for x in range(W):

            out[pad + y, pad + x] = np.sum(K * (tmp[y: y + K_size, x: x + K_size]))

    out = np.clip(out, 0, 255)

    out = out[pad: pad + H, pad: pad + W].astype(np.uint8)

    return out

# Read image

img = cv2.imread("../paojie.jpg").astype(np.float)

# BGR2GRAY

gray = BGR2GRAY(img)

# emboss filtering

out = emboss_filter(gray, K_size=3)

# Save result

cv2.imwrite("out.jpg", out)

cv2.imshow("result", out)

cv2.waitKey(0)

cv2.destroyAllWindows()

三. 实验结果:

Emboss滤波器_第2张图片

Emboss 滤波器作用于图像后 ↑

Emboss滤波器_第3张图片

原图转换为灰度图像后 ↑

        可以看到,Emboss滤波器能够有效地增强图像的轮廓。


四. 参考内容:

        https://www.cnblogs.com/wojianxin/p/12508170.html

        https://www.jianshu.com/p/0f7102dec590

 

你可能感兴趣的:(数字图像处理入门)