boblsturm@0
|
1 function [Y] = rot_kernel(kernel, deg)
|
boblsturm@0
|
2
|
boblsturm@0
|
3 N = size( kernel, 1 );
|
boblsturm@0
|
4 max_rots = 4*(N-1);
|
boblsturm@0
|
5 deg_per_rot = 360 / max_rots;
|
boblsturm@0
|
6
|
boblsturm@0
|
7 % deg = deg - mod( deg, deg_per_rot );
|
boblsturm@0
|
8 deg = deg_per_rot * ( round( deg / deg_per_rot ) );
|
boblsturm@0
|
9 num_of_rots = ceil( deg / deg_per_rot );
|
boblsturm@0
|
10
|
boblsturm@0
|
11 if num_of_rots < 1
|
boblsturm@0
|
12 Y = kernel;
|
boblsturm@0
|
13 return
|
boblsturm@0
|
14 else
|
boblsturm@0
|
15 for r = 1:num_of_rots
|
boblsturm@0
|
16 if mod( r, 2 ) == 0
|
boblsturm@0
|
17 kernel = rot_outer_layer( kernel );
|
boblsturm@0
|
18 else
|
boblsturm@0
|
19 kernel = rot_inner_layer( kernel );
|
boblsturm@0
|
20 end
|
boblsturm@0
|
21 end
|
boblsturm@0
|
22 end
|
boblsturm@0
|
23
|
boblsturm@0
|
24 Y = kernel;
|
boblsturm@0
|
25
|
boblsturm@0
|
26 end
|
boblsturm@0
|
27
|
boblsturm@0
|
28 function [Y] = rot_outer_layer( A )
|
boblsturm@0
|
29 dim = size( A, 1 );
|
boblsturm@0
|
30 top = A( 1, : );
|
boblsturm@0
|
31 right = A( 2:dim, dim )';
|
boblsturm@0
|
32 bottom = fliplr( A( dim, 1:dim - 1 ) );
|
boblsturm@0
|
33 left = fliplr( A( 2:dim - 1, 1 )' );
|
boblsturm@0
|
34 shifted_layers = wshift('1D',[top,right,bottom,left],-1);
|
boblsturm@0
|
35
|
boblsturm@0
|
36 top = shifted_layers( 1:length(top));
|
boblsturm@0
|
37 last_ind = length( top );
|
boblsturm@0
|
38
|
boblsturm@0
|
39 right = shifted_layers( last_ind + 1 : last_ind + length(right));
|
boblsturm@0
|
40 last_ind = last_ind + length( right );
|
boblsturm@0
|
41
|
boblsturm@0
|
42 bottom = shifted_layers( last_ind + 1 : last_ind + length(bottom));
|
boblsturm@0
|
43 last_ind = last_ind + length( bottom );
|
boblsturm@0
|
44
|
boblsturm@0
|
45 left = shifted_layers( last_ind + 1 : end );
|
boblsturm@0
|
46
|
boblsturm@0
|
47 A( 1, : ) = top;
|
boblsturm@0
|
48 A( 2:dim, dim ) = right';
|
boblsturm@0
|
49 A( dim, 1:dim - 1 ) = fliplr( bottom );
|
boblsturm@0
|
50 A( 2:dim - 1, 1 ) = fliplr( left' );
|
boblsturm@0
|
51
|
boblsturm@0
|
52 Y = A;
|
boblsturm@0
|
53 end
|
boblsturm@0
|
54
|
boblsturm@0
|
55 function [Y] = rot_inner_layer( kernel )
|
boblsturm@0
|
56 % dim = size( kernel, 1 );
|
boblsturm@0
|
57 % if dim < 2
|
boblsturm@0
|
58 % Y = rot_outer_layer( kernel )
|
boblsturm@0
|
59 % return;
|
boblsturm@0
|
60 % else
|
boblsturm@0
|
61 % Y = rot_inner_layer( kernel( 2:dim - 1, 2:dim - 1 ) )
|
boblsturm@0
|
62 % end
|
boblsturm@0
|
63 dim = size( kernel, 1 );
|
boblsturm@0
|
64
|
boblsturm@0
|
65 if mod( dim / 2, 2 ) == 0
|
boblsturm@0
|
66 max_rots = dim / 2 - 1;
|
boblsturm@0
|
67 else
|
boblsturm@0
|
68 max_rots = dim / 2 - 0.5;
|
boblsturm@0
|
69 end
|
boblsturm@0
|
70
|
boblsturm@0
|
71 low = 2;
|
boblsturm@0
|
72 high = dim - 1;
|
boblsturm@0
|
73 for i = 1:max_rots
|
boblsturm@0
|
74 kernel( low:high, low:high ) = rot_outer_layer( kernel( low:high, low:high ) );
|
boblsturm@0
|
75 low = low + 1;
|
boblsturm@0
|
76 high = high - 1;
|
boblsturm@0
|
77 end
|
boblsturm@0
|
78
|
boblsturm@0
|
79 Y = kernel;
|
boblsturm@0
|
80 end |