• Python: scikit-image 彩色图像滤波


    一般的滤波器都是针对灰度图像的,scikit-image 库提供了针对彩色图像滤波的decorator:adapt_rgb,adapt_rgb 提供两种形式的滤波,一种是对rgb三个通道分别进行处理,另外一种方式是将rgb转为hsv颜色模型,然后针对v通道进行处理,最后再转回rgb颜色模型。

    针对模式一,称为 each_channel

    @adapt_rgb(each_channel)
    def sobel_each(image):
        return filters.sobel(image)

    模式二称为 hsv_value

    @adapt_rgb(hsv_value)
    def sobel_hsv(image):
        return filters.sobel(image)

    利用上述两种模式,可以对彩色图像滤波,下面是完整的用例代码;

    from skimage import data
    from skimage.exposure import rescale_intensity
    import matplotlib.pyplot as plt
    
    from skimage.color.adapt_rgb import adapt_rgb, each_channel, hsv_value
    from skimage import filters
    
    
    @adapt_rgb(each_channel)
    def sobel_each(image):
        return filters.sobel(image)
    
    
    @adapt_rgb(hsv_value)
    def sobel_hsv(image):
        return filters.sobel(image)
    
    image = data.astronaut()
    
    # display the original image
    plt.imshow(image)
    
    fig = plt.figure(figsize=(16, 9))
    ax_each = fig.add_subplot(121, adjustable='box-forced')
    ax_hsv = fig.add_subplot(122, sharex=ax_each, sharey=ax_each, adjustable='box-forced')
    
    # We use 1 - sobel_each(image)
    # but this will not work if image is not normalized
    ax_each.imshow(rescale_intensity(1 - sobel_each(image)))
    ax_each.set_xticks([]), ax_each.set_yticks([])
    ax_each.set_title("Sobel filter computed
     on individual RGB channels")
    
    # We use 1 - sobel_hsv(image) but this will not work if image is not normalized
    ax_hsv.imshow(rescale_intensity(1 - sobel_hsv(image)))
    ax_hsv.set_xticks([]), ax_hsv.set_yticks([])
    ax_hsv.set_title("Sobel filter computed
     on Value converted image (HSV)")
    
    plt.show()

    参考来源: http://scikit-image.org/docs/dev/auto_examples/

    原图:

    这里写图片描述

    效果图:

    这里写图片描述

  • 相关阅读:
    hdu1565 用搜索代替枚举找可能状态或者轮廓线解(较优),参考poj2411
    cf1114D 区间dp基础
    poj2411 状态压缩-铺地板题型-轮廓线解法(最优)
    poj3254 炮兵阵地弱化版,记数类dp
    poj2441状态压缩dp基础
    zoj3471 状态压缩dp基础
    北极通讯网络(最小生成树)
    黑暗城堡(生成树)
    关押罪犯(并查集)
    搭配购买(并查集+0/1背包)
  • 原文地址:https://www.cnblogs.com/mtcnn/p/9412560.html
Copyright © 2020-2023  润新知