将图像从笛卡尔坐标转换为极坐标-肢体变暗 [英] Converting an image from Cartesian to Polar - Limb Darkening

查看:450
本文介绍了将图像从笛卡尔坐标转换为极坐标-肢体变暗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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?

像这个例子:

或例如以下示例:

由于某种原因,我在MATLAB中找到了许多示例,但在Python中却没有找到一个示例.我一直在看这来自opencv ,但我我不完全确定这就是我想要的,因为我想保持原始图像/阵列的大小.我知道转换为极坐标会扭曲"图像,但这很好,我主要要做的是测量从中心到边缘的太阳圆盘强度,并绘制强度与半径的函数,因此我可以测量四肢变黑.

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.

推荐答案

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

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:

代码:

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

结果:

这篇关于将图像从笛卡尔坐标转换为极坐标-肢体变暗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆