首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >图像消除纹理

图像消除纹理

作者头像
裴来凡
发布2022-05-29 10:11:01
发布2022-05-29 10:11:01
1.8K0
举报
代码语言:javascript
复制
import numpy as np
from PIL import Image
import matplotlib.pyplot as plt
from scipy import ndimage
cov_len=23
img=Image.open("C:/Users/xpp/Desktop/Lena.png", 'r')
img=img.convert('L')
avg_img=[]
for i in range(19):
    px=np.random.randint(0,256-cov_len)
    py=np.random.randint(0,256-cov_len)
    rect=(px,py,px+cov_len,py+cov_len)
    cut_img=img.crop(rect)
    avg_img.append(np.array(cut_img).reshape(-1))
avg_img=np.array(avg_img).mean(axis=0).reshape(cov_len, cov_len)
avg_img=avg_img/avg_img.sum()#加权平均值
i=ndimage.convolve(img,avg_img)
img_result=Image.fromarray(i)
img_result.save('C:/Users/xpp/Desktop/result.png')
plt.imshow(img_result,cmap='gray')
plt.show()

算法:图像消除纹理是首先将原始图像转换为灰度图像,随机选取和卷积核大小相同的正方形框小图像,选取多个图像取平均值来保证纹理特征能够适应整张图像,最终得到小图像之后取加权平均值,类似于高斯模糊一样的效果,这样卷积出来的结果能有效消除图像纹理。

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2022-01-29,如有侵权请联系 cloudcommunity@tencent.com 删除
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档