X
PrevPrev Go to previous topic
NextNext Go to next topic
Last Post 05 Apr 2021 11:44 AM by  Amber Iler
Minimum Noise Fraction (MNF) options in IDL
 3 Replies
Sort:
You are not authorized to post a reply.
Author Messages

Amber Iler



New Member


Posts:2
New Member


--
26 Mar 2021 03:31 PM
    Hello,

    I'm working on a procedure that will help automate the hyperspectral workflow I've been repeating by hand to whiten my data and associated spectral library. The idea is to provide the file name of a hyperspectral file and an ROI file that identifies a convenient uniform area to use for the shift difference noise calculations. I attempted to use the ENVI 'ForwardMNFTransform' Task, but it doesn't appear that this task allows you to perform a shift difference noise calculation. Thus, I have resorted to the MNF_DOIT routine, but I am again encountering problems applying the shift difference.

    Here's my current code:

    PRO whitening_automation


    ; Specify input file and ROI to use for noise statistics calculation (ideally, a uniform dark area)

    inFile = FILEPATH('006_140820_175610_L2S.dat', ROOT_DIR="F:\L2Data\")

    roiFile = FILEPATH('006_140820_175610_uniform.roi', ROOT_DIR="F:\L2Data\")


    ; Also provide an output directory and root filename to use for output files

    outDir = "F:\HSI_demo\"

    rootName = "006_140820_175610"


    ; Open input file and load the uniform ROI to use for whitening

    raster = e.OpenRaster(inFile)

    ENVI_Restore_ROIs, roiFile


    ; Get the input file ID and query the file for dimensions and number of bands

    fid = ENVIRasterToFID(raster)

    ENVI_File_Query, fid, DIMS=dims, NB=nb


    ; Get the pointer ID for the ROI

    roiID = ENVI_GET_ROI_IDS(FID=fid)


    ; Now perform MNF transform

    ENVI_Doit, 'MNF_Doit', $
    FID = fid, $
    DIMS = dims, $
    POS = Lindgen(nb), $
    OUT_NAME = outDir+rootName+'_mnf' $
    SD_DIMS = roiID, $
    /SHIFT_DIFF, $
    STA_NAME = outDir+rootName+'_mnf.sta', $
    NOISE_STA_NAME = outDir+rootName+'_mnf_noise.sta', $
    /NO_PLOT, $
    R_FID = mnf_fid

    Can anyone identify where this has gone wrong or provide an alternative that uses the ENVI 'ForwardMNFTransform' Task? Thanks!


    Amber Iler



    New Member


    Posts:2
    New Member


    --
    30 Mar 2021 08:05 AM
    One issue appears to be a missing comma after the definition of OUT_NAME, which should read:

    OUT_NAME = outDir+rootName+'_mnf', $


    MariM



    Veteran Member


    Posts:2396
    Veteran Member


    --
    31 Mar 2021 07:32 AM
    The main issue here is that SD_DIMS cannot use an ROI directly in the DIMS parameter. The SD_DIMS needs the actual rectangular DIMS (in samples/lines) of the ROI. You can use the undocumented routine, envi_roi_compute_spatial_boundry, to obtain the rectangular DIMS of the ROI:

    roiID = ENVI_GET_ROI_IDS(FID=fid)
    envi_roi_compute_spatial_boundry, roiid[0], sd_dims, fid=fid
    print, 'sd_dims are ', sd_dims

    Amber Iler



    New Member


    Posts:2
    New Member


    --
    05 Apr 2021 11:44 AM
    Thank you, Mari. It appears one remaining issue is that MNF_DOIT wants the IN_MEMORY parameter to be set to 0, despite this not being required according to the documentation. Without it, it doesn't run through to completion. For posterity, here are the changes I made to the procedure from the "Get the pointer ID for the ROI" comment line:

    ; Get the pointer ID for the ROI

    roiIDs = ENVI_GET_ROI_IDS(FID=fid)

    ENVI_ROI_COMPUTE_SPATIAL_BOUNDRY, roiIDs[0], sd_dims, FID=fid

    ; Now perform MNF transform

    ENVI_Doit, 'MNF_Doit', $

    FID = fid, $

    DIMS = dims, $

    IN_MEMORY = 0, $

    POS = Lindgen(nb), $

    OUT_NAME = outDir+rootName+'_mnf', $

    SD_DIMS = sd_dims, $

    /SHIFT_DIFF, $

    STA_NAME = outDir+rootName+'_mnf.sta', $

    NOISE_STA_NAME = outDir+rootName+'_mnf_noise.sta', $

    /NO_PLOT, $

    R_FID = mnf_fid

    You are not authorized to post a reply.