小工具知识网

当前位置: 首页 > 行业知识 > 数字图像处理—python

行业知识

数字图像处理—python

2026-11-17 13:29:48 来源:互联网转载

pycahem���端也可以下载库,我只会用终端下载,用的镜像网站

pip install torch -i https://pypi.tuna.tsinghua.edu.cn/simplepip install scikit-image -i https://pypi.tuna.tsinghua.edu.cn/simple.pip install matplotlib -i https://pypi.tuna.tsinghua.edu.cn/simple.

在敲的过程中我深刻体会到了,python代码对缩进要求极高,稍有不慎....

(1)采用均值方法/最大值进行图像模拟采样

将image[i,j,k]=np.mean(delta)修改为image[i,j,k]=np.max(delta)

from skimage import datafrom matplotlib import pyplot as pltimport numpy as np  #导入所需类包image = data.coffee()  #载入测试图像print(image.shape)  #显示图像原始大小print(type(image))  #显示图像类型ratio = 20image1 = np.zeros((int(image.shape[0]/ratio),                  int(image.shape[1]/ratio),image.shape[2]),                  dtype = 'int32')  #设置采样比率for i in range(image1.shape[0]):    for j in range(image1.shape[1]):        for k in range(image1.shape[2]):  #对图像进行遍历            delta = image[i * ratio:(i + 1)*ratio,j *ratio:(j + 1)*ratio,k]  #获取需要采样的图像块            image1 [i,j,k] = np.mean(delta)  #计算均值,并存入结果图像  均值进行图像采样          #image1 [i,j,k] = np.max(delta)最大值进行图像值采样    plt.imshow(image1)  #打印采样后的图像    plt.show()

(2)图像量化

from skimage import datafrom matplotlib import pyplot as pltimage = data.coffee()  #载入测试图像ratio = 128for i in range(image.shape[0]):    for j in range(image.shape[1]):        for k in range(image.shape[2]):  #对图像进行遍历            image [i][j][k] = int(image[i][j][k]/ratio)*ratio  #计算均值,并存入结果图像plt.imshow(image)  #打印采样后的图像plt.show()

上一篇:车辆改色后怎么去备案新车上牌

下一篇:源码网站运营秘籍,吸引用户的策略与实战技巧全解析!