RGB 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 color image
%        padd ... image padding (useful when picture after collin crossing
%                 border
% output:imout ... output color 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] = imcollinfrgb(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 x] = size(imin);
  % allocate mem
  imout = ones(sizem+2*paddm,sizen+2*paddn,3)*255; % white space plus  padding
  imip = ones(sizem+2*ipaddm,sizen+2*ipaddn,3)*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 x] = 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= -8.900000e+001 max= 4.673733e+002 
2: min= -8.830275e+001 max= 6.541278e+002 
size 644,484

collineate image using bicubic interpolation r,g,b:

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