Python编程对彩色图像滤波处理

编程语言及工具

102人已加入

描述

一般的滤波器都是针对灰度图像的,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()

原图:

效果图:

打开APP阅读更多精彩内容
声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉

全部0条评论

快来发表一下你的评论吧 !

×
20
完善资料,
赚取积分