Hey so I've written a snippet of code in order to perform an affine transformation and I am not getting the results I want. Can someone see what I am doig wrong.

1 view (last 30 days)
Marshall
Marshall on 1 Feb 2016
Answered: Walter Roberson on 6 Feb 2016
Here I have an assignement to transform an image based on a user input. Below is what I have.
imshow(k)
p1 = impoint
Newp1 = impoint
p2 = impoint
Newp2 = impoint
p3 = impoint
Newp3 = impoint
p4 = impoint
Newp4 = impoint
p5 = impoint
Newp5 = impoint
POINT1= getPosition(p1)
POINT2= getPosition(p2)
POINT3= getPosition(p3)
POINT4= getPosition(p4)
POINT5= getPosition(p5)
NPOINT1= getPosition(Newp1)
NPOINT2= getPosition(Newp2)
NPOINT3= getPosition(Newp3)
NPOINT4= getPosition(Newp4)
NPOINT5= getPosition(Newp5)
X = [ POINT1 1 0 0 0; 0 0 0 POINT1 1; POINT2 1 0 0 0; 0 0 0 POINT2 1; POINT3 1 0 0 0; 0 0 0 POINT3 1; ...
POINT4 1 0 0 0; 0 0 0 POINT4 1; POINT5 1 0 0 0; 0 0 0 POINT5 1 ]
NPOINT1'
xprime = [NPOINT1';NPOINT2';NPOINT3'; NPOINT4';NPOINT5']
a = X \ xprime
A = [a(1:3)'; a(4:6)'; 0 0 1]
A = A;
A(7) = 0
A(8) = 0
above is a technique to find an affine transformation between two images. In this case though I am trying to use points on the same image in order to pull off this. I will demonstrate with an image below
: Do you know if this can actually work. I am using this program to use the affine transformation. Any feedback helps:
orange = [0 0 0]';
a = .15;
T = maketform('affine', A );
A2 = imread('latticenew.jpg');
h1 = figure; imshow(A2); title('Original Image')
R = makeresampler({'cubic','nearest'},'fill');
B = imtransform(A2,T,R,'FillValues',orange);
h2 = figure; imshow(B);
title('Sheared Image');
The transformation is drastically different from what I want. And as you can see I have to set A(7) and A(8) to zero in order to use the maketform function although it outputs the parameter not close to zero.

Answers (1)

Walter Roberson
Walter Roberson on 6 Feb 2016
I do not know anything about affine transforms. I only cleaned up the presentation of your question so that other people could read it more easily.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!