Learn R Programming

PET (version 0.5.1)

norm: L1 and L2 norm

Description

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

Usage

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".

Value

Returns the L1 or L2 norm.

Details

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

$$L1 = \frac{1}{n} \sum_{i=1}^{n}\left|X_i-Y_i\right| $$ $$L2 = \left(\frac{1}{n} \sum_{i=1}^{n}\left(X_i-Y_i\right)^2\right)^{\frac{1}{2}} $$

Examples

Run this code
# NOT RUN {
P <- phantom(n=101)
P.pois <- markPoisson(P)$Data
cat("The L1 is:",norm(P, P.pois, mode="L1"),"\n")
rm(P,P.pois)
# }

Run the code above in your browser using DataLab