圆柱投影python代码
时间: 2023-11-16 17:56:17 浏览: 144
python图像柱面投影代码
下面是圆柱投影的Python实现代码:
```
from skimage.io import imread, imshow, imsave
from skimage.transform import resize
import math
import numpy as np
img = imread('img.jpg')
img = (resize(img, [1000, 800]) * 255).astype(np.uint8)
###圆柱投影
def cylindrical_projection(img, f):
rows = img.shape[0]
cols = img.shape[1]
# f = cols / (2 * math.tan(np.pi / 8))
blank = np.zeros_like(img)
center_x = int(cols / 2)
center_y = int(rows / 2)
for y in range(rows):
for x in range(cols):
theta = math.atan((x - center_x) / f)
point_x = int(f * math.tan((x - center_x) / f) + center_x)
point_y = int((y - center_y) / math.cos(theta) + center_y)
if point_x >= cols or point_x < 0 or point_y >= rows or point_y < 0:
pass
else:
blank[y, x, :] = img[point_y, point_x, :]
return blank
waved_img = cylindrical_projection(img, 500)
imshow(waved_img)
```
其中,`img`是原始图像,`f`是圆柱投影的参数,`waved_img`是圆柱投影后的图像。
阅读全文