Mercurial > hg > ishara
annotate general/discretise/intmap.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 function M=intmap(min,max) |
samer@4 | 2 % intmap - Discretisation map for integers (ie alread discrete) |
samer@4 | 3 % |
samer@4 | 4 % intmap :: integer~'min value', integer~'max value' -> dmap(N). |
samer@4 | 5 % |
samer@4 | 6 % Maps integers to natural numbers, saves on multiplications and |
samer@4 | 7 % roundings as performed by the real->natural maps. |
samer@4 | 8 |
samer@4 | 9 N=max-min+1; |
samer@4 | 10 off=min-1; |
samer@4 | 11 M=dmap(N,@map,@revmap); |
samer@4 | 12 |
samer@4 | 13 function I=map(X) |
samer@4 | 14 I=X-off; |
samer@4 | 15 I(I<1)=-inf; |
samer@4 | 16 I(I>N)=inf; |
samer@4 | 17 end |
samer@4 | 18 |
samer@4 | 19 function X=revmap(I) |
samer@4 | 20 I=shiftdim(shiftdim(I),-1); |
samer@4 | 21 X1=off+I-0.5; |
samer@4 | 22 X2=off+I+0.5; |
samer@4 | 23 X=cat(1,X1,X2); |
samer@4 | 24 end |
samer@4 | 25 end |
samer@4 | 26 |