Hello,
I have a 67x67x149 (col, row, band) hyperpsectral image. I have partial least squares regression coefficients that correspond to each band and an intercept. I want to multiply the corresponding coefficients with the corresponding band's spectral data and add the intercept for each pixel. The final product would be a single band image. I have some preliminary code from other application that I was trying to adapt to my purpose which I will paste below. I am thinking the coefficients can be brought in in a text file or something. Anyhow. I would be grateful if someone can help me with this as soon as possible. It wouild save a lot of time. Thank you!
c='E:\Hyperion_157bands\cont_rem_image.hdr'
;d=strcompress(c, /remove_all)
envi_open_file, c, r_fid=fid
if (fid eq -1) then return
;Figure out the image dimensions, using the anonymous structure created with
;the query command.
envi_file_query, fid, ns=ns, nl=nl, nb=nb
NumCols = ns
NumRows = nl
NumBands = 1 ; equate the number of bands to the number of indices you will calculate.
PLS_out = fltarr(NumBands,NumCols,NumRows)
;for each pixel create a 2 one-dimensional arrays. 1 containing the band number and the other
;the corresponding value in the band for the pixel we are at.
;x_val = intarr(149)
y_val = fltarr(149)
int = 3.41
;loop through the image:
for i=0, (NumCols - 1) do begin
for j=0, (NumRows - 1) do begin
;note that since envi starts an array at 0, then band 1 = band 0 and
;I have to subtract one from each of the bands above.
y_val=envi_get_slice(fid=fid, line=j, pos=pos, xs=i, xe=i)
if (total(y_val) gt 0) then begin
;calculate the derivatives
x_val = pos+1
; y_val = dmax
out = int + 0.2*float(y_val)
;one_deriv = deriv(x_val, y_val)
;two_deriv = deriv(x_val, one_deriv)
;populate the output image arrays, loop throught each band, one pixel at a time...
for k=0, (nb - 1) do begin
out1[k,i,j] = out[k]
;DerivOne[k,i,j] = one_deriv[k]
;DerivTwo[k,i,j] = two_deriv[k]
endfor
endif
endfor
endfor
;writing the array to tiff files
e='E:\Hyperion_157bands\PLSout_image.tif'
;f=strcompress(e, /remove_all)
write_tiff, e, PLS_out, /float
;close the file and remove from envi
envi_file_mng, id=fid, /remove
end
|