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

shifuxian
Posts: 14
Joined: 2017-10-04
Location: Japan

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!


s.r.chinn
Posts: 326
Joined: 2007-08-16
Location: United States

For some related guidelines and approaches take a look at A.G.'s blog post:
https://www.igorpro.net/blog/2017/4/4/how-to-average-data-over-an-annula...


shifuxian
Posts: 14
Joined: 2017-10-04
Location: Japan

s.r.chinn wrote:
For some related guidelines and approaches take a look at A.G.'s blog post:
https://www.igorpro.net/blog/2017/4/4/how-to-average-data-over-an-annular-domain

Thank you very much for your reply! I find the blog entry very helpful!


shifuxian
Posts: 14
Joined: 2017-10-04
Location: Japan

s.r.chinn wrote:
For some related guidelines and approaches take a look at A.G.'s blog post:
https://www.igorpro.net/blog/2017/4/4/how-to-average-data-over-an-annular-domain

Hello, in this particular approach, does the command Interp2d automatically give the f(r,theta) function for my 2x2 matrix? I'm confused as to how I can acquire my f(r,theta). Any help would be very much appreciated. Thank you.


Igor's picture
Posts: 764
Joined: 2007-06-29
Location: United States

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.


thomas_braun
Posts: 515
Joined: 2009-10-07
Location: Germany

Don't forget the builtin functions r2polar and p2rect.


shifuxian
Posts: 14
Joined: 2017-10-04
Location: Japan

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.


shifuxian
Posts: 14
Joined: 2017-10-04
Location: Japan

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.


Igor's picture
Posts: 764
Joined: 2007-06-29
Location: United States

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.


shifuxian
Posts: 14
Joined: 2017-10-04
Location: Japan

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.

AttachmentSize
Trial.txt577.31 KB
Graph4.jpg1.13 MB

Back to top