首页 > 编程知识 正文

极坐标与笛卡尔坐标相互转化(python笛卡尔转换极坐标,将图像从笛卡尔坐标转换为极坐标-肢体变暗)

时间:2023-05-05 19:24:09 阅读:121634 作者:4022

import numpy as np

导入cv2

frommatplotlibimportpyplotasplt

img=cv2.im read (c : (用户(not my username (桌面) (20140505 ) 124500 ) 4096 ) hmiIC.jpg ) )。

孤独的夕阳_image=cv2 .孤独的夕阳alize(img,dst=None,孤独的夕阳_type=cv2.NORM_MINMAX,dtype=cv2.CV_32F )。

plt.imshow (孤独的夕阳_image,cmap='afmhot ',interpolation='bicubic ' ) )。

PLT.xticks([,PLT.yticks ) [ ] ) ) )。

plt.show () )

The solar disc I'm using:

I ' mwonderingifthereisaneasywaytoconverttheimagefromcartesiantopolar?

Like this example:

Or like this example:

For some reason,I ' vefoundmanyexamplesinmatlabbuti ' veyettofindoneinpython.I ' vebeenlookingatthisfromopencvbuti ' mnotententtion asiwanttokeeptheoriginalimage/array size.iknowconvertingtopolarwill ' screw ' uptheimagebutthatisfine, themainthingi ' mwantingtodoismeasuretheintensityofthesolardiskfromthecenterouttotheedge,plottingafunctionofintensityvsradiuradiue

解决方案

代码:

导入cv2

import numpy as np

source=cv2.im read (c :/users/selwyn 77/desktop/sun.jpg ',1 ) )

----ensureimageisofthetypefloat-- -

img=source.astype(NP.float32 ) )

----thefollowingholdsthesquarerootofthesumofsquaresoftheimagedimensions----

--- thisisdonesothattheentirewidth/heightoftheoriginalimageisusedtoexpressthecompletecularrangeoftheresultingpolarimagth

value=NP.sqrt ((img.shape [0]/2.0 ) *2.0 ) ) img.shape[1]/2.0 ) **2.0 ) )

polar _ image=cv2.linear polar (img,(img.shape[0]/2,img.shape[1]/2 ),value,cv2.warp_fill_ool

polar _ image=polar _ image.as type (NP.uint8) )。

CV2.imshow(polarimage ),polar_image ) )。

cv2 .等待密钥(0) () ) ) ) ) ) ) ) ) ) ) )。

cv2.destroyAllWindows (

结果:

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。