annotate general/discretise/binmap.m @ 61:eff6bddf82e3 tip

Finally implemented perceptual brightness thing.
author samer
date Sun, 11 Oct 2015 10:20:42 +0100
parents e44f49929e56
children
rev   line source
samer@4 1 % binmap - linear discretisation map from bin centres
samer@4 2 %
samer@4 3 % binmap :: real~'first bin centre', real~'last bin centre', N:natural~'num bins'->dmap(N).
samer@4 4 function M=binmap(min,max,N)
samer@4 5
samer@4 6 dx=(max-min)/(N-1);
samer@4 7 rdx=1/dx;
samer@4 8 M=dmap(N,@map,@revmap);
samer@4 9
samer@4 10 function I=map(X)
samer@4 11 I=1+round(rdx*(X-min));
samer@4 12 I(I<1)=-inf;
samer@4 13 I(I>N)=inf;
samer@4 14 end
samer@4 15
samer@4 16 function X=revmap(I)
samer@4 17 I=shiftdim(shiftdim(I),-1);
samer@4 18 X1=min+(I-1.5)*dx;
samer@4 19 X2=min+(I-0.5)*dx;
samer@4 20 X=cat(1,X1,X2);
samer@4 21 end
samer@4 22 end