1

I have a picture

enter image description here

and I want to get projective transformation by shifting it back like this:

enter image description here

but the only result I can see is this:

enter image description here

and I cannot find my mistake. My code (A - picture I want to transform):

p=0.25;
a=p*rows(A);

U = @(m, n) ([1 1; 1 m; n 1; n m]);
V = @(m, n) ([1+a 1+a; 1-a m-a; n-a 1+a; n+a m-a]);


D=transform(A, U(rows(A), cols(A)),...
               V(rows(A), cols(A)),...
               'projective');
imshow(D)

function B=transform(A,U,V,type)
[m n] = size(A)
tform = maketform(type,U,V);  
B = imtransform(A,tform,'size',[m n]);
myname
  • 137
  • 1
  • 7

1 Answers1

0

It seems like you have the "directions" of your axes mixed up. Try this mapping:

V = @(m, n) ([1+a 1-a; 1+a m+a; n-a 1+a; n-a m-a]);

For the black background you can fix it by setting some parameter/value pair on imtransform

(Unfortunately I'm not at a computer with matlab, so I can't guarantee the correctness of the mapping. I'll check it tomorrow and update it if it is wrong)

KlausCPH
  • 1,816
  • 11
  • 14