STK_LINREG Name
STK_LINREG Purpose
Fit line by linear regression to columns in a stack of images.
Category
Calling Sequence
stk_linreg, xx, yy, m, b, r2 Inputs
xx = x values for each pixel in stack (3-D). in
yy = stack of images (3-D). in
Keyword Parameters
Outputs
m = Slope of fit for each column in stk (2-D). out
b = y-intercept of fit for each column in stk (2-D). out
r2 = Correlation coeficient for each column (2-D). out
Common Blocks
Notes
Notes: yy is a stack of images. So it is a 3-D array.
xx is the corresponding 3-D array that gives the x value
for each image pixel. Let each image have size nx by ny,
and let there be nz images. Then to generate an xx array
that is the index of each image do the following:
t = reform(findgen(nz),1,1,nz) ; Make a single column of indices.
xx = rebin(t,nx,ny,nz,/samp) ; Now make full 3-D indices.
Reference: http://mathworld.wolfram.com/LeastSquaresFitting.html
Example
nx=5 & ny=8 & nz=10 ; Dimensions of stack.
t = reform(findgen(nz),1,1,nz) ; Column of indices.
xx = rebin(t,nx,ny,nz,/samp) ; Full index array.
yy = xx*27 + 73 + randomu(k,nx,ny,nz)*30 ; Make a noisy line.
stk_linreg,xx,yy,m,b,r2 ; Do fits.
hlp,m,b,r2 ; Check.
; 1 Float array (5, 8). Min = 25.2887, Max = 28.7566
; 2 Float array (5, 8). Min = 76.2687, Max = 98.0477
; 3 Float array (5, 8). Min = 0.982812, Max = 0.995149
plot,xx(2,3,*),yy(2,3,*),psym=-2
x = findgen(10)
oplot,x,x*m(2,3)+b(2,3),col=255
Modification History
R. Sterner, 2004 Jan 27
Copyright (C) 2004, Johns Hopkins University/Applied Physics Laboratory
This software may be used, copied, or redistributed as long as it is not
sold and this copyright notice is reproduced on each copy made. This
routine is provided as is without any express or implied warranties
whatsoever. Other limitations apply as described in the file disclaimer.txt.