【发布时间】:2013-05-15 06:43:51
【问题描述】:
我正在尝试将图像从笛卡尔转换为极坐标,以便解开图像,但出现运行时错误。如果您对它的视觉效果感到好奇,请参阅 this example.
代码:
import scipy
import scipy.ndimage
import numpy as np
from math import *
import cv2
def logpolar(input):
# This takes a numpy array and returns it in Log-Polar coordinates.
coordinates = np.mgrid[0:max(input.shape[:])*2,0:360] # We create a cartesian array which will be used to compute log-polar coordinates.
log_r = 10**(coordinates[0,:]/(input.shape[0]*2.)*log10(input.shape[1])) # This contains a normalized logarithmic gradient
angle = 2.*pi*(coordinates[1,:]/360.) # This is a linear gradient going from 0 to 2*Pi
# Using scipy's map_coordinates(), we map the input array on the log-polar coordinate. Do not forget to center the coordinates!
lpinput = scipy.ndimage.interpolation.map_coordinates(input,(log_r*np.cos(angle)+input.shape[0]/2.,log_r*np.sin(angle)+input.shape[1]/2.),order=3,mode='constant')
# Returning log-normal...
return lpinput
# Load image
image = cv2.imread("test.jpg")
result = logpolar(image)
控制台中的错误消息:
【问题讨论】:
-
我的第一个猜测是您传入的是 3 维彩色图像。乍一看,我认为您的代码无法处理。
-
嘿锤子你介意让你的评论成为答案吗?另外,解释一下你是如何得出你的猜测的?如果您想知道,您是对的,因为它是彩色图像 =)
-
当然,很高兴它有帮助:)
标签: python opencv python-2.7 numpy scipy