I am working on a virtual camera model that takes an image of a scene. I have the x and y of the image of each point on the image plain. My problem is that the image should be 640×640 and the scene consists of 12 milion points so there are multiple points in one pixel of image. In the project it is ok to over write the color of the points projected on one pixel so I wrote the following code: (Prime_CO is a 12000000×2 matrix and each row of it has the x a y of each point of the image.RGB_final is a 12000000×3 matrix which has the RGB colors of each point of Prime_CO, the final image should be a 640x640x3 array which has the RGB of each pixel.)
IM1=zeros(640,640,3);pixel_size=0.01984375;start_point=-6.35; for j=1:640 for i=1:640 for num=1:12000000 if Prime_CO(num,1)>=start_point+((j-1)*pixel_size) && Prime_CO(num,1)<=start_point+(j*pixel_size) && Prime_CO(num,2)>=start_point+((i-1)*pixel_size) && Prime_CO(num,2)<=start_point+(i*pixel_size) IM1(i,j,1)=RGB_final(num,1); IM1(i,j,2)=RGB_final(num,2); IM1(i,j,3)=RGB_final(num,3); end end endend
The problem is that it takes MATLAB a long time to run this code. How should I do this appropriately?
Best Answer