image collineation with interp2 bicubic interpolation

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

Contents

Interface:

% input: A = [A1;A2;A3] ... matrix of collineation
%        imin ... input image
%        padd ... image padding (useful when picture after collin crossing
%                 border
% output:imout ... output padded image
%        To ... forward transformation mesh
%               (m,n,1) contains rows of transf. (m,n,2) contains cols.

%note: 'publish()' can't publish functions:

%function [imout, To] = imcollinf(A,imin,padd);

prepare picture for collineation, generate mesh:

  % sometimes padding of the picture is useful, due to the interp2 padding
  % must be equal for input and ouput picture.
  paddm = padd;
  paddn = padd;
  ipaddm = padd;
  ipaddn = padd;
  [sizem sizen] = size(imin);
  % allocate mem
  imout = ones(sizem+2*paddm,sizen+2*paddn)*255; % 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);
  % sizes of padded images
  [sizem sizen] = size(imout);
  % meshgrid: see also meshgrid function
  % index(:,:,1) = [ 1 2 3 4 ....n sizen
  %                  1 2 3 4 ....n
  %                  ...
  %                  1 2 3 4 ....n //rows: sizem.
  %
  % index(:,:,2) = [ 1 1 1 1 ....1 //cols: sizen
  %                  2 2 2 2 ....2
  %                  ...
  %                  m m m m ....m m=sizem.
  %
  [index(:,:,1) index(:,:,2)] = meshgrid(1:1:sizen, 1:1:sizem);

collineation point-to-point (interp2 does not require inverse collin):

see collin.m doc, external function.

  % returns point-to-point transformation:
  T=collin(A,index);

print stats:

  % min, max points.
  a = min(min(T(:,:,1))); b =max(max(T(:,:,1)));
  fprintf('1: min= %d max= %d \n',a,b);
  a = min(min(T(:,:,2))); b =max(max(T(:,:,2)));
  fprintf('2: min= %d max= %d \n',a,b);
  To=T;
  %padd transf. matrix if neccessary but ipaddm == paddm >> removed, see collin, collini
  %iT(:,:,1) = iT(:,:,1)+ipaddm-paddm;
  %iT(:,:,2) = iT(:,:,2)+ipaddn-paddn;
  fprintf('size %d,%d',sizem,sizen);
1: min= 1.842812e+002 max= 1.064017e+003 
2: min= -1.244042e+002 max= 7.261543e+002 
size 740,900

collineate image using bicubic interpolation

  imout=interp2(index(:,:,1),index(:,:,2),imip,T(:,:,1),T(:,:,2),'cubic');