比较python中opencv lineartoPolar()转换

2024-09-30 20:20:41 发布

您现在位置:Python中文网/ 问答频道 /正文

我的目标是将二维功率谱从笛卡尔坐标转换为极坐标。在

imshow(np.log10(psd2shift),cmap=cm.jet)

enter image description here stackoverflow上有几篇关于如何做到这一点的文章,比如link。所以我相信我的密码是正确的。在

^{pr2}$

enter image description here

尽管如此,我还是得不到我想要的: enter image description here

显然,在转换中有一个差异,尽管我已经深入研究了linearPolar函数或文档here,但我还是未能揭示这一点。似乎中心的定义不正确,但我很确定是。想法?在

使用help(cv.linearPolar) 退货: 关于内置函数linearPolar的帮助:

linearPolar(...)
    linearPolar(src, center, maxRadius, flags[, dst]) -> dst
    .   @brief Remaps an image to polar coordinates space.
    .   
    .   @anchor polar_remaps_reference_image
    .   ![Polar remaps reference](pics/polar_remap_doc.png)
    .   
    .   Transform the source image using the following transformation:
    .   \f[\begin{array}{l}
    .   dst( \rho , \phi ) = src(x,y) \\
    .   dst.size() \leftarrow src.size()
    .   \end{array}\f]
    .   
    .   where
    .   \f[\begin{array}{l}
    .   I = (dx,dy) = (x - center.x,y - center.y) \\
    .   \rho = Kx \cdot \texttt{magnitude} (I) ,\\
    .   \phi = Ky \cdot \texttt{angle} (I)_{0..360 deg}
    .   \end{array}\f]
    .   
    .   and
    .   \f[\begin{array}{l}
    .   Kx = src.cols / maxRadius \\
    .   Ky = src.rows / 360
    .   \end{array}\f]
    .   
    .   
    .   @param src Source image
    .   @param dst Destination image. It will have same size and type as src.
    .   @param center The transformation center;
    .   @param maxRadius The radius of the bounding circle to transform. It determines the inverse magnitude scale parameter too.
    .   @param flags A combination of interpolation methods, see cv::InterpolationFlags
    .   
    .   @note
    .   -   The function can not operate in-place.
    .   -   To calculate magnitude and angle in degrees @ref cv::cartToPolar is used internally thus angles are measured from 0 to 360 with accuracy about 0.3 degrees.

Tags: thetoimagesrcsizeparamarraycv
1条回答
网友
1楼 · 发布于 2024-09-30 20:20:41

我的第一印象是你可能弄乱了中心的坐标。OpenCV中的点被称为(x,y),它被错误地翻译为(col, row)。交换你的代码

ro,col=img.shape
cent=(int(col/2),int(ro/2))
max_radius = int(np.sqrt(ro**2+col**2)/2)
polar=cv2.linearPolar(img,cent,max_radius,cv2.WARP_FILL_OUTLIERS)

plt.figure(figsize=(16,10))
plt.imshow(polar,cmap='jet', interpolation='bicubic')
plt.show()

我想我想要的是接近你的形象。在

enter image description here

相关问题 更多 >