このリンクをたどって、画像にアナモルフォシスを実行しようとしました
https://github.com/aydal/Cylinderical-Anamorphosis/blob/master/anamorph.py
それはアナモフィックなイメージを与えますが、そのイメージは半円で与えられます。しかし、私は完全な円のサイズで出力したい。で試しました
warp[c-j, i-1] = img[p-1, q-1]
warp[c+j, i-1] = img[p-1, q-1]
それ以外のwarp[c-j, i-1] = img[p-1, q-1]
しかし、それは完全な円で1つの画像を与えるのではなく、同じ出力を2回作成します!
誰でも私を助けてください。
完全なコード:
import math
from cv2 import *
import numpy as np
img = imread("test.jpg")
(rows, cols) = (img.shape[0], img.shape[1])
r = 0 #offset-gives space to keep cylinder and height of the image from bottom: original: math.trunc(.25*rows)
c = rows #this will be the decisive factor in size of output image-maximum radius of warped image: original: c = r+rows
warp = np.zeros([c,2*c,3], dtype=np.uint8)
def convert(R, b):
return math.trunc(b*rows/(2*math.asin(1))), math.trunc(c-R)
for i in range(0, 2*c):
for j in range(1, c):
b = math.atan2(j, i-c)
R = math.sqrt(j*j+math.pow(i-c, 2))
if R>=r and R<=c:
(q, p) = convert(R, b)
warp[c-j, i-1] = img[p-1, q-1]
#warp[c+j, i-1] = img[p-1, q-1]
imshow("Output", warp)
waitKey()