X
PrevPrev Go to previous topic
NextNext Go to next topic
Last Post 25 Jun 2015 12:55 PM by  anon
applying partial least squares regression coefficient to hyperspectral image
 3 Replies
Sort:
You are not authorized to post a reply.
Author Messages

anon



New Member


Posts:
New Member


--
25 Jun 2015 12:55 PM
    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

    MariM



    Veteran Member


    Posts:2396
    Veteran Member


    --
    25 Jun 2015 01:08 PM
    Isn't this similar to applying a gain and offset to each band? If so, I would suggest you look at ENVI's ENVIApplyGainOffsetTask (or gainoff_doit in ENVI Classic). file:///C:/Program%20Files/Exelis/ENV...

    Deleted User



    New Member


    Posts:
    New Member


    --
    25 Jun 2015 02:39 PM
    Thank you. This is a useful suggestion. However, I am not sure how I will end up with a single band image using this. And, how will I add the intercept after the gain values are multiplied with the respective bands for each pixel?

    MariM



    Veteran Member


    Posts:2396
    Veteran Member


    --
    29 Jun 2015 07:51 AM
    I thought you were trying to apply the coefficient and intercept (offset) to each pixel in a band which would result in a multi-band file. This is what the Gain and Offset tool in ENVI does. It sounds like you want to apply a gain/offset to each spectrum, is this correct?
    You are not authorized to post a reply.