完成作业X

This commit is contained in:
2509165030
2026-04-16 16:05:17 +08:00
parent 5ab002efbc
commit 7a0ea130aa
3 changed files with 83 additions and 0 deletions

30
import numpy as np.py Normal file
View File

@@ -0,0 +1,30 @@
import numpy as np
# 定义原始图像矩阵
image = np.array([
[100, 150, 200],
[80, 120, 180],
[60, 90, 140]
], dtype=np.uint8)
print("原图:")
print(image)
print("-" * 20)
# 1. 变暗20每个像素值减20
# 注意uint8类型不会出现负数自动取模小于0会变成255附近
image_dark = image - 20
print("1. 变暗20后的图像:")
print(image_dark)
print("-" * 20)
# 2. 裁剪左上角:保留 image[0:2, 0:2]
image_crop = image[0:2, 0:2]
print("2. 裁剪左上角2*2区域:")
print(image_crop)
print("-" * 20)
# 3. 水平翻转:使用 np.fliplr()
image_flip = np.fliplr(image)
print("3. 水平翻转后的图像:")
print(image_flip)