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

新手上路,请多包涵
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()

我正在使用的太阳盘:

我正在使用的太阳能圆盘图片

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

像这个例子:

像这个例子

或者像这个例子:

或者像这个例子

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

原文由 DankEmperor 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 1.4k
2 个回答

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

代码

 import cv2
import numpy as np

source = cv2.imread('image_path', 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()

结果:

在此处输入图像描述

原文由 Jeru Luke 发布,翻译遵循 CC BY-SA 4.0 许可协议

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

 convert sun.jpg +distort DePolar 0 result.jpg

在此处输入图像描述

Anthony Thyssen 在这里 提供了一些极好的提示和技巧。

原文由 Mark Setchell 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题