完成作业一:3-1-3

This commit is contained in:
2509165031
2026-04-16 15:54:57 +08:00
parent db73c2d474
commit bc6c115d45
3 changed files with 85 additions and 0 deletions

32
0416 2.py Normal file
View File

@@ -0,0 +1,32 @@
import numpy as np
# 定义4×4图像矩阵
img = np.array([
[255, 255, 0, 0],
[255, 255, 0, 0],
[0, 0, 255, 255],
[0, 0, 255, 255]
], dtype=np.uint8)
print("原始图像:")
print(img)
print("-" * 30)
# 1. 统计白色(255)和黑色(0)像素数量
white_count = np.sum(img == 255)
black_count = np.sum(img == 0)
print(f"白色像素(255)数量:{white_count}")
print(f"黑色像素(0)数量:{black_count}")
print("-" * 30)
# 2. 水平翻转并打印
img_flip = np.fliplr(img)
print("水平翻转后图像:")
print(img_flip)
print("-" * 30)
# 3. 逆时针旋转90度转置+上下翻转)
# 方法:先转置,再上下翻转(np.flipud)
img_rot90_ccw = np.flipud(img.T)
print("逆时针旋转90度后图像")
print(img_rot90_ccw)