image collineation using inverse (backward) transformation

Petr Sladek (sladep1) & Milan Kratochvil (kratom4) at CTU Prague

Contents

interpolation uses inverse transformation

output image defines discrete [x,y]; [m n]=T^-1(x,y) returns brightness at [x,y] pixel

fcn body

%function [imout, To] = imcollini(A,imin);
  % allocate mem
  paddm = 100;
  paddn = 100;
  ipaddm = 300;
  ipaddn = 300;
  [sizem sizen] = size(imin);
  imout = ones(sizem+2*paddm,sizen+2*paddn)*120; % white space plus  padding
  imip = ones(sizem+2*ipaddm,sizen+2*ipaddn)*255; % white space plus  padding
  %copy padded input image:
  imip(ipaddm:(ipaddm+sizem-1),ipaddn:(ipaddn+sizen-1))=imin(1:sizem,1:sizen);

  [sizem sizen] = size(imout);
  % meshgrid
  [index(:,:,1) index(:,:,2)] = meshgrid(1:1:sizen, 1:1:sizem);

inverse (backward) transformation

% see also inverse A proinv() function

  iT=collin(proinv(A),index);
  % passpoints are derived from direct

forward transformation

  To=collin(A,index);
  To(:,:,1) = To(:,:,1)+paddm;
  To(:,:,2) = To(:,:,2)+paddn;
  %min, max points.
  a = min(min(iT(:,:,1))); b =max(max(iT(:,:,1)));
  fprintf('1: min= %d max= %d \n',a,b);
  a = min(min(iT(:,:,2))); b =max(max(iT(:,:,2)));
  fprintf('2: min= %d max= %d \n',a,b);
  % padding
  iT(:,:,1) = iT(:,:,1)+ipaddm-paddm;
  iT(:,:,2) = iT(:,:,2)+ipaddn-paddn;
  [im in]=size(imip);

  %create column index matrix:
  Tindex = round(reshape(iT(:,:,1),1,sizem*sizen)).*im +round(reshape(iT(:,:,2),1,sizem*sizen));
  Iindex = 1:1:(sizem*sizen);
  if length(Tindex)==length(Iindex)
    fprintf('len of Tindex= %d, len of Index=%d\n',length(Tindex),length(Iindex));
    fprintf('size %d,%d',sizem,sizen);
    %collineate image:
    imout(Iindex(:))=imip(Tindex(:));
  else
    fprintf('something is wrong');
  end
1: min= 1.148649e+000 max= 3.445946e+002 
2: min= 7.432432e-001 max= 2.229730e+002 
len of Tindex= 90000, len of Index=90000
size 300,300