-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmake_tile.m
142 lines (108 loc) · 3.03 KB
/
make_tile.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
function tile = make_tile( pix, type, mode )
% tile = make_tile( pix, type, mode )
% Creates a 2D image wallpaper tile given a patch size in pixels, a
% type of tile shape and a mode for the pixel values.
%
% pix : m x n sparse matrix
%
% type : character string, specifies Wallpaper group type
%
% motif : character string, specifies pixel distribution
%
% Written by Rick Gilmore, [email protected]
%
% Released under GPLv3
%--------------------------------------------------------------------------
%
% History
%
% 2013-04-21 rog wrote
%--------------------------------------------------------------------------
%
% Development notes
%
% 2013-04-21 Need to add and test code for complete set of 17 Wallpaper
% groups.
% Define defaults if unspecified
if nargin > 3
error('Too many input arguments.');
elseif nargin == 2
mode = 'randn';
elseif nargin == 1
type = 'L';
mode = 'randn';
elseif nargin < 1
pix = 7;
type = 'L';
mode = 'randn';
end
% Check parameters
[ nx, ny ] = size( pix );
if ( nx > 2 ) || ( ny > 2 )
error('Pix must be scalar or vector.');
end
if ~ischar( type )
error('Type must be character array.');
end
if ~ischar( mode )
error('Mode must be character array.');
end
% Initialize tile
if isscalar( pix )
tile = zeros( pix, pix );
end
if ( nx == 1 ) && ( ny == 2 )
tile = zeros( pix(1), pix(2) );
end
if ( nx == 2 ) && ( ny == 1 )
tile = zeros( pix(1), pix(2) );
end
[ tile_h, tile_v ] = size( tile );
% Determine center coords
center_v = round( (pix+1)/2 );
center_h = round( (pix+1)/2 );
% Make initial pattern i, j coordinates
switch type
case {'L'} % Minimal L shape has 3 pix on long and 2 pix on short
% Long segment
i1 = (center_v - 1) : (center_v + 1);
j1 = ones( 1, length( i1 ) ) * center_h;
% Short segment
i2 = center_v + 1;
j2 = center_h + 1;
% Combine
i = [ i1 i2 ];
j = [ j1 j2 ];
case {'F'} % Minimal F is 4 pix long x 2 pix wide
% Long segment
i1 = (center_v - 2) : (center_v + 1);
j1 = ones( 1, length( i1 ) ) * ( center_h - 1);
% Short segment top
i2 = center_v - 2;
j2 = center_h;
% Short segment middle
i3 = center_v;
j3 = center_h;
% Combine
i = [ i1 i2 i3 ];
j = [ j1 j2 j3 ];
case {'rand', 'RAND'}
% Want 'sparsity' to be comparable to 'F' and 'L' so
n_pts = 6;
i = round( rand(1,6)*( pix(1) - 1) + 1 );
j = round( rand(1,6)*( pix(1) - 1) + 1 );
otherwise
error('Type value not supported.');
end
% Make value array for image coordinates
switch mode
case {'randn'}
s = randn(1, length( i ) );
case {'bw', 'bw'}
s = ones( 1, length( i ) );
otherwise
error('Image mode not supported.');
end
% Generate tile as sparse matrix
tile = sparse( i, j, s, tile_h, tile_v );
return;