利用 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')

五、实验体会

相关推荐
天远云服19 分钟前
天远企业司法认证API对接实战:PHP构建B2B供应链合规防火墙
大数据·开发语言·后端·node.js·php
空空kkk25 分钟前
Java基础——代理
java·开发语言
赵谨言26 分钟前
基于YOLOv5的植物目标检测研究
大数据·开发语言·经验分享·python
野生技术架构师27 分钟前
互联网大厂必备 Java 面试八股文真题解析
java·开发语言·面试
不光头强33 分钟前
IO流知识点
开发语言·python
老约家的可汗33 分钟前
C++篇之类和对象下
java·开发语言·c++
水月wwww35 分钟前
Rust的安装与卸载 | windows
开发语言·windows·rust
SouthRosefinch43 分钟前
一、HTML简介与开发环境
开发语言·前端·html
€8111 小时前
Java入门级教程27——ActiveMQ的下载与应用
java·开发语言·activemq·点对点文本消息发送·点对点对象消息发送·mysql+redis·序列化对象消息传输
Irissgwe1 小时前
C&C++内存管理
c语言·开发语言·c++·c++内存管理