-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLBAIM.m
More file actions
81 lines (58 loc) · 2.8 KB
/
LBAIM.m
File metadata and controls
81 lines (58 loc) · 2.8 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
70
71
72
73
74
75
76
77
78
79
80
81
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% %%%
%%% LBAIM (local binocular attention based on information maximization) %%%
%%% %%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [infomap,response,histo] = LBAIM(imL,imR,fixpoint,bases1,bases2,convolve)
% Set to defaults or input values
nargs = nargin;
if nargs < 6, convolve = 1; end
% For convolve = 1 set these
sigval = 5; % How many pixels correspond to 1 degree visual angle
sigwin = [30 30]; % What size of window is needed to contain the above
histwin_half = 20;
bins = 55;
% Output related
contrastval = 2; % How much contrast in the "transparent" representation
% Read image
imL = im2double(imL);
imR = im2double(imR);
p = 10; pm = p-1; ph = p/2;
col_imL = im2col(imL,[p p],'sliding');
col_imR = im2col(imR,[p p],'sliding');
col_bino = [col_imL;col_imR];
response = reshape((bases1'*col_bino).^2+(bases2'*col_bino).^2,[size(bases1',1),size(imL,1)-p+1,size(imL,2)-p+1]);
minscale = min(min(min(response)));
maxscale = max(max(max(response)));
for z=1:size(response,1)
% Translate image from 1xMxN to MxN for ease of processing
tempim = zeros(size(imL,1)-pm,size(imL,2)-pm);
tempim(1:size(imL,1)-pm,1:size(imL,2)-pm) = response(z,1:size(imL,1)-pm,1:size(imL,2)-pm);
% Scale temporary copy of feature plane
stempim = tempim-minscale;
stempim = stempim./(maxscale-minscale);
% Compute histogram from the local region around the fixpoint
% (fixpoint is usually set ot the center of the image)
histo = imhist(stempim((fixpoint(1)-histwin_half):(fixpoint(1)+histwin_half),(fixpoint(2)-histwin_half):(fixpoint(2)+histwin_half)),bins);
% Rescale values based on histogram to reflect likelihood
ts(z,:,:) = histo(round(stempim*(bins-1)+1))./sum(histo);
end
% Overall information content is product of individual feature maps with
% Shannon definition of Self-Information applied - Can do a log of products
% or a sum of logs...
% Width and height of information map
wid = size(ts,2);
hei = size(ts,3);
% Initialize to information gained from 1st feature domain
infomapt = -log(reshape(ts(1,:,:),wid,hei)+0.000001);
% Add information gained from remaining features
for z=2:size(response,1)
infomapt = infomapt - log(reshape(ts(z,:,:),wid,hei)+0.000001);
end
if (convolve == 1)
infomapt = filter2(fspecial('gaussian',sigwin,sigval),infomapt);
end
infomapt = infomapt.^contrastval;
% Pad the final map so that its size matches the input image
infomap = zeros(size(imL,1),size(imL,2))+min(min(infomapt));
infomap(ph+1:size(imL,1)-ph+1,ph+1:size(imL,2)-ph+1)=infomapt;