Converting an image from Cartesian to Polar - Limb Darkening

前端 未结 3 1671
迷失自我
迷失自我 2021-02-08 01:49
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)         


        
3条回答
  •  不思量自难忘°
    2021-02-08 02:03

    OpenCV has functions to convert images from Cartesian form to Polar and vice-versa. Since you require to convert the image to polar form the following can be adopted:

    Code:

    import cv2
    import numpy as np
    
    source = cv2.imread('C:/Users/selwyn77/Desktop/sun.jpg', 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()
    

    Result:

提交回复
热议问题