-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtile_image.m
41 lines (37 loc) · 927 Bytes
/
tile_image.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
function tile_image(img,outpat,isize,padsize)
%tile_image Splits large image into tiles
% Arguments:
% img: Input image to tile
% outpat: Output pattern (should include two %02d or similar specifiers for tile coordinates)
% isize: Tile size
% padsize: Size of the padding around the tile
img = padarray(img,[padsize padsize],0);
j = 0;
for ystart=1:isize:size(img,1)-padsize-isize
j = j + 1;
i = 0;
ybreak = 0;
yend = ystart + isize + 2 * padsize - 1;
if yend > size(img,1)
yend = size(img,1);
ybreak = 1;
end
for xstart=1:isize:size(img,2)-padsize-isize
i = i + 1;
xbreak = 0;
xend = xstart + isize + 2 * padsize - 1;
if xend > size(img,2)
xend = size(img,2);
xbreak = 1;
end
subimg = img(ystart:yend,xstart:xend);
imwrite(subimg,sprintf(outpat,j,i));
if xbreak
break
end
end
if ybreak
break
end
end
end