


==============================================================
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
==============================================================

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