I have 3D point cloud (laser scanning) and an orthophoto, geo-referenced by a TIFF World File (.tfw). I want to project every 3D point of the point cloud into the 2D image.
Here is an example of a .TFW file:
2.4384
0.0000
0.0000
-2.4384
441794.4342
5094101.4520
These are the 6 coefficients of a three-by-three transformation matrix. They indicate that a pixel is 2.4384 meters square, and that the center of the upper left pixel has an easting (x coordinate) of 441794.4342 and a northing of 5094101.4520. See here.
So I can get the X,Y of the point cloud (supposing that the Z is 0):
x_cloud = 2.4384 * column + 0.0 * row + 441794.4342
y_cloud = (-2.4384) * row + 0.0 * column + 5094101.4520
How do I find (X_pixel, Y_pixel) from a 3D point using the TFW file?
Solution
I found a solution for my problem, it was simple. let's see our TIFF World File
2.4384 -> A
0.0000 -> B
0.0000 -> C
-2.4384 -> D
441794.4342 -> E
5094101.4520 ->F
here is my pseudo code:
forEach point cloud {
x_cloud = currentX_cloud;
y_cloud = currentY_cloud;
z_cloud = currentZ_cloud;
x_pixel = (x_cloud - E) / A;
y_pixel = img.rows - (y_cloud - F + A * img.rows) / A;
//accessing to pixel values
R = img.at<cv::Vec3b>(y_pixel, x_pixel)[0];
G = img.at<cv::Vec3b>(y_pixel, x_pixel)[1];
B = img.at<cv::Vec3b>(y_pixel, x_pixel)[2];
}
(I'm using OpenCV to manipulate the orthophoto and LidarFormat to deal with the point cloud data (LAS file))