3D reconstruction from a 2D image

15 visualizzazioni (ultimi 30 giorni)
Damon Pierre-Marie
Damon Pierre-Marie il 9 Nov 2017
Commentato: Ayush singhal il 22 Mag 2021
Hello,
I have some difficulties to reconstruct a 3D scene from a 2D image. I would like to create a top view of scene removing the perspective, in other words, realize an inverse perspective mapping. Let's assume we know the camera position, orientation and its parameters. Moreover we consider all the captured points lie on the same plane XY. Then, it is easy to prove that a pixel at a (u,v) location in the image will move to the coordinate (X,Y,0) in the 3D space with:
X=-((u*P(3,4)-P(1,4))*(v*P(3,1)-P(2,1)) + (v*P(3,4)-P(2,4))*(P(1,1)-u*P(3,1)))/((u*P(3,2)-P(1,2))*(v*P(3,1)-P(2,1)) + (v*P(3,2)-P(2,2))*(P(1,1)-u*P(3,1)));
Y=(X*(u*P(3,2)-P(1,2)) + (u*P(3,4)-P(1,4)))/(P(1,1)-u*P(3,1));
P is the projection matrix such that: P=[KR KT] with K,R and T respectively the intrinsic, rotation and translation matrices.
Once all the 3D locations of each pixel are computed, I would like to display the XY plane with the color information of the original pixel as if it was a 2D image.
However, a pixel (u,v) can mapped in 3D space to a non integer location meaning that I get a non-regular scatter plot were each (X,Y) point contain a color information. I tried to divide the XY plane into small windows and then compute the average color of all points into each squares but it is very slow.
Please find my code enclosed. Some help would be appreciated!
Thank you in advance, Pm
  8 Commenti
mostafa TAIBI
mostafa TAIBI il 13 Feb 2020
another question if you allow, for the 3d reconstruction is that you take all the pixels of the image after you use the formula to calculate X and Y?
Matt J
Matt J il 13 Feb 2020
Modificato: Matt J il 13 Feb 2020
If you use imwarp as my answer below recommends,
Image2 = imwarp(Image1,projective2d(P(:,[1,2,4]).'))
then no transformation of coordinates need be done by you explicitly. That is all handled for you inside imwarp.

Accedi per commentare.

Risposta accettata

Matt J
Matt J il 9 Nov 2017
Modificato: Matt J il 9 Nov 2017
Once all the 3D locations of each pixel are computed, I would like to display the XY plane with the color information of the original pixel as if it was a 2D image.
I don't think you need to be doing the work of mapping and interpolating the coordinates. I think it should be as simple as
Image2 = imwarp(Image1,projective2d(P(:,[1,2,4]).'))
  13 Commenti
Matt J
Matt J il 22 Mag 2021
Modificato: Matt J il 22 Mag 2021
If it's a similar question, you should apply the posted solution. If you can't apply the posted solution, it probably means the question isn't similar enough, and you should probably post it in its own thread.

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by