30 lines
688 B
Python
30 lines
688 B
Python
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) |