数字图像处理数字图像处理 – 实验作业一实验作业一 – Python
文章目录文章目录第二章 数字图像基础1、用程序实现同时对比度实验2、用程序实验空间分辨率变化效果3、用程序实验幅度分辨率变化效果
第二章第二章 数字图像基础数字图像基础
这几个题目网上有很多MATLAB版的解答,这里自己写了一个python的版本,实现的思路是基本一致基本一致的
依赖库依赖库
import matplotlib.pyplot as plt
import matplotlib.image as img
import numpy as np
import math
%matplotlib inline
1、用程序实现同时对比度实验、用程序实现同时对比度实验
程序代码:程序代码:
# set image size
height = 256
weight = 256
channel = 3
img_size = (height, weight, channel)
img_list = []
# R=G=B gray
light_gray = 200
deep_gray = 100
center_gray = 150
img_1 = np.ones(img_size, dtype = int) * deep_gray
img_2 = np.ones(img_size, dtype = int) * light_gray
img_1[50:200, 50:200,:] = center_gray
img_2[50:200, 50:200,:] = center_gray
img_list = [img_1, img_2]
_, axs = plt.subplots(1, 2, figsize=(8,8))
for i in range(len(axs)):
axs[i].set_title("image"+str(i+1))
axs[i].imshow(img_list[i])
axs[i].axes.get_xaxis().set_visible(False)
axs[i].axes.get_yaxis().set_visible(False)
plt.show()
输出结果:输出结果:
2、用程序实验空间分辨率变化效果、用程序实验空间分辨率变化效果
本题和下一题使用的原图本题和下一题使用的原图
大小为1024*1024
程序代码:程序代码:
timg_1024 = img.imread("timg.jpg")
m, n ,c = timg_1024.shape
img_list = [] img_list_name = [] index = [int(math.pow(2,i)) for i in range(8)]
评论0