0

I have a stack of images (about 180 of them) and there are 2 stars (just basic annotations) on every single image. Hence, the position (x,y) of the two stars are provided initially. The dimensions of all these images are fixed and constant.

The 'distance' between the image is about 1o with the origin to be the center (width/2, height/2) of every single 2D image. Note that, if this is plotted out and interpolated nicely, the stars would actually form a ring of an irregular shape.

Enter image description here

The dotted red circle and dotted purple circle are there to give a stronger scent of a 3D space and the arrangement of the 2D images (like a fan). It also indicates that each slice is about 1o apart.

  1. With the provided (x,y) that appeared in the 2D image, how do you get the corresponding (x,y,z) in the 3d space knowing that each image is about 1o apart?

  2. I know that MATLAB had 3D plotting capabilities, how should I go about implementing the solution to the above scenario? (Unfortunately, I have very little experience plotting 3D with MATLAB)

SOLUTION

Based on the accepted answer, I looked up a bit further: spherical coordinate system. Based on the computation of phi, rho and theta, I could reconstruct the ring without problems. Hopefully this helps anyone with similar problems.

I have also documented the solution here. I hope it helps someone out there, too: http://gray-suit.blogspot.com/2011/07/spherical-coordinate-system.html

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Gary Tsui
  • 1,755
  • 14
  • 18
  • 1
    The question isn't clear. Is it a video of two stars in the sky? – whoplisp Jul 06 '11 at 08:26
  • no, the stars are just basic annotations. – Gary Tsui Jul 06 '11 at 08:29
  • 1
    I still don't understand. Maybe explain what you are trying to achieve. – whoplisp Jul 06 '11 at 08:35
  • May i know which part you don't understand, i'll try my best to explain it to you. Basically, i want to plot the annotations in the 2d image in 3D. – Gary Tsui Jul 06 '11 at 08:38
  • This might be better suited to the Maths area of stack exchange (although not sure). How i'm visualising the problem is, you have a 3D object (looks like an irregular ring). You have many images with points defining where on the image this ring would be if the image was a cross section of the ring. Viewed top down the images slice the object like you might slice a pizza if you needed to share it between about 360 people. – George Duckett Jul 06 '11 at 08:51
  • @George Duckett, correct, cross section wise, it would be like a ring in 2D. – Gary Tsui Jul 06 '11 at 08:54

4 Answers4

1

Given the 2D coordinates (x,y) just add the angle A as a third coordinate: (x,y,A). Then you have 3D.

If you want to have the Anotations move on a circle of radius r in 3D you can just calculate: you can use (r*cos(phi),r*sin(phi),0) which draws a circle in the XY-plane and rotate it with a 3x3 rotation matrix into the orientation you need.

whoplisp
  • 2,508
  • 16
  • 19
  • would that A be cosine? sine? and how do i derive that A from all the given information i gave in the original post? – Gary Tsui Jul 06 '11 at 08:43
  • You should thoroughly revise your question. – whoplisp Jul 06 '11 at 08:47
  • May i know which part you don't understand, please let me know which part you want me to revise, and i'll try my best to make it better. thanks. – Gary Tsui Jul 06 '11 at 08:50
  • hi whoplisp, thanks for your effort, but in my question, i already stated that i have a stack of images, aligned and ordered as illustrated, and for every image, there are two annotations. Each image is about 1 degree apart. Now i only want to map them to a 3D space. – Gary Tsui Jul 06 '11 at 08:52
  • 1
    When you say stack I would think that you moved z (because I have a micrcoscopy background). Then you say you rotated the image. You can just say the angle you rotated is equivalent to movement in z for your plotting purposes and plot the two annotation points in a 3D plot with the angle being the z-coordinate. Please understand that this is hard to see from your question. I looked back in your history and it looks like you are now trying to plot your bridge points. – whoplisp Jul 06 '11 at 09:04
1

I believe the y coordinate stays as is for 3D, so we can treat this as converting 2D x and image angle to an x and z when viewed top down.

The 2D x coordinate is the distance from the origin in 3D space (viewed top down). The image angle is the angle the point makes with respect to the x axis in 3D space (viewed top down). So the x coordinate (distance from orign) and the image angle (angle viewed top down) makes up the x and z coordinates in 3D space (or x and y if viewed top down).

That is a polar coordinate. Read how to convert from polar to cartesian coordinates to get your 3D x and z coordinates.

I'm not great at maths either, here's my go:

3D coords = (2Dx * cos(imageangle), 2Dy, 2Dx * sin(imageangle))

George Duckett
  • 31,770
  • 9
  • 95
  • 162
  • thanks for the response, you are correct about the polar coordinates. to locate a point on a sphere, it is x=r sin(theta)cos(phi), y = r sin(theta)sin(phi) and z = r cos(theta). However, i am having a hard time connecting them together as you can tell by now, i am super weak in math. – Gary Tsui Jul 06 '11 at 08:58
1

It is not clear from you question around which axis your rotation is taking place. However, my answer holds for a general rotation axis.

First, put your points in a 3D space, lying on the X-Y plane. This means the points have a 0 z-coordinate. Then, apply a 3D rotation of the desired angle around the desired axis - in your example, it is a one degree rotation. You could calculate the transformation matrix yourself (should not be too hard, google "3D rotation matrix" or similar keywords). However, MATLAB makes it easier, using the viewmtx function, which gives you a 4x4 rotational matrix. The extra (fourth) dimension is dependent on the projection you specify (it acts like a scaling coefficient), but in order to make things simple, I will let MATLAB use its default projection - you can read about it in MATLAB documentation.

So, to make the plot clearer, I assume four points which are the vertices of a square lying on the x-y plane (A(1,1), B(1,-1), C(-1,-1), D(1,-1)).

az = 0;     % Angle (degrees) of rotation around the z axis, measured from -y axis.
el = 90;    % Angle (degrees) of rotation around the y' axis (the ' indicates axes after the first rotation).
x = [1,-1, -1, 1,1]; y = [1, 1, -1, -1,1]; z = [0,0, 0, 0,0];     % A square lying on the X-Y plane.
[m,n] = size(x);
x4d = [x(:),y(:),z(:),ones(m*n,1)]';    % The 4D version of the points.
figure
for el = 90 : -1 :0 % Start from 90 for viewing directly above the X-Y plane.
    T = viewmtx(az, el);
    x2d = T * x4d;                            % Rotated version of points.
    plot3 (x2d(1,:), x2d(2,:),x2d(3,:),'-*'); % Plot the rotated points in 3D space.
    grid
    xlim ([-2,2]);
    ylim ([-2,2]);
    zlim([-2,2]);
    pause(0.1)
end
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Itamar Katz
  • 9,544
  • 5
  • 42
  • 74
0

If you can describe your observation of a real physical system (like a binary star system) with a model, you can use particle filters.

Those filters were developed to locate a ship on the sea, when only one observation direction was available. One tracks the ship and estimates where it is and how fast it moves, the longer one follows, the better the estimates become.

whoplisp
  • 2,508
  • 16
  • 19