Converting 2x2 Matrix into a Polar Function f(r,theta)

Hello, I am pretty new in using Igor Pro and any input from the more experienced users will be very much appreciated. So I have a 2x2 matrix corresponding to an intensity image. The structures of interest are circular and so what I'd like to do is average the intensity over all angles for a given radius. To do this, I am thinking of designating a center and converting the 2x2 matrix into a polar function f(r,theta) and then later on integrate that function over theta so I can get an intensity profile vs radius plot. Does this sound doable in Igor Pro or is there an easier more convenient way to do this? Somebody suggested something about 2D interpolation but I haven't any idea about that yet. Thank you for your inputs!
It would be useful if you explained the nature of your 2x2 matrix. If all you have are 4 values there is little point in trying to compute an (r,theta). In general, given a matrix with a defined origin (Xc,Yc) you can perform conversions for any (x,y) in the domain:
Variable rr=sqrt((x-xc)^2+(y-yc)^2)
Variable theta=atan2((y-yc),(x-xc))

This means that for a 2D matrix you can write:
Function f(rr,theta,dataWave,xc,yc)
    Variable rr,theta,xc,yc
    Wave dataWave
    Variable xx=rr*cos(theta)+xc
    Variable yy=rr*sin(theta)+yc
    return interp2d(dataWave,xx,yy)
End


I hope this helps,

A.G.
Igor wrote:
It would be useful if you explained the nature of your 2x2 matrix. If all you have are 4 values there is little point in trying to compute an (r,theta). In general, given a matrix with a defined origin (Xc,Yc) you can perform conversions for any (x,y) in the domain:
Variable rr=sqrt((x-xc)^2+(y-yc)^2)
Variable theta=atan2((y-yc),(x-xc))

This means that for a 2D matrix you can write:
Function f(rr,theta,dataWave,xc,yc)
    Variable rr,theta,xc,yc
    Wave dataWave
    Variable xx=rr*cos(theta)+xc
    Variable yy=rr*sin(theta)+yc
    return interp2d(dataWave,xx,yy)
End


I hope this helps,

A.G.


Hello A.G.,
I have made a mistake in my previous posts. I am actually working on a 512x512 matrix, not a 2x2 matrix. What I was trying to say was that I'm dealing with a 2-dimensional wave.
Thank you very much for your inputs! I appreciate them.
Igor wrote:
It would be useful if you explained the nature of your 2x2 matrix. If all you have are 4 values there is little point in trying to compute an (r,theta). In general, given a matrix with a defined origin (Xc,Yc) you can perform conversions for any (x,y) in the domain:
Variable rr=sqrt((x-xc)^2+(y-yc)^2)
Variable theta=atan2((y-yc),(x-xc))

This means that for a 2D matrix you can write:
Function f(rr,theta,dataWave,xc,yc)
    Variable rr,theta,xc,yc
    Wave dataWave
    Variable xx=rr*cos(theta)+xc
    Variable yy=rr*sin(theta)+yc
    return interp2d(dataWave,xx,yy)
End


I hope this helps,

A.G.


Hello again,
I don't know what I'm doing wrong but I keep getting the command error "expected wave name, variable name, or operation" when I run the function procedure. I am using Igor Pro 7.02. Any insights about this? Thank you.

shifuxian wrote:

I don't know what I'm doing wrong but I keep getting the command error "expected wave name, variable name, or operation" when I run the function procedure. I am using Igor Pro 7.02. Any insights about this? Thank you.


It is difficult to answer your question without knowing precisely what you are trying to execute, when you are getting this error message and what are the names of the waves involved.
Igor wrote:
shifuxian wrote:

I don't know what I'm doing wrong but I keep getting the command error "expected wave name, variable name, or operation" when I run the function procedure. I am using Igor Pro 7.02. Any insights about this? Thank you.


It is difficult to answer your question without knowing precisely what you are trying to execute, when you are getting this error message and what are the names of the waves involved.


Dear A.G.,
I have solved the previous problem. Thanks!
Here is the nature of the calculation that I want to do. I have intensity profile images and first I want to re-scale (maybe just change the aspect ratio) to force the ring-like structures to be circles (ideally, they should be circular). With this process however, my 2D wave remains unchanged and is still non-square (I think). Then, what I want to do is perform interpolation to get an f(r,theta) and integrate over all theta to get an intensity vs. radius plot, averaged over theta. Do you have any similar routines for such a calculation? Thank you. I am attaching a sample intensity profile image and the corresponding wave.

PS: If the projection on the x-y plane is not a circle, then the limits of integration for r will be in the form of functions. This is a difficulty for me.
Graph4.jpg (321.75 KB) Trial.txt (577.31 KB)