Python: scikit-image 彩色图像滤波
2024-09-04 11:36:05
一般的滤波器都是针对灰度图像的,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/
原图:
效果图:
最新文章
- grub2配置显示系统选择菜单(ubuntu 14.04)
- 学习笔记_springmvc返回值、数据写到页面、表单提交、ajax、重定向
- 使用python的redis 实现消息的pub/sub功能
- 基于MSP430F413水果电池供电的低功耗时钟
- Xamarin Studio支持TypeScript开发
- docker stop 与 docker kill的区别
- Cache 应用程序数据缓存
- DOM 之 document 查找元素方法
- 如何用googletest写单元测试
- JDK动态代理例子
- 一道C语言面试题:写一个宏,将16位的整数转为Big Endian
- Java动态代理深入解析
- Spring Boot + Websocket + Thymeleaf + Lombok
- HTML_CSS笔记
- Linux LVM磁盘管理
- [整理]解析Json需要设置Mime
- Zephir入门 —— 语法篇
- node和yarn
- 借助Maven为项目划分development,test,production环境
- 小技巧-如何加快github下载代码的速度(转)
热门文章
- VueJS路由
- Objective-C 执行AppleScript脚本
- D类功放基础简介
- tomcat报错: Error parsing HTTP request header
- phpQuery—基于jQuery的PHP实现(转)
- Chrome自带恐龙小游戏的源码研究(二)
- scapy windows install
- lucene分词器中的Analyzer,TokenStream, Tokenizer, TokenFilter
- 玩转 eclipse:[1]如何快速找错-debug
- Ejabberd作为推送服务的优化手段(转)