how to make a oval to a circle in a 2d wave

Hey all,

I have a 2D binary value wave (eg, 256*256 pixels wave storing only 0 and 1). The middle area pixels are 1 and the rest are 0. If we view the wave as an image, there should have a circle shape in the center of the image (eg, center is (128, 128) and radius = 50). However, a wave which has a oval in the middle area (a little off circle shape). My question is that is there a function in Igor that I can "fit" the oval in to a circle shape?

Thanks!
Could you please explain your usage of "fit"? Mathematical or "squeeze" or representation or ...
A sample experiment (creation, waves and the image) would be amazingly useful to help you.

HJ
HJDrescher wrote:
Could you please explain your usage of "fit"? Mathematical or "squeeze" or representation or ...
A sample experiment (creation, waves and the image) would be amazingly useful to help you.

HJ



Hey HJ,

Thanks for your reply.

The problems I met is that I have 2 sets of 2D waves. One set is a stack of simulation 2D waves. The first wave of the stack is a binary value wave in which the middle area is 1 and surrounding area is 0. So the image looks like a bright circle sitting in the dark background. The rest of the first stack images have the same bright area(the size and position), but have some patterns inside the circle area. The second set is the same as the first one, but it's from experiment. Because of some non-ideal condition in the experiment, the bright area has a little deformation and is a oval.

Because I want to compare the patterns in the 2 sets of waves layer by layer (the first layer in set A compare the first layer in set B) and pixel by pixel, I need to "fit" the oval to a circle shape.



Perhaps you mean that when you display your square image in a graph it is being shown as a non-square rectangle, thereby distorting the display of the circle?

If that is the case, then if you use NewImage to display the image, it will by default make the graph window be square. But to keep it square when you resize the window, you need to set one of the special axis modes in the Modify Graph dialog. If you set the Height mode to Aspect and enter 1 in the box the graph should remain square when resized. Plan mode will also do what you want, but it's a bit more complicated.

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
johnweeks wrote:
Perhaps you mean that when you display your square image in a graph it is being shown as a non-square rectangle, thereby distorting the display of the circle?

If that is the case, then if you use NewImage to display the image, it will by default make the graph window be square. But to keep it square when you resize the window, you need to set one of the special axis modes in the Modify Graph dialog. If you set the Height mode to Aspect and enter 1 in the box the graph should remain square when resized. Plan mode will also do what you want, but it's a bit more complicated.

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com


Hey John,

No, the image in both sets, simulation and experiment, are square. Each image in both sets looks like a image of moon or sun. What I want to do is compare the detail patterns of the moon (like the craters) in simulation image with it in experiment image using chi-square calculation.

In simulation, we set it to a circle, but in the experiment, the actual "moon or sun" is not a exact circle (it's a oval now). If the "moon" in the experiment image is a oval, the edge area will have large difference compared to simulation which would dominate the chi-square calculation. Only when we make the moon in experiment image the same shape and size as it is in the simulation image, the small detail patterns on the moon dominate chi-square calculation.

So what I want to do is just use some mathematical method make the oval moon in experiment to a circle.

Thanks
johnweeks wrote:
Perhaps you mean that when you display your square image in a graph it is being shown as a non-square rectangle, thereby distorting the display of the circle?

If that is the case, then if you use NewImage to display the image, it will by default make the graph window be square. But to keep it square when you resize the window, you need to set one of the special axis modes in the Modify Graph dialog. If you set the Height mode to Aspect and enter 1 in the box the graph should remain square when resized. Plan mode will also do what you want, but it's a bit more complicated.

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com


Also because there is a stack of experiment images, once I find how to "fit" the first image's moon to a circle, I want to perform the same operation (the same parameters settings, so in other experiment images, each corresponding pixel has the same movement vector as the first experiment image) to the rest of images in experiment set.
Dahair,
I don't fully understand your experiment but I am attaching a simple pxp illustrating a "best" fit of a circle to a 2D ellipse. It is shown for an upright 2D test ellipse wave, but ought to work for an arbitrary orientation.
I am still guessing but if your data set "is stretched" along the x or y axis you just might change the wave scaling to achieve the desired effect (but this is a a hack !!).
For different orientations you might have to perform a transformation according to the principal axis theorem. (I only did this on paper so far, so my knowledge in Igor of this issue is limited.)

A small sample experiment illustrating your problem would be really helpful.
HJ
s.r.chinn wrote:
Dahair,
I don't fully understand your experiment but I am attaching a simple pxp illustrating a "best" fit of a circle to a 2D ellipse. It is shown for an upright 2D test ellipse wave, but ought to work for an arbitrary orientation.


Hi Chinn,

Thank you for your example. I attached an example to help you understand my problem. In the example, there are 4 2D waves. e0 and e1 are from experiment, s0 and s1 are from simulation. These images are from diffraction in transmission electron microscopy. e0 and s0 are the condition with out sample so there is no patterns in the middle bright area and the edge is not blurred. e1 and s1 has sample so the edge is not clear to decide.

What I want to do is compare the patterns in the bright area in e1 and s1 by calculating chi-square.

In all 4 images, center bright area should be a circle, but in experiment (e0 and e1) it is not a circle because of aperture's shape. This prevent me from chi-square comparison. So I want to applied a kind of transform to make the bright area in e0 to a circle shape. Also I want to applied the same transform on e1 (I mean use the transform parameter got from e0's transform) so that it can imitate the circle aperture condition. In this way, I can compare patterns in the middle bright area in e1 and s1 pixel by pixel and calculate the chi-square between e1 and s1.

Thanks.
example.pxp
HJDrescher wrote:
I am still guessing but if your data set "is stretched" along the x or y axis you just might change the wave scaling to achieve the desired effect (but this is a a hack !!).
For different orientations you might have to perform a transformation according to the principal axis theorem. (I only did this on paper so far, so my knowledge in Igor of this issue is limited.)

A small sample experiment illustrating your problem would be really helpful.
HJ


Hi HJ,

I have post an example and explanation above. Please have a look and thanks for your help!
johnweeks wrote:
Perhaps you mean that when you display your square image in a graph it is being shown as a non-square rectangle, thereby distorting the display of the circle?

If that is the case, then if you use NewImage to display the image, it will by default make the graph window be square. But to keep it square when you resize the window, you need to set one of the special axis modes in the Modify Graph dialog. If you set the Height mode to Aspect and enter 1 in the box the graph should remain square when resized. Plan mode will also do what you want, but it's a bit more complicated.

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com


Hi John,

I have post an example and some explanation above. Please have a look and thanks for your help!
You might want to approach this using image processing. Specifically, use ImageThreshold to convert your s1 image to binary and then use ImageAnalyzeParticles. The latter computes the various moments of the particle (stored in M_rawMoments) from which you can get the fitting ellipse.

A.G.
WaveMetrics, Inc.
The experiment file illustrated a lot. Thank you.
As Igor mentioned ImageAnalyzeParticles is the way to go. Internally it probably does the transformation with the principal axis theorem (since the result is called M_rawMoments).
HJ