fit3d: Fit a Plane to Image (Matrix) with SVD

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/fit3d.r

Description

Find plane that best fits trend in image (matrix)

Usage

1
fit3d(mat)

Arguments

mat

image (matrix) of values to fit plane to

Details

This function returns the best fit plane with the DC offset included. In other words average of the matrix values is added to the best fit plane within the function.

Value

matrix with same dimensions as mat whose values represent the best fit plane.

Author(s)

Alex J.C. Witsil

See Also

svd

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
## break the RGB image into 3 matrices
img.r <- erebus[,,1]
img.g <- erebus[,,2]
img.b <- erebus[,,3]

## find the planar trend in the red channel
trend.r <- fit3d(img.r)
trend.g <- fit3d(img.g)
trend.b <- fit3d(img.b)

## subtract the red channel trend from the original red channel image
img.r.detrend <- img.r-trend.r
img.g.detrend <- img.g-trend.g
img.b.detrend <- img.b-trend.b

## combine the RGB detrended matrices into an array
img.detrend = array(dim=dim(erebus))
img.detrend[,,1] <- img.r.detrend
img.detrend[,,2] <- img.g.detrend
img.detrend[,,3] <- img.b.detrend

################
### PLOTTING ###
################

close.screen(all.screens=TRUE)
split.screen(c(1,3))
screen(1)
image2(erebus,asp=1,main='Original Image',ylab='image rows',xlab='image cols')
screen(2)
image2(trend.r,asp=1,main='Fitted Trend',ylab='image rows',xlab='image cols')
screen(3)
image2(img.detrend,asp=1,main='Detrended Image',ylab='image rows',xlab='image cols')

## close screens
close.screen(all.screens=TRUE)

imagefx documentation built on Feb. 14, 2020, 1:07 a.m.