将图像从笛卡尔坐标转换为极坐标 - 肢体变暗
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()
我正在使用的太阳盘:
我想知道是否有一种简单的方法可以将图像从笛卡尔坐标转换为极坐标坐标?
像这个例子:
或者像这个例子:
出于某种原因,我在 MATLAB 中找到了很多示例,但我还没有在 Python 中找到一个示例。我一直在查看 this from opencv,但我不完全确定它是我想要的,因为我想保持原始 image/array 大小。我知道转换为极坐标会使图像 'screw' 向上,但这很好,我想做的主要事情是测量太阳圆盘从中心到边缘的强度,绘制强度与函数的关系图半径所以我可以测量肢体变黑。
您可以在终端中使用 ImageMagick 在命令行上进行极坐标笛卡尔失真 - 它安装在大多数 Linux 发行版上,可用于 macOS 和Windows:
convert sun.jpg +distort DePolar 0 result.jpg
Anthony Thyssen here 提供了一些极好的提示和技巧。
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()
结果:
scikit-image 也提供了沿这些思路的转换。参见 skimage.transform.warp_polar。
注意,这确实引入了像素强度的插值。
有关用法示例,另请参阅 polar demo。
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 中找到一个示例。我一直在查看 this from opencv,但我不完全确定它是我想要的,因为我想保持原始 image/array 大小。我知道转换为极坐标会使图像 'screw' 向上,但这很好,我想做的主要事情是测量太阳圆盘从中心到边缘的强度,绘制强度与函数的关系图半径所以我可以测量肢体变黑。
您可以在终端中使用 ImageMagick 在命令行上进行极坐标笛卡尔失真 - 它安装在大多数 Linux 发行版上,可用于 macOS 和Windows:
convert sun.jpg +distort DePolar 0 result.jpg
Anthony Thyssen here 提供了一些极好的提示和技巧。
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()
结果:
scikit-image 也提供了沿这些思路的转换。参见 skimage.transform.warp_polar。
注意,这确实引入了像素强度的插值。
有关用法示例,另请参阅 polar demo。