首页 > 编程知识 正文

python 滤波器,python实现中值滤波算法

时间:2023-05-06 20:17:23 阅读:150926 作者:2178

典型的滤镜针对灰度图像,scikit-image库提供了两种过滤格式: decorator:adapt_rgb和adapt_rgb,用于过滤彩色图像。 一种是分别处理rgb的三个通道,另一种是将rgb转换为hsv颜色模型后处理v通道,最后

对于模式1,称为each_channel

@Adapt_RGB(each_Channel ) ) ) ) ) ) ) ) )。) ) ) ) @Adapt_RGB(each_Channel ) )

efSobel_each(image ) :

return filters.sobel(image )

模式2被称为hsv_value

@Adapt_RGB(HSV_value )为

efSobel_HSV(image ) :

return filters.sobel(image )

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

from skimage import data

fromskimage.exposureimportrescale _ intensity

import matplotlib.pyplot as plt

fromskimage.color.adapt _ rgbimportadapt _ RGB、each_channel、hsv_value

from skimage import filters

@Adapt_RGB(each_Channel ) ) ) ) ) ) ) ) )。) ) ) ) @Adapt_RGB(each_Channel ) )

efSobel_each(image ) :

return filters.sobel(image )

@Adapt_RGB(HSV_value )为

efSobel_HSV(image ) :

return filters.sobel(image )

image=data.astronaut (

# display the original image

PLT.imshow(image ) )。

fig=PLT.figure (fig size=(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 ' )

#weuse1-Sobel_each(image ) )。

# butthiswillnotworkifimageisnotnormalized

ax _ each.im show (rescale _ intensity (1- Sobel _ each ) image ) )

ax_each.set_xticks([],ax_each.set_yticks([] )

ax _ each.set _ title (sobelfiltercomputed (nonindividualrgbchannels ) )。

#weuse1-Sobel_HSV(image ) butthiswillnotworkifimageisnotnormalized

ax _ HSV.im show (rescale _ intensity (1- Sobel _ HSV ) image ) )

ax_hsv.set_xticks([],ax_hsv.set_yticks([] )

ax _ HSV.set _ title (sobelfiltercomputed (nonvalueconvertedimage ) HSV ) )

plt.show () )

参照来源:

原图:

效果图:

(责任编辑: ioter )

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。