Mercurial > hg > ishara
view general/discretise/linmap.m @ 61:eff6bddf82e3 tip
Finally implemented perceptual brightness thing.
author | samer |
---|---|
date | Sun, 11 Oct 2015 10:20:42 +0100 |
parents | e44f49929e56 |
children |
line wrap: on
line source
function M=linmap(p1,p2,p3) % linmap - Create linearly spaced discretisation map % % linmap :: Min:real, Max:real, N:natural -> dmap(N). % linmap :: [Min,Max]:[[1,2]], N:natural -> dmap(N). % % Parameters work almost but not quite like linspace: the % third parameter is the number of GAPS, not the number of % points, defining the map, So for a map with edges at 0:10, % use linmap(0,10,10). To get the same edges from linspace, % you would need linspace(0,10,11). % unpack parameters if nargin==2, min=p1(1); max=p1(2); bins=p2; else min=p1; max=p2; bins=p3; end dx=(max-min)/bins; M=dmap(bins,@(t)map(bins,min,1/dx,t),@(t)revmap(min,dx,t)); function I=map(N,min,k,X) I=1+floor(k*(X-min)); I(I<1)=-inf; I(I>N)=inf; function X=revmap(min,ik,I) I=shiftdim(shiftdim(I),-1); X1=min+(I-1)*ik; X2=min+(I)*ik; X=cat(1,X1,X2);