0°,30°,60°,90°,120°,150°的偏振图片
时间: 2024-03-22 11:38:30 浏览: 19
这里是一个简单的 Python 代码,用于生成偏振角为 0°,30°,60°,90°,120°,150°的偏振图片。需要安装 Pillow 库。
```python
from PIL import Image
import numpy as np
import math
# 图片宽度和高度
width = 200
height = 200
# 构建一个黑色的底图
img = np.zeros((height, width, 3), dtype=np.uint8)
# 循环生成六张偏振图片
for i in range(6):
# 计算偏振角度
angle = i * 30
# 计算偏振方向
direction = np.array([math.cos(math.radians(angle)), math.sin(math.radians(angle)), 0])
# 计算偏振后的图像
polarizer = np.outer(direction, direction)
polarized_img = np.dot(img, polarizer)
# 将像素值缩放到 0 到 255 之间
polarized_img = (255 * (polarized_img - polarized_img.min()) / (polarized_img.max() - polarized_img.min())).astype(np.uint8)
# 将偏振后的图像保存为文件
Image.fromarray(polarized_img).save(f"{angle}.jpg")
```
这个代码会在当前目录下生成 0.jpg,30.jpg,60.jpg,90.jpg,120.jpg,150.jpg 六张偏振图片。