完成作业3-1-3
This commit is contained in:
26
2509165016--1.py
Normal file
26
2509165016--1.py
Normal file
@@ -0,0 +1,26 @@
|
||||
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)
|
||||
Reference in New Issue
Block a user