norm: L1 and L2 norm

Description Usage Arguments Details Value Author(s) Examples

View source: R/eval.r

Description

Computes the L1 or L2 norm between two vectors or matrices.

Usage

1
norm(orgImage, testImage, mode = "L2")

Arguments

orgImage

A vector or a matrix.

testImage

A vector or a matrix of same size as orgImage.

mode

Defaults to mode="L2" to compute a L2 norm between orgImage and testImage. Alternative choice is "L1".

Details

If X and Y are vectors of length n or (n1,n2)-matrices with n=n1*n2 then the L1-norm and the L2-norm will be compute as follow:

L1 = 1/n*(∑_{i=1}^{n} |X_i-Y_i|)

L2 = (1/n*(∑_{i=1}^{n} (X_i-Y_i)^2))^0.5

Value

Returns the L1 or L2 norm.

Author(s)

Joern Schulz, jschulz78@web.de.

Examples

1
2
3
4
P <- phantom(n=101)
P.pois <- markPoisson(P)$Data
cat("The L1 is:",norm(P, P.pois, mode="L1"),"\n")
rm(P,P.pois)

Example output

Loading required package: adimpro
Loading required package: awsMethods

Use the function setCores() to change the number of CPU cores.

sh: 1: cannot create /dev/null: Permission denied
sh: 1: cannot create /dev/null: Permission denied
sh: 1: cannot create /dev/null: Permission denied
Reading RAW images requires to install dcraw, see 

    http://cybercom.net/~dcoffin/dcraw/ for LINUX and http://www.insflug.org/raw/ 
    for MAC OS and Windows 


Attaching package: 'PET'

The following object is masked from 'package:base':

    norm

Warning message:
In fun(libname, pkgname) : could not determine path to Imagemagick 

    please set the correct path manually using 

    'Sys.setenv(ImageMagick='path2imagemagick')'
Creation of the source-data --> complete. 
AR step: 
Progress: 71 %
Progress: 100 %
Needed time in all:  0.606 0.061 0.668 0 0 
The L1 is: 18.60592 

PET documentation built on May 2, 2019, 2:43 a.m.