clear all
close all
load TestWithNoise_smalldisp.mat
nbins=20;

algorithm = { 'Dx_maxE_pureph' 'Dx_maxE_TE' 'Dx_maxE_all' 'Dx_phase' };
alglabel = { 'Max-E (phase only)' 'Max-E (pos only)' 'Max-E (hybrid pos/phase)' 'Our new algorithm'    };
col = {'b' 'g' 'm' 'y'};

dxb = [minD : (maxD-minD)/nbins : maxD]+0.01;
% Find which bin contains the true disparity
jdxtrue = find(hist(Dxtrue,dxb));
for j=1:length(algorithm)
    [freqq{j},dxx{j}] = eval(['hist(' algorithm{j} '(1:nims),dxb);']);
    pcacc(j) = freqq{j}(jdxtrue) / sum(freqq{j});
    SD(j) = std( eval(algorithm{j}) );
    if strcmp(alglabel{j},'max-E (phase only)') % add on other cycles
        for n=[-2 -1 1 2];
            if Dxtrue+n/SF > minD & Dxtrue+n/SF < maxD
                jdx = find(hist(Dxtrue+n/SF,dxb));
                pcacc(j) = pcacc(j) + freqq{j}(jdx) / sum(freqq{j});
            end
        end
    end
    alglabel{j} = sprintf('%s; %d%% accurate',alglabel{j},round(100*pcacc(j)));
end

for j=1:4
    mx(j) = max(freqq{j});
end
mxy = max(mx);
mxy = ceil(mxy/500)*500;

figure('pos',[49         627        1229         295])
for j=1:4
    subplot(1,4,j)
    bar(dxx{j},freqq{j})
    title(alglabel{j})
    xlim([minD maxD])
    hold on
    ylim([0 mxy])
    plot(Dxtrue*[1 1],ylim,'r')
    hold off
    xlabel('disparity (deg)')
    text(0.1,0.9,char(64+j),'units','norm','fonts',20,'fontw','bold')
end
drawnow
subplot(1,4,1)
ylabel('frequency')



