forked from tiepvupsu/DICTOL
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdisplayPatches.m
59 lines (57 loc) · 1.58 KB
/
displayPatches.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
function displayPatches2(D, nRows, nCols)
% function tmp = displayPatches(D)
% Display all columns of `D` in an panel
% require: `size(D, 1)` is a square number or `size(D, 1)/3` is a square number
% (the former case corresponds to color)
% -----------------------------------------------
% Author: Tiep Vu, [email protected], 6/1/2016 10:09:38 AM
% (http://www.personal.psu.edu/thv102/)
% -----------------------------------------------
V = 1;
[n, K] = size(D);
size(D);
sizeEdge=sqrt(n/V);
if floor(sizeEdge) ~= sizeEdge
V=3;
sizeEdge=sqrt(n/V);
end
%% nomalization
p=3.5;
m=min((D(:)));
if (m >= 0)
me=0;
sig=sqrt(mean(((D(:))).^2));
else
me=mean(D(:));
sig=sqrt(mean(((D(:)-me)).^2));
end
D = D-me;
D = min(max(D,-p*sig),p*sig);
M = max((D(:)));
m = min((D(:)));
D = (D-m)/(M-m);
%% Prepare the panel
% nRows=floor(sqrt(K)); % number of rows
% nCols = ceil(K/nRows); % number of columns
if nargin == 1
[nRows, nCols] = my_factor(K);
elseif nargin == 2
nCols = ceil(K/nRows);
end
tmp = zeros((sizeEdge+1)*nRows+1,(sizeEdge+1)*nCols+1,V);
for r = 1:nRows
for c = 1:nCols
if (r-1)*nCols+c > K
break;
end
patchCol = D(:,(r-1)*nCols+c);
patchCol = reshape(patchCol, [sizeEdge,sizeEdge V]);
tmp(((r-1)*(sizeEdge+1)+2): (r*(sizeEdge+1)),...
((c-1)*(sizeEdge+1)+2) : (c*(sizeEdge+1)), :) = patchCol;
end
end
%% display
colormap('jet');
imagesc(tmp);
axis equal off;
end