I have a mini project to do about homography, but I am really a beginner in Matlab. I have calculated the homography matrix easily by taking a set pixels from both images but the problem is how to apply this matrix to all pixels of the original image (I think it's difficult to treat each pixel individually).
Here is the original image :
I want to apply the homography to this image (I have already extracted the homography matrix) to get a frontal view of the cover.
So with my weak knowledge of Matlab, I applied the following operations:
- I get 4 points from the corners of the original image and the corresponding points in the output image
I have estimated the homography :
0.9638 -0.0960 52.5754 0.2449 1.3808 -17.0081 -0.0001 0.0013 1.0000
then I have applied it on the image using this poor Matlab code:
function [Ired] = affect(I,P) I1=im2double(I); for i=1:308 i for j=1:288 v1 = [j;i;1]; v2 = P*v1; v3 =v2/v2(3,1); if (v3(1,1) <0 || v3(2,1)<0 || v3(3,1)<0) continue; else Ired(round(1+v3(2,1)),round(1+v3(1,1)))=I1(i,j); end end
and the result is the following:
but the problem with this code is it takes a lot of time (sometimes 10 minutes) to perform the operation on the image, especially if the size of the image is high. Is there a way to implement this code without loops to make it faster?
I get these black dots all over the image, I can do a dilation but the image will be distorted, do you have an idea how to eliminate this dots without distorting the image?
I cannot use predefined Matlab functions in this project.