3D reconstruction from a 2D image
Show older comments
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 Comments
mostafa TAIBI
on 3 Feb 2020
Hello everyone, I'd like to know how you got this formula...
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));
Pplease I want the expression of X,Y,Z Euclidean coordinates for a rotating camera as a function of u,v (pixel) and the projection matrix P
Matt J
on 4 Feb 2020
I don't know if that formula is to be trusted, but I offered a simpler expression of the relationships in this comment,
Damon Pierre-Marie
on 4 Feb 2020
Damon Pierre-Marie
on 4 Feb 2020
mostafa TAIBI
on 4 Feb 2020
For z different from zero the problem will be more difficult I can't ignore z because I'm looking for a 3d reconstruction.
If the scene you are trying to reconstruct is not confined to a 3D plane, then this post is not relevant to you. It was all predicated on the assumption that the scene was planar.
If the scene you are interested is confined to a plane, then rotate your 3D coordinate system so that the plane becomes the xy-plane and the discussion below applies.
mostafa TAIBI
on 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?
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.
Accepted Answer
More Answers (0)
Categories
Find more on Computer Vision with Simulink in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


