Masthead

Lab 2: Image Processing Techniques in ENVI

Introduction

In this lab we will cover the ENVI processing techniques for radiometric calibration, atmospheric correction and masking. This lab will also cover applying masks and calculating spectral indices.

Learning Outcomes

About the Data
The primary data is this lab is Landsat Collection 2 Level-1, Landsat Collection 2 Level-2 Surface Reflectance data will be viewed for comparison.
The specific data used in the lab is a Landsat 9 image of the Oregon acquired May 2nd 2025.

Introduction to ENVI Modeler: Automating Workflows

The ENVI Modeler is a visual programming tool that enables you to create custom task-based workflows within ENVI. The user interface is designed to help users build workflows without any knowledge of ENVI programming. You can easily create custom workflows and batch-process data with the ENVI Modeler. A model consists of two primary elements: nodes and connectors. A node is a basic building block such as an input file, task, or other operation. A connector is a grey line that connects nodes to one another via their input and output parameters. Task nodes are displayed as yellow-colored boxes, while Basic nodes are displayed as boxes of various colors (depending on your selection). If a node accepts input, it has an arrow on the left side. If it creates output, it has an arrow on the right side. A node can have arrows on both sides.

ENVI Modeler Examples from NV5 Geospatial

Examples ENVI Models from GitHub

ENVI Task List

  1. Start the ENVI Modeler using one of these options:

    • Select Display > ENVI Modeler from the ENVI menu bar.
    • In the ENVI Toolbox, expand the Task Processing folder and double-click ENVI Modeler. You can also drag and drop an existing .model file into the ENVI application
  1. The ENVI Modeler interface will open in a new window. by default, a blank model is open in the Layout Window. To begin,click the Save icon and save your model as Low High Clip in the folder titled 'Models'.ENVI Modeler
  2. Double-click (or drag into the model layout window) the Input Parameters under the Basic Nodes menu. The Input Parameters node creates a user interface window that opens when the model is launched, allowing the user to specify the input files and parameters to use in the model.
  3. Next, we will add a Task to the model. In the Tasks menu, find the Low Clip task and add it to the model window by double clicking or dragging the task into the window. To find Tasks quicker, you can type the name of task into the search bar. See the full list of Tasks available: ENVI Task List.
  4. Click the Parameters Icon button in the Low Clip node, this will open the parameters of a node. The Low Clip task has three parameters: the Input Raster (the raster to be clipped), the Threshold (pixel values below the threshold are set to the specified threshold value), and the Output Raster (where/how the resulting raster will be saved). Close the Low Clip window for now.Low Clip Parameters
  5. All elements in a model need to be related with a connector. A connector is a grey line that connects nodes to one another. Connect the Low Clip node to the Input Parameters node. To connect nodes, move the cursor over an arrow in a node until a + icon appears. Click and drag to draw a line to the appropriate arrow on another node, then release the mouse button, once connected the connector becomes a solid line. Connect Nodes
  6. After adding this connection, the Connect Parameters window will open automatically. If more than one connection is possible between two nodes, the Connect Parameters dialog automatically appears so that you can specify the correct connection. In the window, click the Add New Inputs button under the Input Parameters and then click Input Raster. This creates an input parameter box that will allow the user to specify the raster file. Essentially, the connection feeds the user-specified raster into the Low Clip task. Click OK
  7. Add Inputs to Nodes
  8. Click the Parameters Icon button in the Low Clip node to open the task parameters. The Input Raster should now be linked to the Input Parameters [input_raster], but the other parameters still need to be specified. The threshold needs to be set for each band (seven bands total for this data) as an array in the following format [0,0,0,0,0]. Set the threshold to 0 for each band (see below). This will set any pixels with negative values (less than 0) to 0. If you set parameters directly in the window, users will not be able to modify these settings.
  9. For now, set the Output Raster to Virtual Raster. This means that the task won’t permanently save the raster. We will change this later, but to test the model, we will create virtual rasters.
  10. What's a Virtual Raster?
    Some Task nodes create virtual rasters, where no output is written to disk. Virtual rasters provide an efficient way to pass the results of one raster to the input of another task. A virtual raster is a special type of raster whose pixel values are generated on demand during data processing or visualization. Virtual rasters save time and disk space by computing only the pixels you really need instead of the entire image. They can be used as input to other operations without any intermediate steps and without having to keep track of file references.

  11. Before moving on, we will validate the model to check for errors or missing connections. In the ENVI Modeler window select Code >Validate Model. The validation should return no errors, if not check your settings and connections and try again. Save your model.Validate
  12. While we could run the model now, we wouldn’t see any results because the results of the task aren't automatically added to the View or Data Manager. Use the Data Manager node whenever you create output that you want to add to the ENVI Data Manager and the View node to displays output from tasks in the current ENVI view. In the Basic Nodes menu find and add both the Data Manager and View nodes to the model.
  13. Connect both the Data Manager and View nodes to the output of the Low Clip node. This will send the result of the Low Clip task to the current view and add it to the Data Manager. Save your model.
  14. Validate your model again to make sure there are no errors or issues. Now click Run to start the model.
  15. An Input Parameters window will pop-up, this is where you will specify the raster to be clipped. Select the Landsat Surface Reflectance in the Data Selection window. Then click OK to run the model.
  16. After the model runs you will see the newly processed image in your viewer. Use the Quick Stats tool to confirm that the Low Clip task worked. There should no longer be any negative values, the minimum bands values should be 0 for all bands.
  17. Now that we have confirmed that our basic models works, we will add a nother task and a few more paramters. Return to ENVI Modeler window (Ctrl-M is a shortcut) and add the High Clip task to the model.
  18. Delete the exiting connection between the Input Parameters and the Low Clip task by highlighting the connecting and clicking the Delete button or righ-clicking and select Delete.
  19. Connect the High Clip node to the Input Parameters node. In the Connect Parameters window, click the Add New Inputs button under the Input Parameters and then click Input Raster (same as step xx). Click OK to update the connection setting.
  20. Now connect the output of the High Clip Node to the Low Clip node. The connection window won't open this time because there is only one output from the High Clip task (the clipped raster), so the connections will automatically be set.
  21. Click the Parameters Icon button in the High Clip node to open the task parameters. The Input Raster should now be linked to the Input Parameters [input_raster], but the upper threshold still needs to be set. Set the threshold to 1 for each band using the follow syntax, [1,1,1,1,1,1,1]. This will set any pixels with values greater than 1 to 1. Set the Output Raster to Virtual Raster and close the window.
  22. Validate your model to check for errors and save the model. Now the model should clip both the low (negative) and high values of the selected. Run the model and check the statistics of the resulting raster to confirm the model ran correctly.
  23. While to model should run correctly, it currently does not allow the user to permanently save the clipped raster or to specify the file name or location. We can add an input parameter to allow the user to specify where to save the resulting file.
  24. Connect the Input Parameters node to the Low Clip task node. In the Connection Parameters add a New Input that connects to the Output Raster URI button. This will create a user inpu field where users can specify how and where the output raster is saved. Click OK.
  25. Add Inputs to Nodes
  26. Now try running the model again, this time there will be an additioanl Input parameter . While the model works, we could improve the model by updating the labels and adding more informative help text, close the window.Input Window
  27. Click the Rename IconRename on the Input Parameters node. Update the name to something more descriptive, like High Low Clip Parameters. All nodes names can be updated to better describe the task.
  28. Now click on the settings buttonParameters Iconon the Input Parameters node. In the Input Parameters window you can change the order of the inputs, alter the text and add more descriptive instructions. Update the text to make it more descriptive.
  29. Save your model and now run it for the final time. This time save your out put raster in your lab folder.
  30. Download the Lab 2 data files from the shared Google Drive folder or the class share network drive (Z:). The data consists of two Landsat "tarball" files (.tar). Extract the two files into your original data folder, note that each of the files should be extracted into separate folders. When the process is finished you should have two folders that each contain Landsat data files, one is Level-1 data while the other is Level-2 data.. Open ENVI (ENVI 6.0).
  31. In ENVI go to File → Open and navigate to the location of the Lab 2 original data folder. Find the folder with the Level-1 Landsat 8 data (hint: look at the file name, level-1 data is designate with L1TP) and select the metadata text file (it will end in "_mtl.txt") and click open.
  32. First we will calibrate the Level-1 data so the pixel values represent real-world units, in this case percent reflectance. From the Toolbox, select Radiometric Correction → Radiometric Calibration or type “radiometric” in the toolbox and open the Radiometric Calibration tool.
  33. In the Radiometric Calibration window select the data (Input Raster) for calibration, for this exercise will be using the multi spectral data "....._MTL_MultiSpectral". Set the calibration type to "Top of the Atmosphere Reflectance". Leave the default scale factor and data type (1, Float, respectively). Save the calibrated image in your Working folder as "TOA_Reflectance.dat". When the process is complete the calibrated image should automatically open.Calibration

View Image Statistics

  1. Now we will calculate and view statistics for the image. Right click on the "TOA Reflectance" file in the Layer Manager and select "Quick Stats". A dialogue box will come up as ENVI calculates various statistics for the image. Once the calculations are complete the statistics view window will open.
  2. The basic stats include the minimum, maximum and mean pixel values for each of the bands. Scroll down to see more detailed distribution statistics for each of the bands. The values for reflectance data should range from ~0-1, representing 0 to 100% reflectance. Note that there may be values outside this range that you may want to investigate.
  3. For each band (seven in total) write down or copy/paste the minimum value, this is the lowest (non-zero) pixel value for that band. You can highlight the Band and associated Min value columns and copy them by selecting the Copy to Clipboard icon, then paste this information into a spreadsheet. We will use this information for our atmospheric correction process (note that values will differ from image below). Copy to Clipboard

Atmospheric Correction (Dark Subtraction)

We will use the Dark Subtraction Tool to estimate and remove the effects of atmospheric scattering from the image by subtracting pixel values that represents a background scattering from each band. We will be using the band minimum values we researched and wrote down in the previous steps.

  1. From the Toolbox, select Radiometric Correction → Dark Subtraction or type "Dark" in the Toolbox and open the Dark Subtraction Tool. The Dark Subtraction Input File window appears.
  2. In the Dark Subtraction Input File dialog select the file "TOA Reflectance" and click OK.
  3. The Dark Subtraction Values dialog appears, under Subtraction Method select "User Value". Click on each band (Bands 1-7) and enter in the minimum value you wrote down in the previous steps. Once you have entered in a value for Band 1, click on Band 2 and enter in the appropriate value. Do this for all seven bands. Note the image below is an example and that values will differ.
  4. Band Parameters
  5. Once you have entered in the values for all seven bands name your output file "surface_reflectance.dat" and save it in your Final Folder. Click OK to start the Dark Subtraction process, it may take a minute or two to complete the process. The image should automatically open in your viewer.

Masking with ROIs - Create a No Data Mask

Masks are used to exclude certain pixels from image processing or when computing image statistics. Masked pixels appear as transparent in the display. Masks can be created several different ways, using the FMask tool, ROIs or the Build Raster Mask Tool. The next steps will go over several methods.

  1. Notice that the outside "no data' areas of the Landsat images are no longer transparent after the dark subtraction process. We can apply a mask to properly exclude these values from display and analysis. Right-click on the Surface Reflectance file in the Layer Manager, and select New Region of Interest. Name the ROI no-data in the ROI tool window.
  2. In the ROI Tool, click the Threshold tab. Click the Add New Threshold Rule button Threshold button. In the File Selection dialog, select the first band associated with the Surface Reflectance file and click OK. A histogram of the band is displayed in the Choose Threshold Parameters dialog.
  3. Use the Min and Max values or the histogram to select all of the 'no data' areas outside the image. These values should be negative. Check the preview box to see the areas selected by the range of values. Click OK when the appropriate areas are selected. If you want to save the ROI for futures use (in another work session), select File > Save As and save the selected ROIs as an XML file that can be read by ENVI.
  4. We will now use the ROI to mask the image. To apply the mask we will use the Save As operation to create a new files with the no-data areas masked. In the Main toolbar, select File → Save As → Save As.. (ENVI). In the Data Selection Window select the "reflectance" as the Input File. Click the Mask button below. In the Mask Selection Window select the "no-data" ROI and check the inverse mask button, then click OK. Click OK in the Data Selection window to save the file. Note that the default is to mask the areas outside of the ROI, if you would like to mask the area selected by the ROI the inverse mask button should be checked.Mask with ROI
  5. Set the data ignore value to 0 and save the file as SR_masked.dat in your final folder. When the new image appears the "no data" areas should be hidden.

Compare the Data Processed Level-1 Data to the Level-2 Surface Reflectance Data

  1. For comparison open the Landsat Level-2 data by opening up the metadata file associated with the data (LC08_L2SP_....._MTL.txt). This file is the Landsat Level-2 Surface Reflectance data that has been calibrated used the NASA/USGS algorithm (see note below). We will use this data to compare it to our processed data, first visually compare the two Surface Reflectance images.
  2. Landsat 8-9 OLI Collection 2 Surface Reflectance data are generated using the Land Surface Reflectance Code (LaSRC) (version 1.5.0), which makes use of the coastal aerosol band to perform aerosol inversion tests, uses auxiliary climate data from MODIS or VIIRS , and a unique radiative transfer model. Learn more about the LaSRC (Land Surface Reflectance Code)

  3. View the Stats, look at the range of values.
  4. In the Layer Manager make sure your have the masked Surface Reflectance data selected. Click the Spectral Profile icon Spectral Profile Icon on the toolbar or select Display → Profiles → Spectral Spectral Profile Iconfrom the menu bar. This opens the Spectral Profile window. Move the cursor around to look at the spectral profiles (or reflectance curves) of different areas. The x-axis is the the wavelength and the y-axis displays the percent of light reflected (
  5. In the Spectral Profile window click Options → Additional Profiles → Add File and select the "TOA_Reflectance.dat" and click OK. Repeat this process to added the Level-2 Surface Reflectance data (LC08 ..L2SP (Surface Reflectance)). You should now see three spectral profiles in spectral profile plot.
  6. In the Options menu select Legend to add a legend to the graph. Explore the spectral profile of different pixel types (i.e. Water, Vegetation, Snow, Clouds etc) by moving the cursor around the display window. Make note of any differences between the spectral profiles of the three different processed images.
  7. Export at least three different land cover types for comparison (e.g. vegetation, water, clouds for example). Select "Export" → ASCII. This will save the data associated with the plot as a text file, the text file lists the actual pixel values (reflectance) for each of the bands, for all three images. Select "Export" → "Image" from the Spectral Profile menu bar to save a copy of the spectral profile graph. Save your spectral plot image and data in your Final folder as you will need this for your lab report, you should have three plot images and three data text files. You will need to use this data to to discuss the differences in the processing. See GSP 216 Lab 3 steps 26-34 for how to style spectral profiles and export text data into Excel.

Masking Specific Features

You can create a mask from a region of interest (ROI), from a shapefile, by creating binary rasters, or by using options available in the Build Raster Mask tool. In addition to excluding the no data areas, we also want to exclude water and cloud pixels from a vegetation analysis. There are many different ways to create clouds (and other feature) masks and the next section will cover a few techniques.

Fmask Algorithm Cloud Mask

  1. The Calculate Cloud Mask Using Fmask tool can be used to create a cloud mask for Landsat and Sentinel-2 data. We will test out the tool on out dataset. From the Toolbox, select Feature Extraction > Calculate Cloud Mask Using Fmask Algorithm.
  2. Click the Browse button next to the Input Rasters field. In the File Selection dialog, select all datasets that correspond to the Landsat Level-1 files and click OK in the File Selection dialog.
  3. Keep all of the default parameters. Select the working folder as the output file location and name your file Fmask.dat. Check the Display result option and click OK to run the process. fMask
  4. When processing is complete, the cloud mask is displayed and added to the Layer Manager. The cloud mask is a binary image where cloud (masked) pixels have values of 0 and non-cloud (non-masked) pixels have values of 1. Visually evaluate the effectiveness of the Fmask process by toggling the layers. Note what features are included in the mask and which are not.

View the Landsat QA Band and Create a Custom Mask

Landsat data products also include Quality Assessment (QA) bands to identify the pixels that exhibit adverse instrument, atmospheric, or surface conditions. This can include clouds, cloud shadows. This information can also be used to generate masks to exclude or isolate certain pixel types from analysis. There are several external tools available to extract information from the QA bands : https://www.usgs.gov/landsat-missions/landsat-level-1-quality-assessment-tools. Typically Level-1 data is used to generate mask, but Level-2 data can be used as well.

  1. Now we will open the Landsat QA band, select file open and in your Originals folder and select the file "LC08_L1TP_.....QA_PIXEL.tif" and click OK. This is the Landsat Quality Assessment band.
  2. Use the cursor value toolCursor to investigate what some of the pixel values are for various features (clouds water etc). You may want to open a new view or toggle between the Landsat surface reflectance layer and the QA band layer for comparison. Make note of some of the QA pixel values associate with clouds, shadows and other features that you might want to mask.
  3. Now we will create a ROI (Region of Interest) to use as out mask. Multiple ROIs can be employed to create a mask. Right click on the SR_Masked.dat file and select New Region of Interest. You can select specific features using several different methods. Use the threshold option to select certain pixel values in the ROI. Experiment using different bands and the QA bands to try and isolate certain features in the image. For example clouds tend to have relatively high reflectance across the spectrum while water and cloud shadows have low reflectance. Depending on the scene and masking requirements you may want to create multiple separate ROIs for different features. You can also create multiple threshold rules for an ROI.
  4. Using one of the above techniques create a mask that masks specific features, note that clouds should be masked in all masks. You will apply this mask when calculating a spectral index of your choice in the next step. Some possibilities for masking are:
    1. Mask all non-vegetated areas - ideal for using with spectral vegetation indices like NDVI, NBR etc
    2. Mask all non-water area - ideal for studying water
    3. Mask all non-snow areas - ideal for studying snow reflectance
  5. Now we will build the raster mask. From the Toolbox, select Raster Management > Build Raster Mask. The Build Mask Input File dialog appears.

  6. Select the input file of SR_masked.dat and click OK. The Mask Definition dialog appears. From the Mask Definition dialog menu bar, select Options, here you can choose to add specific values to mask or ROIs to include in the mask. Under options select the import ROIs option and add the ROI(s) you created in the previous step. If the input file has a data ignore values (no data values), then the dialog opens with these values automatically entered in these fields.Mask Definition
  7. Under Options change the mask option to "Selected Areas Off". This will produce a mask where the selected ROI(s) and no data values are masked or "off". Save the file as mymask.dat in the working folder and click OK. Compare the Fmask and your mask results.

Calculate Spectral Index and Apply Mask

ENVI can calculate a variety of different spectral indices.

  1. From the Toolbox, select Band Algebra → Spectral Indices or type "Spectral Indices" in the Toolbox and open the Spectral Index tool. The Spectral Indices dialog appears. Select the SR_Masked.dat as your Input Data and click Mask button.
  2. In the Mask selection window select the preferred mask from previous steps (either the Fmask or the custom mymask that you created) and click OK.
  3. Now we will select the desired Spectral Index from the Spectral Index list. Select a spectral index designed to measure vegetation: Name your output raster appropriately and save it in the finals folder as a .dat file. Click OK and by default the spectral index image should appear in the viewer.

Visualize the Spectral Index

 

  1. Right click on the "spectral index" layer in the Layer Manager and select "Change Color Table" and select one of the color tables. Applying a Color Table makes it easier to see the differences in spectral indices (or any index) values.
  2. Another way to display and investigate data values is using the Raster Color Slice tool. Right click on the layer and select New Raster Color Slice. Select the desired layer to create a raster color slice of.
  3. Use the Chip to View option or Snipping Tool to capture an image for export of either the index layer with the color table applied or the raster color slice. A simple legend or color bar can be added to the screen under the annotations option.

 

Turn In - Summary Report

A Word document with:





Contact Info

Humboldt State University
1 Harpst Street Arcata, CA 95521
skh28@humboldt.edu

© Copyright 2020 HSU - All rights reserved.