Files
task-3-1-3-Matrix-Fundament…/import numpy as np.py
2026-04-16 16:05:17 +08:00

30 lines
688 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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)