Home > Source > Registration > setup_grid.m

setup_grid

PURPOSE ^

SETUP_GRID: Create a grid for points (shapes) to be embedded

SYNOPSIS ^

function [grid, steps] = setup_grid(image_width, unwarped_image, unwarped_points, placement_method, n_points)

DESCRIPTION ^

 SETUP_GRID: Create a grid for points (shapes) to be embedded
             in.

 Code written by Katherine Smith, 2003

    GENERAL

      [grid, steps] = setup_grid(image_width, unwarped_image,
                  unwarped_points, placement_method, n_points)

    INPUT/S

      -image_width:
           The width of the input image.

      -unwarped_image:
           The input image.

      -unwarped_points:
           The control points of this image.

      -placement_method:
           One of: 'overlap grid', 'grid', 'random',
           'random_and_scale', 'edge', 'edge_and_scale'.

      -n_points:
           Number of points in grid?
           
    OUTPUT/S

      -grid:
           The grid in 1-D

      -steps:
           The steps on the grid in 1-D

    PENDING WORK

      -

    KNOWN BUG/S

      -

    COMMENT/S

      -steps must be specified for single-point warps but not for
      multi-point warps

    RELATED FUNCTION/S

      

    ABOUT

      -Created:     November 23rd, 2003
      -Last update: Novermber 25th, 2003
      -Revision:    0.0.2
      -Author:      R. S. Schestowitz, University of Manchester
 ==============================================================

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [grid, steps] = setup_grid(image_width, unwarped_image, unwarped_points, placement_method, n_points)
0002 % SETUP_GRID: Create a grid for points (shapes) to be embedded
0003 %             in.
0004 %
0005 % Code written by Katherine Smith, 2003
0006 %
0007 %    GENERAL
0008 %
0009 %      [grid, steps] = setup_grid(image_width, unwarped_image,
0010 %                  unwarped_points, placement_method, n_points)
0011 %
0012 %    INPUT/S
0013 %
0014 %      -image_width:
0015 %           The width of the input image.
0016 %
0017 %      -unwarped_image:
0018 %           The input image.
0019 %
0020 %      -unwarped_points:
0021 %           The control points of this image.
0022 %
0023 %      -placement_method:
0024 %           One of: 'overlap grid', 'grid', 'random',
0025 %           'random_and_scale', 'edge', 'edge_and_scale'.
0026 %
0027 %      -n_points:
0028 %           Number of points in grid?
0029 %
0030 %    OUTPUT/S
0031 %
0032 %      -grid:
0033 %           The grid in 1-D
0034 %
0035 %      -steps:
0036 %           The steps on the grid in 1-D
0037 %
0038 %    PENDING WORK
0039 %
0040 %      -
0041 %
0042 %    KNOWN BUG/S
0043 %
0044 %      -
0045 %
0046 %    COMMENT/S
0047 %
0048 %      -steps must be specified for single-point warps but not for
0049 %      multi-point warps
0050 %
0051 %    RELATED FUNCTION/S
0052 %
0053 %
0054 %
0055 %    ABOUT
0056 %
0057 %      -Created:     November 23rd, 2003
0058 %      -Last update: Novermber 25th, 2003
0059 %      -Revision:    0.0.2
0060 %      -Author:      R. S. Schestowitz, University of Manchester
0061 % ==============================================================
0062 
0063 steps = [];
0064 
0065 switch placement_method,
0066     
0067   case 'overlap_grid'
0068     ctr = 1;
0069     for i=1:5
0070         step = 2 / (i + 1); % 2/2=1, 2/3, 2/4=1/2, 2/5...
0071         for j=1:i % will execute 1,2,3... times
0072           grid(ctr)= -1 + j * step; % 0 + stepsize*number of steps
0073           steps(ctr) = step; % CTR STANDS FOR COUNTER, NOT CENTRE - save corresponding step size
0074           ctr = ctr + 1; % increment step index
0075         end
0076     end
0077     
0078   case 'grid'
0079     grid = -0.9:0.2:0.9; % divide into 10 segments (10 lines or knot-points)
0080   
0081   case 'alternating_grid'
0082 %     random_number = rand;
0083 %     if (rand < 0.3)
0084 %        grid = -0.9:0.2:0.9; % divide into 10 segments
0085 %     elseif (rand > 0.7)
0086 %        grid = -0.9:0.3:0.9; % divide into 7 segments
0087 %     else
0088 %        grid = -0.8:0.4:0.8; % divide into 5 segments
0089 %     end
0090    grid = -0.45:0.1:0.45;
0091       % ...still to be modified...
0092    
0093   case 'random'
0094     for ctr = 1:n_points
0095       grid(ctr) = rand * 2 - 1; % choose one to begin with... do-while loop would fit better here
0096       while(min(abs(grid(1:ctr-1) - grid(ctr))) < 0.01) % find the minimum of the differences and ensure it is very small
0097         grid(ctr) = rand * 2 - 1; % generate the next random value for a line margin in the grid until it's a good choice
0098       end
0099     end
0100 
0101   case 'random_and_scale'
0102       % width is only used here, but it is not really image width!!
0103     for ctr = 1:n_points
0104       steps(ctr) = image_width + 1;
0105       while (steps(ctr) > image_width / 2) % iterate until the value is good enough, i.e. small enough
0106         steps(ctr) = abs(randn(1)) * (image_width / 2) * 0.7; % some mysterious formulation
0107       end
0108       grid(ctr) = -1 + steps(ctr) + rand * (image_width - 2 * steps(ctr)); % set grid according to step above and apply some randomisation to step size too
0109 %     grid(ctr) = steps(ctr) + 1 + rand*(image_width - 2*steps(ctr));
0110     end
0111 
0112   case 'edge'
0113     % Smith: put knotpoints on n_knots strongest edges
0114     % RSS: steps however is not set, hence no 'scale'
0115     n_knots = n_points;
0116       % Smith set this to 2
0117     edges = diff(unwarped_image);
0118     [dummy,indices] = sort(abs(edges));
0119     indices = flipud(indices);
0120     which = indices(1:n_knots);
0121     grid = unwarped_points(which);
0122   
0123   case 'edge_and_scale'
0124       % put knotpoints on n_knots strongest edges
0125     n_knots = n_points; 
0126       % Smith set this to 2 for bump data
0127     edges = diff(unwarped_image);
0128     [dummy,indices] = sort(abs(edges));
0129       % absolute value as we do not account for "mirroring" effects
0130     indices = flipud(indices);
0131       % sort them by magnitude
0132     which = indices(1:n_knots); 
0133       % choose these which are the strongest n edges
0134     grid = unwarped_points(which);
0135     steps = min([1 - abs(grid), 1 + abs(grid)], [], 2);
0136   
0137   otherwise
0138     error(['Placement method ',placement_method,' is unknown']);
0139 end

Generated on Fri 14-May-2004 10:05:30 by m2html © 2003