【问题标题】:Comparing opencv lineartoPolar() transformation in python比较python中的opencv lineartoPolar()转换
【发布时间】:2019-09-04 21:26:58
【问题描述】:

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

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

stackoverflow 上有几篇关于如何做到这一点的帖子,例如link。所以我相信我的代码是正确的。

ro,col=psd2shift.shape
cent=(int(ro/2),int(col/2))
max_radius = int(np.sqrt(ro**2+col**2)/2)
polar=cv.linearPolar(np.log10(psd2shift),cent,max_radius,cv.WARP_FILL_OUTLIERS)
plt.imshow(polar,cmap=cm.jet, interpolation='bicubic')

尽管如此,我没有得到我想要的,这是:

显然,尽管借助 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.

【问题讨论】:

  • 如果您包含原始图像(psd2shift)会有所帮助。
  • 我指的是实际图片,不是plt.imshow显示的图片

标签: python numpy opencv polar-coordinates cartesian


【解决方案1】:

我的第一印象是您可能弄乱了中心的坐标。 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()

我得到了图像,我认为它与您想要的很接近。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-06-06
  • 1970-01-01
  • 1970-01-01
  • 2023-04-04
  • 1970-01-01
  • 1970-01-01
  • 2013-01-29
相关资源
最近更新 更多