Files
task-3-1-3-Matrix-Fundament…/2509165016--1.py
2026-04-16 15:29:50 +08:00

26 lines
576 B
Python
Raw Permalink 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
# 定义3x3灰度图像
image = np.array([
[100, 150, 200],
[80, 120, 180],
[60, 90, 140]
], dtype=np.uint8)
print("原图:")
print(image)
# 1. 变暗20每个像素值减20需确保数值非负uint8会自动截断这里手动保证
image_dark = np.clip(image - 20, 0, 255)
print("\n变暗20后")
print(image_dark)
# 2. 裁剪左上角2x2区域
image_crop = image[:2, :2]
print("\n裁剪左上角2x2区域")
print(image_crop)
# 3. 水平翻转
image_flip = np.fliplr(image)
print("\n水平翻转:")
print(image_flip)