简体   繁体   English

将图像从笛卡尔坐标转换为极坐标 - 肢体变暗

[英]Converting an image from Cartesian to Polar - Limb Darkening

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()

The solar disc I'm using:我正在使用的太阳能盘:

我正在使用的太阳能盘的图像

I'm wondering if there is an easy way to convert the image from cartesian to polar?我想知道是否有一种简单的方法可以将图像从笛卡尔坐标转换为极坐标?

Like this example:像这个例子:

像这个例子

Or like this example:或者像这个例子:

或者像这个例子

For some reason, I've found many examples in MATLAB but I've yet to find one in Python.出于某种原因,我在 MATLAB 中找到了许多示例,但我还没有在 Python 中找到一个。 I've been looking at this from opencv but I'm not entirely sure it's what I want, as I want to keep the original image/array size.我一直在从 opencv这个,但我不完全确定这是我想要的,因为我想保持原始图像/数组大小。 I know converting to polar will 'screw' up the image but that is fine, the main thing I'm wanting to do is measure the intensity of the solar disk from the center out to the edge, plotting a function of intensity vs radius so I can measure limb darkening.我知道转换为极坐标会“搞砸”图像,但这很好,我想做的主要事情是测量太阳盘从中心到边缘的强度,绘制强度与半径的函数,所以我可以测量肢体变黑。

OpenCV has functions to convert images from Cartesian form to Polar and vice-versa. OpenCV 具有将图像从笛卡尔形式转换为极坐标形式的功能,反之亦然。 Since you require to convert the image to polar form the following can be adopted:由于您需要将图像转换为极坐标形式,因此可以采用以下方法:

Code :代码

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()

Result:结果:

在此处输入图片说明

You can do polar-cartesian distortion just on the command line with ImageMagick in the Terminal - it is installed on most Linux distros and is available for macOS and Windows:您可以在终端中使用ImageMagick在命令行上进行极坐标失真 - 它安装在大多数 Linux 发行版上,可用于 macOS 和 Windows:

convert sun.jpg +distort DePolar 0 result.jpg

在此处输入图片说明

There are some excellent hints and tips from Anthony Thyssen here .有安东尼蒂森一些优秀的提示和技巧在这里

scikit-image also offers a transformation along these lines. scikit-image 也提供了沿着这些方向的转换。 See skimage.transform.warp_polar .skimage.transform.warp_polar

Note, this does introduce an interpolation of pixel intensities.请注意,这确实引入了像素强度的插值。

See also polar demo for usage examples.有关使用示例,另请参阅polar 演示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM