利用 Python 进行数据分析实验(七)

一、实验目的

使用Python解决问题

二、实验要求

自主编写并运行代码,按照模板要求撰写实验报告

三、实验步骤

  1. 操作书上第九章内容
  2. 请画出如图2.png所示的图形
  3. 通过编码获得fcity.jpg的手绘图像(如beijing.jpg所示)

四、实验结果

T2

py 复制代码
"""
请画出如图2.png所示的图形
"""
import turtle as t

t.pen(speed=0)
xy = -300

# t.seth(0)
while (xy <= 0):
    t.penup()
    t.goto(xy, xy)  # pendown是默认状态

    for i in range(4):
        t.pendown()
        t.forward(2 * (-xy))
        t.left(90)
        t.penup()

    xy = xy + 10
t.done()
# t.getcanvas().postscript(file = "T2.eps")

T3

py 复制代码
"""
通过编码获得fcity.jpg的手绘图像(如beijing.jpg所示)
"""
import numpy as np
from PIL import Image

image_array = np.asarray(Image.open('./picture/fcity.jpg').convert('L')).astype('float')
depth = 8 # 范围0~100,数值过高则亮部细节过度,数值过低则缺失亮部细节
grad = np.gradient(image_array)
grad_x, grad_y = grad
grad_x = grad_x * depth / 100
grad_y = grad_y * depth / 100
A = np.sqrt(grad_x ** 2 + grad_y ** 2 + 1)
uni_x = grad_x / A
uni_y = grad_y / A
uni_z = 1. / A

# 适当调整了光源的位置,补充部分亮部缺失的细节
vec_el = np.pi / 1.8
vec_az = np.pi / 7
dx = np.cos(vec_el) * np.cos(vec_az)
dy = np.cos(vec_el) * np.sin(vec_az)
dz = np.sin(vec_el)

b = 255 * (dx * uni_x + dy * uni_y + dz * uni_z)
b = b.clip(0, 255)

im = Image.fromarray(b.astype('uint8'))
im.save('./picture/res.jpg')

五、实验体会

相关推荐
墨白曦煜6 分钟前
Java集合框架整体分类(完整的集合框架关系)
java·开发语言
被放养的研究生9 分钟前
dir()与help()
python
YuanlongWang12 分钟前
C# 基础——async/await 的实现原理与最佳实践
开发语言·c#
kkkkk02110617 分钟前
JavaScript性能优化实战:深度剖析瓶颈与高效解决方案
开发语言·javascript·性能优化
我的xiaodoujiao22 分钟前
使用 Python 语言 从 0 到 1 搭建完整 Web UI自动化测试学习系列 20--PO(POM) 设计模式和用例撰写
python·学习·测试工具·设计模式·pytest
一碗绿豆汤29 分钟前
C语言-结构体
c语言·开发语言
子不语18029 分钟前
深度学习(一)——基础知识:Python语言/解释器/环境/编辑器
python·学习
kalvin_y_liu35 分钟前
ManySpeech —— 使用 C# 开发人工智能语音应用
开发语言·人工智能·c#·语音识别
爱学习的爬虫1 小时前
Python实现Jenkins实现自动化执行Job
python·自动化·jenkins
一晌小贪欢1 小时前
Python爬虫第9课:验证码识别与自动化处理
爬虫·python·自动化·网络爬虫·python爬虫·python3