Code covered by the BSD License  

Highlights from
Grid-based modeling of images

image thumbnail

Grid-based modeling of images

by

 

These functions enable calculating functions using the grid-based modeling.

interpolation_a_grid_on_domain(input_grid, L, W, dc)
function [Hf] = interpolation_a_grid_on_domain(input_grid, L, W, dc)
% This function can be used to interpolate a calculated grid-function back on the image domain
%
% May 30th, 2010, By Reza Farrahi Moghaddam and Rachid Hedjam, Synchromedia Lab, ETS, Montreal, Canada
%
% For more details about the grid-based modeling, please refer to [1].
%
%
% USAGE:
% [Hf] = interpolation_a_grid_on_domain(input_grid, L, W, dc)
% where
%   input_grid: The input grid data. It is the calculated values of the
%   function on the grid. get_function_on_grid and
%   get_function_on_grid_prior can be used to obtain this matrix.
%   L: is the size of the first dimension of the image domain
%   W: is the size of the second dimension of the image domain
%   dc: dc is the grid step size, s_G
%   Hf: the output, containing the inpterpolated values of the fucntion on the image domain.
%
% Below, an example of calculating the mean function using the grid-based
% modeling on an sample image is provided. First, the 'mean' function is
% calculated on the grid, using get_function_on_grid function. Then, the
% result is interpolated on the image domain using the
% interpolation_a_grid_on_domain function (see mypublishtest.m for the complete script):
%   u_avg_G = Get_function_on_grid(u, @mean, s_G, 1);
%   u_avg = interpolation_a_grid_on_domain(u_avg_G, xm, ym, s_G);
%
% In cases where the function needs some prior parameters, please use
% Get_function_on_grid_prior function. An example is provided in
% mypublishtest.m
%
% [1] R. Farrahi Moghaddam and M. Cheriet, A multi-scale
% framework for adaptive binarization of degraded document images, Pattern
% Recognition, 43, pp. 2186--2198, 2010, DOI: 10.1016/j.patcog.2009.12.024
%



% interpole Fxy by [axy, bxy, cxy, dxy]
%   a(x,y)     b(x,y)
%     Fxy
%   c(x,y)     d(x,y)
% F(x,y)=ax+by+cxy+d

if (dc == 1)
    Hf = input_grid;
    return;
end

G=input_grid;

%create the Hf area 
Hf=zeros(L,W);

for x=1:L
    for y=1:W
        
       % find the relatif coordinate

      Dx=GetDifference(x,dc);
      Dy=GetDifference(y,dc);

      % 090402: bug resolved (dominator must be dc+1 no dc)
      ax=floor((x-1)/(dc))+1;
      ay=floor((y-1)/(dc))+1;
      
      bx=ax;
      by=ay+1;

      cx=ax+1;
      cy=ay;

      dx=ax+1;
      dy=ay+1;

      % ----> interpolt it now
      g1=G(ax, ay)+(G(cx,cy)-G(ax,ay))*Dx;
      g2=G(bx, by)+(G(dx,dy)-G(bx,by))*Dx;
      g3=g1+(g2-g1)*Dy;

      Hf(x,y)=g3; 
        
    end
end

end

function [dif]=GetDifference(x,dc)
a=floor((x-1)/(dc));
b=(a)*(dc)+1;
c=(x-b)/(dc);
dif=c;
end

Contact us