-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmontage.m
64 lines (57 loc) · 1.28 KB
/
montage.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
% M = montage(images[, cy, cx[, pad]])
%
% Takes the cell array 'images' and displays the first
% cy*cx images of them on a grid, with 'pad' pixels in between.
function M = montage(images, cy, cx, pad),
if isnumeric(images),
rgb = length(size(images)) == 4 && size(images,3) == 3;
if rgb,
imagescell = cell(size(images, 4), 1);
for i=1:size(images,4),
imagescell{i} = images(:, :, :, i);
end
else,
imagescell = cell(size(images, 3), 1);
for i=1:size(images,3),
imagescell{i} = images(:, :, i);
end
end
images = imagescell;
end
if ~exist('cy', 'var'),
cy = floor(sqrt(length(images)));
end
if ~exist('cx', 'var'),
cx = ceil(sqrt(length(images)));
end
if ~exist('pad', 'var'),
pad = 5;
end
if cy < 0 && cx > 0,
cy = ceil(length(images) / cx);
end
if cx < 0 && cy > 0,
cx = ceil(length(images) / cy);
end
if length(images) == 0,
M = [];
return;
end
ny = size(images{1}, 1)+pad*2;
nx = size(images{1}, 2)+pad*2;
nf = size(images{1}, 3);
M = ones(ny*cy, nx*cx, nf);
c = 1;
for j=1:cy,
for i=1:cx,
im = padarray(im2double(images{c}), [pad pad 0], 1);
im = imresize(im, [ny nx]);
im(im > 1) = 1;
im(im < 0) = 0;
M((j-1)*ny+1:j*ny, (i-1)*nx+1:i*nx, :) = im;
c = c + 1;
if c > length(images),
return;
end
end
end