-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathvisualizer.m
More file actions
69 lines (56 loc) · 1.67 KB
/
visualizer.m
File metadata and controls
69 lines (56 loc) · 1.67 KB
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
function visualizer(img, cnn, patchsize)
%VISUALIZER - Visualizes the Similarity
% visualizer(img, cnn, patchsize)
% img - input image (default - 'img' from workspace)
% cnn - nn-field (default - 'cnn' from workspace)
% patchsize - patchsize (default - 'patchsize' from workspace)
%
% Author: Sk. Mohammadul Haque
% Copyright (c) 2013 Sk. Mohammadul Haque
%
ok = 0;
h2 = 0;
if(nargin<3), patchsize = evalin('base','patchsize'); end;
if(nargin<2), cnn = evalin('base','cnn'); end;
if(nargin<1), img = evalin('base','img'); end;
h = figure;
imshow(uint8(img));
sz = size(img);
if(numel(patchsize)==1), patchsize = [patchsize patchsize]; end;
while true
try
% try getting
while(~ok)
figure(h);
[y, x] = ginput(1);
x = fix(x); y = fix(y);
if(x>0 && x<=(sz(1)-patchsize(1)) && y>0 && y<=(sz(2)-patchsize(2)))
ok = 1;
end
end
hold off;
figure(h);
for k = find(h2~=0)
delete(h2(k,1));
end
hold on;
% get indices
nx = squeeze(full(cnn(x,y,1,:)))+1;
ny = squeeze(full(cnn(x,y,2,:)))+1;
nd = squeeze(full(cnn(x,y,3,:)));
% now draw
figure(h);
h2 = zeros(length(nd),1);
[~,ndi] = sort(nd);
ndim = max(ndi);
for k = 1:length(nd)
color = [(1-(find(ndi==k,1,'first')/ndim)^0.6) 0.15 0.15];
h2(k,1) = rectangle('Position',[nx(k) ny(k) patchsize(2) patchsize(1)],'LineWidth', 2,'EdgeColor', color);
end
% reset
ok = 0;
catch dummy
return;
end
end
end