|
a |
|
b/combinedDeepLearningActiveContour/functions/display_network.m |
|
|
1 |
function [h, array] = display_network(A, opt_normalize, opt_graycolor, cols, opt_colmajor) |
|
|
2 |
% This function visualizes filters in matrix A. Each column of A is a |
|
|
3 |
% filter. We will reshape each column into a square image and visualizes |
|
|
4 |
% on each cell of the visualization panel. |
|
|
5 |
% All other parameters are optional, usually you do not need to worry |
|
|
6 |
% about it. |
|
|
7 |
% opt_normalize: whether we need to normalize the filter so that all of |
|
|
8 |
% them can have similar contrast. Default value is true. |
|
|
9 |
% opt_graycolor: whether we use gray as the heat map. Default is true. |
|
|
10 |
% cols: how many columns are there in the display. Default value is the |
|
|
11 |
% squareroot of the number of columns in A. |
|
|
12 |
% opt_colmajor: you can switch convention to row major for A. In that |
|
|
13 |
% case, each row of A is a filter. Default value is false. |
|
|
14 |
warning off all |
|
|
15 |
|
|
|
16 |
if ~exist('opt_normalize', 'var') || isempty(opt_normalize) |
|
|
17 |
opt_normalize= true; |
|
|
18 |
end |
|
|
19 |
|
|
|
20 |
if ~exist('opt_graycolor', 'var') || isempty(opt_graycolor) |
|
|
21 |
opt_graycolor= true; |
|
|
22 |
end |
|
|
23 |
|
|
|
24 |
if ~exist('opt_colmajor', 'var') || isempty(opt_colmajor) |
|
|
25 |
opt_colmajor = false; |
|
|
26 |
end |
|
|
27 |
|
|
|
28 |
% rescale |
|
|
29 |
A = A - mean(A(:)); |
|
|
30 |
|
|
|
31 |
if opt_graycolor, colormap(gray); end |
|
|
32 |
|
|
|
33 |
% compute rows, cols |
|
|
34 |
[L M]=size(A); |
|
|
35 |
sz=sqrt(L); |
|
|
36 |
buf=1; |
|
|
37 |
if ~exist('cols', 'var') |
|
|
38 |
if floor(sqrt(M))^2 ~= M |
|
|
39 |
n=ceil(sqrt(M)); |
|
|
40 |
while mod(M, n)~=0 && n<1.2*sqrt(M), n=n+1; end |
|
|
41 |
m=ceil(M/n); |
|
|
42 |
else |
|
|
43 |
n=sqrt(M); |
|
|
44 |
m=n; |
|
|
45 |
end |
|
|
46 |
else |
|
|
47 |
n = cols; |
|
|
48 |
m = ceil(M/n); |
|
|
49 |
end |
|
|
50 |
|
|
|
51 |
array=-ones(buf+m*(sz+buf),buf+n*(sz+buf)); |
|
|
52 |
|
|
|
53 |
if ~opt_graycolor |
|
|
54 |
array = 0.1.* array; |
|
|
55 |
end |
|
|
56 |
|
|
|
57 |
|
|
|
58 |
if ~opt_colmajor |
|
|
59 |
k=1; |
|
|
60 |
for i=1:m |
|
|
61 |
for j=1:n |
|
|
62 |
if k>M, |
|
|
63 |
continue; |
|
|
64 |
end |
|
|
65 |
clim=max(abs(A(:,k))); |
|
|
66 |
if opt_normalize |
|
|
67 |
array(buf+(i-1)*(sz+buf)+(1:sz),buf+(j-1)*(sz+buf)+(1:sz))=reshape(A(:,k),sz,sz)/clim; |
|
|
68 |
else |
|
|
69 |
array(buf+(i-1)*(sz+buf)+(1:sz),buf+(j-1)*(sz+buf)+(1:sz))=reshape(A(:,k),sz,sz)/max(abs(A(:))); |
|
|
70 |
end |
|
|
71 |
k=k+1; |
|
|
72 |
end |
|
|
73 |
end |
|
|
74 |
else |
|
|
75 |
k=1; |
|
|
76 |
for j=1:n |
|
|
77 |
for i=1:m |
|
|
78 |
if k>M, |
|
|
79 |
continue; |
|
|
80 |
end |
|
|
81 |
clim=max(abs(A(:,k))); |
|
|
82 |
if opt_normalize |
|
|
83 |
array(buf+(i-1)*(sz+buf)+(1:sz),buf+(j-1)*(sz+buf)+(1:sz))=reshape(A(:,k),sz,sz)/clim; |
|
|
84 |
else |
|
|
85 |
array(buf+(i-1)*(sz+buf)+(1:sz),buf+(j-1)*(sz+buf)+(1:sz))=reshape(A(:,k),sz,sz); |
|
|
86 |
end |
|
|
87 |
k=k+1; |
|
|
88 |
end |
|
|
89 |
end |
|
|
90 |
end |
|
|
91 |
|
|
|
92 |
if opt_graycolor |
|
|
93 |
h=imagesc(array,'EraseMode','none',[-1 1]); |
|
|
94 |
else |
|
|
95 |
h=imagesc(array,'EraseMode','none',[-1 1]); |
|
|
96 |
end |
|
|
97 |
axis image off |
|
|
98 |
|
|
|
99 |
drawnow; |
|
|
100 |
|
|
|
101 |
warning on all |