image thumbnail

Implementation of Image warping

by

 

This is a matlab implementation of image warping algorithm.

warping.m
clear; 
close all;
img = imread('fig1.jpg');
m =[1, -0.1, 0
    0, 1, 0.2
    0, 0, 1];
sz = size(img);
[X,Y]= meshgrid([1:sz(2)], [1:sz(1)]);
A = [reshape(Y,1,[]);
     reshape(X,1,[]);
     ones(1,length(Y(:)));];
AA = m*A;
AA = AA./[AA(3,:);AA(3,:);AA(3,:)];
AA = int32(AA);
a1 = AA(1,:) - min(AA(1,:)) +1;
a2 = AA(2,:) - min(AA(2,:)) +1;


szNew = sz;
szNew(1) = max(a1);
szNew(2) = max(a2);

ind = a1 + (a2-1)*szNew(1);
indOld = A(1,:) + (A(2,:)-1)*sz(1);

imgNew = uint8(zeros(szNew(1),szNew(2),3))*255;

imgNew(ind) = img(indOld);
imgNew(ind + szNew(1)*szNew(2)) = img(indOld + sz(1)*sz(2));
imgNew(ind + szNew(1)*szNew(2)*2) = img(indOld + sz(1)*sz(2)*2);

figure('position',[200,500,500,300]);
imshow(img);
figure('position',[800,500,500,300]);
imshow(imgNew);

Contact us