Plot a 2D image in projected coordinate systems.

I am not sure if the title describes my problem well enough - trying to get used to the notation and things like that in linear algebra and geography.
To start with then I have this image and it is represented in a 2D matrix, call it A. I want to project it onto a plane normal to n=[1,2,3]. I believe I have understood how to find the perpendular vectors from A to the normal plane.
(hope I am using the right words but meaning the vector going from the origin, parallell to the normal vector creates a 90 degree corner with the vector going from the normal plain to another vector in the original image 2D - creating right triangle)
Anyhow I will describe it a bit, so if you have the mathimatical understanding to tell me wrong it would be nice, because then I do not need the Matlab help yet. My matrix A started with [1; -90] so I used that as the origin (x0,y0,z0) (z would be 0 right in 2D?) then I took just the next vector from the A [1; -91] as (x1,y1,z1) n = (a,b,c) then I need to find t so that (x0,y0,z0) (x1,x2,x3) and (x0+ta,y0+tb,z0+tc) make right triangle and then the point (x0+ta,y0+tb,z0+tc) is the projection of [1;-91].
t = ((a*x1-ax0)+(b*x1-b*x0) + (c*x1-c*x0))/(a² + b² + c²)
t = 0.142857 and the I could find the projected image by A (original image) + t*n(the normal vector).
Ok, hope someone understood my... my Matlab question is how can I plot visually this new 3*10095 matrix so I have the three axis in the plot (seeing the image laying down on the z axis after the transformation)?

Antworten (1)

Matt J
Matt J am 25 Sep. 2020
Bearbeitet: Matt J am 25 Sep. 2020

0 Stimmen

I do not understand how a 3*10095 matrix is being interpreted as an image. You don't to have any pixel values, as far as I can see. If you just want to plot a cloud of 3D points, you would use scatter3().

4 Kommentare

I am very new to this matlab, and linear algebra actually also, but I got this image.mat file, where "an image consisting of 200 by 200 pixels.The image represented by 2 by 10095 matrix, where the first row represent the x coordinates, the second the y-coordinates of all the pixels which are black in the image"
Then I accessed the matrix:
```
data = load('image.mat')
R = data.B % B is the matrix representation of the image
%I add the z row to it to make the matrix 3*10095 in the form (x,y,z)
col_size = size(R, 2);
ones_row = zeros(1, col_size);
S = [R; ones_row]; %now S is the matrix I want to project onto N = [1,2,3] plane
```
After this I used pen and paper to calculate the linear algebra projection to get the vector u = t*N[1,2,3] then I added this vector to S
```
finalMatrix = S + u;
```
Now I hoped I had found all the (x,y,z) coordinates to for the image on the new plane and I want to "draw/plot it".
I did this with 2D transformations on the image and that worked fine:
```
%Counter-clockwise 120 degree
X = [cos(2*pi/3) -sin(2*pi/3);sin(2*pi/3) cos(2*pi/3)];
T = X * R; % where R = data.B;
plot(T(1, :), T(2, :), 'k.','MarkerSize', 1);
```
Matt J
Matt J am 25 Sep. 2020
OK, but what more input do you need from us? As I have told you, you should use scatter3().
Yes, thanks a lot. It worked for me, I had bit of a problem to figure out how to extract the rows - but got it now:
scatter3(A(1,:,:),A(2,:,:),A(3,:,:),1,[0 0 0])¸
Is it possible to combine the previous matrix and the projected one in same plot ?
Like previous is:
scatter3(R(1,:,:),R(2,:,:),R(3,:,:),1,[0 0 0])
Latter:
scatter3(A(1,:,:),A(2,:,:),A(3,:,:),1,[0 0 0])
And when I run the script I could see them intersecting
Matt J
Matt J am 25 Sep. 2020
Bearbeitet: Matt J am 25 Sep. 2020
Yes, you can use hold():
hold on
scatter3(R(1,:,:),R(2,:,:),R(3,:,:),1,[0 0 0])
scatter3(A(1,:,:),A(2,:,:),A(3,:,:),1,[0 0 0])
hold off

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by