zoukankan      html  css  js  c++  java
  • 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/

    原图:

    这里写图片描述

    效果图:

    这里写图片描述

  • 相关阅读:
    animation-fill-mode
    css3 media queries
    三列,左右两列宽度固定,中间宽度自适应
    两列布局,一列定宽,一列宽度自适应
    css3 animation
    transition和animation区别
    transform 和 transition
    弹出框样式
    python map和filter函数
    leetcode Z字形字符串
  • 原文地址:https://www.cnblogs.com/mtcnn/p/9412560.html
Copyright © 2011-2022 走看看