一般的滤波器都是针对灰度图像的,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\n 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\n on Value converted image (HSV)") plt.show()

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

原图:

效果图:

最新文章

  1. grub2配置显示系统选择菜单(ubuntu 14.04)
  2. 学习笔记_springmvc返回值、数据写到页面、表单提交、ajax、重定向
  3. 使用python的redis 实现消息的pub/sub功能
  4. 基于MSP430F413水果电池供电的低功耗时钟
  5. Xamarin Studio支持TypeScript开发
  6. docker stop 与 docker kill的区别
  7. Cache 应用程序数据缓存
  8. DOM 之 document 查找元素方法
  9. 如何用googletest写单元测试
  10. JDK动态代理例子
  11. 一道C语言面试题:写一个宏,将16位的整数转为Big Endian
  12. Java动态代理深入解析
  13. Spring Boot + Websocket + Thymeleaf + Lombok
  14. HTML_CSS笔记
  15. Linux LVM磁盘管理
  16. [整理]解析Json需要设置Mime
  17. Zephir入门 —— 语法篇
  18. node和yarn
  19. 借助Maven为项目划分development,test,production环境
  20. 小技巧-如何加快github下载代码的速度(转)

热门文章

  1. VueJS路由
  2. Objective-C 执行AppleScript脚本
  3. D类功放基础简介
  4. tomcat报错: Error parsing HTTP request header
  5. phpQuery—基于jQuery的PHP实现(转)
  6. Chrome自带恐龙小游戏的源码研究(二)
  7. scapy windows install
  8. lucene分词器中的Analyzer,TokenStream, Tokenizer, TokenFilter
  9. 玩转 eclipse:[1]如何快速找错-debug
  10. Ejabberd作为推送服务的优化手段(转)