Python 将图像从笛卡尔坐标变换为极轴边缘变暗

Python 将图像从笛卡尔坐标变换为极轴边缘变暗,python,python-3.x,opencv,matplotlib,polar-coordinates,Python,Python 3.x,Opencv,Matplotlib,Polar Coordinates,我正在使用的太阳能光盘: 我想知道是否有一种简单的方法可以将图像从笛卡尔坐标转换为极坐标 像这个例子: 或者像这个例子: 出于某种原因,我在MATLAB中找到了许多示例,但在Python中还没有找到。我一直在看,但我不完全确定这是我想要的,因为我想保持原始图像/阵列大小。我知道转换成极光会“搞乱”图像,但这很好,我想做的主要事情是测量太阳圆盘从中心到边缘的强度,绘制强度与半径的函数,以便我可以测量肢体变暗。您可以使用终端中的ImageMagick在命令行上进行极坐标笛卡尔变形-它安装在大多

我正在使用的太阳能光盘:

我想知道是否有一种简单的方法可以将图像从笛卡尔坐标转换为极坐标

像这个例子:

或者像这个例子:


出于某种原因,我在MATLAB中找到了许多示例,但在Python中还没有找到。我一直在看,但我不完全确定这是我想要的,因为我想保持原始图像/阵列大小。我知道转换成极光会“搞乱”图像,但这很好,我想做的主要事情是测量太阳圆盘从中心到边缘的强度,绘制强度与半径的函数,以便我可以测量肢体变暗。

您可以使用终端中的ImageMagick在命令行上进行极坐标笛卡尔变形-它安装在大多数Linux发行版上,适用于macOS和Windows:

import numpy as np
import cv2
from matplotlib import pyplot as plt

img = cv2.imread('C:\\Users\\not my user name\\Desktop\\20140505_124500_4096_HMIIC.jpg', 0)

norm_image = cv2.normalize(img, dst=None, norm_type=cv2.NORM_MINMAX, dtype=cv2.CV_32F)

plt.imshow(norm_image, cmap='afmhot', interpolation='bicubic')
plt.xticks([]), plt.yticks([])
plt.show()


安东尼·蒂森(Anthony Thyssen)提供了一些极好的提示和技巧。

OpenCV具有将图像从笛卡尔形式转换为极坐标形式的功能,反之亦然。由于您需要将图像转换为极坐标形式,因此可以采用以下方法:

代码

convert sun.jpg +distort DePolar 0 result.jpg
结果:


scikit image还提供了这些方面的转换。看

注意,这确实引入了像素强度的插值


另请参见使用示例。

Python Wand允许ImageMagick的失真。看见但是,我似乎找不到提到的失真方法列表。您可以使用
cv2.linearPolar()
import cv2
import numpy as np

source = cv2.imread('C:/Users/selwyn77/Desktop/sun.jpg', 1)

#--- ensure image is of the type float ---
img = source.astype(np.float32)

#--- the following holds the square root of the sum of squares of the image dimensions ---
#--- this is done so that the entire width/height of the original image is used to express the complete circular range of the resulting polar image ---
value = np.sqrt(((img.shape[0]/2.0)**2.0)+((img.shape[1]/2.0)**2.0))

polar_image = cv2.linearPolar(img,(img.shape[0]/2, img.shape[1]/2), value, cv2.WARP_FILL_OUTLIERS)

polar_image = polar_image.astype(np.uint8)
cv2.imshow("Polar Image", polar_image)

cv2.waitKey(0)
cv2.destroyAllWindows()