Converting an image from Cartesian to Polar - Limb Darkening

女生的网名这么多〃 提交于 2019-12-09 12:41:34

问题


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. 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. 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.


回答1:


OpenCV has functions to convert images from Cartesian form to Polar and vice-versa. 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:




回答2:


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:

convert sun.jpg +distort DePolar 0 result.jpg

There are some excellent hints and tips from Anthony Thyssen here.



来源:https://stackoverflow.com/questions/51675940/converting-an-image-from-cartesian-to-polar-limb-darkening

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!