完成作业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

32
9999.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_pixels = np.sum(img == 255) # 等于255的元素求和
black_pixels = np.sum(img == 0) # 等于0的元素求和
print(f"白色像素(255)数量:{white_pixels}")
print(f"黑色像素(0)数量:{black_pixels}")
print("-" * 30)
# 2. 水平翻转(左右翻转)
img_flip_lr = np.fliplr(img)
print("水平翻转后的图像:")
print(img_flip_lr)
print("-" * 30)
# 3. 逆时针旋转90度转置 + 上下翻转)
# 方法:先转置,再上下翻转
img_rot90_ccw = np.flipud(img.T)
print("逆时针旋转90度后的图像:")
print(img_rot90_ccw)