我试图找到一个好的包或算法来修改图像以向外推动图像的中心以模仿黄斑变性。我找到的最好的方法是image_slicer包并将图像分成4个部分,推动内角并将图像缝合回来。但是,包的连接方法不起作用,文档不清楚。有人有一个可以做到这一点的包吗?
此外,我正试图将图像的外部推入,以创建隧道视觉。
(对于这两个我仍然试图保留图像,虽然偏斜很好,我试图防止图像丢失。)
我写的一些代码
import image_slicer
#split image into 4 pieces
image_slicer.slice('piegraph.jpeg',4) #just a simple sample img
#code to resize corners
#I can figure this out later.
#stitch images back
tiles = ("pie_01_01.png","pie_01_02.png","pie_02_01.png","pie_02_02.png")
image_slicer.join(tiles)
答案 0 :(得分:1)
你可以使用opencv和numpy来做你想做的事。
如果我理解正确您需要的是一张采用原始图像并将其映射为距图像中心距离的函数的映射。
对于"黑洞内的所有像素"你想成为黑人,而你希望他们聚在一起的所有其他人。
因此,如果我们将原始图像设为:
您正在寻找的结果如下:
以下代码用于此。您需要使用的参数是
RBlackHole - 黑洞的半径
因素 - 改变"聚束"太小,所有像素也会映射到黑色太大而且不会聚集。
import cv2
import numpy as np
import math
# Read img
img = cv2.imread('earth.jpg')
rows,cols,ch = img.shape
# Params
FACTOR = 75
RBlackHole = 10
# Create a 2d mapping between the image and a new warp
smallSize = min(rows,cols)
xMap = np.zeros((rows,cols), np.float32)
yMap = np.zeros_like(xMap)
for i in range(rows):
for j in range(cols):
# Calculate the distance of the current pixel from the cneter of the image
r = math.sqrt((i-rows/2)*(i-rows/2) + (j-cols/2)*(j-cols/2))
# If the pixles are in the radius of the black hole
# mapped them to a location outside of the image.
if r <= RBlackHole:
xMap[i, j] = rows*cols
yMap[i, j] = rows*cols
else:
# Mapped the pixels as a function of the distance from the center.
# The further thay are the "buncher thay will be"
xMap[i, j] = (r-RBlackHole)*(j - cols/2)/FACTOR + cols/2
yMap[i, j] = (r-RBlackHole)*(i - rows/2)/FACTOR + rows/2
# Applay the remmaping
dstImg = cv2.remap(img,xMap,yMap,cv2.INTER_CUBIC)
# Save output image
cv2.imwrite("blackHoleWorld.jpg", dstImg)