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.

get_function_on_grid_prior(input_image, handle, dc, shift_flag, prior)
function [temp_Grid] = get_function_on_grid_prior(input_image, handle, dc, shift_flag, prior)
% This function can be used to calculate a function on a grid. The parameters are passed to function using the prior variable.
%
% 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:
% [temp_Grid]= get_function_on_grid_prior(input_image, handle, dc, shift_flag, handle);
% where
%   input_image: The input image
%   handle: The handle of the target function. For example, @mean
%   dc: dc is the grid step size, s_G
%   shift_flag: if 1, the function shuffles the padded area around the image.
%   handle: The parameters of the function handle.
%   temp_Grid: the output, containing the calculated fucntion values on the grid nodes.
%
% Below, an example of calculating the mean function using the grid-based
% modeling on an sample image is provided. First, the 'temp_sample_function_with_prior' function is
% calculated on the grid, using get_function_on_grid_prior 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):
%   function parameters are sent wia prior variable
%       prior.power = 2;
%       u_avg_G = get_function_on_grid_prior(u, @temp_sample_function_with_prior, s_G, 1, prior);
%       u_avg = interpolation_a_grid_on_domain(u_avg_G, xm, ym, s_G);
%
% In cases where the function doesn't need any prior parameter, please use
% simpler function get_function_on_grid. 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
%



%
[m n]=size(input_image);


r1=rem(m-1,dc);
pad1=2*dc-r1;

r2=rem(n-1,dc);
pad2=2*dc-r2;

input2=padarray(input_image,[dc dc],'pre','symmetric');
input3=padarray(input2,[pad1 pad2], 'post','symmetric');

% 090216: if shift_flag is true, shift the extended region clockwise
% (useful for functions, such as mean or std)
if (shift_flag)
    [input3_xm input3_ym] = size(input3);
    input3(1:dc, 1:input3_ym) = circshift(input3(1:dc, 1:input3_ym), [0 dc]);
    input3(1:input3_xm, input3_ym - dc + 1:input3_ym) = circshift(input3(1:input3_xm, input3_ym - dc + 1:input3_ym), [dc 0]);
    input3(input3_xm - dc + 1:input3_xm, 1:input3_ym) = circshift(input3(input3_xm - dc + 1:input3_xm, 1:input3_ym), [0 dc]);
    input3(1:input3_xm, 1:dc) = circshift(input3(1:input3_xm, 1:dc), [dc 0]);
    [input3_xm_new input3_ym_new] = size(input3);    
    if (input3_xm_new ~= input3_xm)||(input3_ym_new ~= input3_ym)
        fprintf('errrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr>>>>>>');
end

%
[t z]=size(input3); %the size of the new flow field

m1=dc-r1;
n1=dc-r2;

side1grd=floor((m+m1)/dc)+1;
side2grd=floor((n+n1)/dc)+1;
temp_Grid=zeros(side1grd,side2grd);

[k l]=size(temp_Grid);

for i=1:k
    for j=1:l
        
       fi=i*dc+1;
       fj=j*dc+1;
       
       % a0, b0, a1, b1 are in the f1
       a0=fi-dc;
       b0=fj-dc;
       a1=fi+dc;
       b1=fj+dc;

       w1=input3(a0:a1,b0:b1);
       
       maxF=handle(reshape(w1,numel(w1),1), prior);           % for exampl the function handler is max now
      % maxF=max(max(w1));
       temp_Grid(i,j)=maxF;
       
    end
     % grid=temp_Grid;
     % output=Grid;
    
end        
    

end

Contact us