Plotting a matrix cartesian coordinate using polar coordinates

I know the matrix f [r, phi] in polar coordinate. I want to plot it in cartesian coordinate. Below is my code:

import numpy as np
import math

f = np.zeros((1024,90))  #In polar co-ordinate 

D = 0.28                #Source to isocenter distance
h = np.zeros(1024)
h[0:512] = np.linspace(0,1,512)
h[513:] = np.linspace(1,0,511) 

for r in range(0,1024) :
    for phi in range(0,90) :
        for b in range(0,360) :
            for s in range(0,1024) :
                U = (D + r*sin(b-phi))/D
                l = math.pow(U,-2)
                k = D/(math.pow((math.pow(D,2)+math.pow(s,2)),0.5))   
                f[r,phi] = 0.5*l*k*q[s,b]*h[s]

I =np.zeros((725,725))

for x in range(1,726) :
    for y in range(1,726) :
        r = math.pow(x,2)+math.pow(y,2)
        phi = math.degrees(math.atan(y/x))
        I[x,y] = f[r,phi]

      

Here the polar coordinate r varies from (0.1024) and phi from (0.90). But I applied filter h which is a ramp filter. So the final f doesn't have exactly 1024 * 90 elements. I want to plot an image f in cartesian coordinate and I set the size to (725,725) which is flexible. But I am getting the following error.

I[x,y] = f[r,phi]
IndexError: index (1025) out of range (0<=index<1024) in dimension 0

      

Can anyone suggest me a way to plot the function f in Cartesian coordinate?

+3


source to share





All Articles