annotate general/numerical/pnorm.m @ 61:eff6bddf82e3 tip

Finally implemented perceptual brightness thing.
author samer
date Sun, 11 Oct 2015 10:20:42 +0100
parents 8476b3d9d295
children
rev   line source
samer@4 1 function N=pnorm(p,A,D)
samer@4 2 % pnorm - general vector norm wrt exponent p
samer@4 3 %
samer@4 4 % pnorm :: nonneg, [[D1]], I:natural -> [[D2]].
samer@4 5 % pnorm :: nonneg, [[N D]] -> [[ 1 D]].
samer@4 6 %
samer@4 7 % where D2 = set(D1,I,1), ie the Ith dimension is
samer@4 8 % collapsed. I defaults to 1. The p-norm is defined as
samer@4 9 % pnorm(p,x,i) = sum(abs(x).^p,i).^(1/p)
samer@4 10 %
samer@4 11 % See also pdev for alternative which uses mean instead of sum
samer@4 12
samer@4 13 if nargin<2, D=1; end;
samer@4 14
samer@4 15 if p==2
samer@4 16 N=sqrt(sum(abs(A).^2,D));
samer@4 17 else
samer@4 18 N=sum(abs(A).^p,D).^(1/p);
samer@4 19 end
samer@4 20
samer@4 21