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 reviewing image statistics and histograms, comparing data and calculating spectral indices.
Learning Outcomes
- Perform Radiometric Calibration in ENVI
- Conducting atmospheric correction (dark object subtraction)
- Evaluating Image Statistics
- Creating and Applying Masks
- Comparing and extracting data
- Visualizing Data
About the Data
The primary data is this lab is Landsat Collection 2 Level-1.
The specific data used in the lab is a Landsat 8 mages of northern California acquired August 6th 2022.
Accessing and Calibrating Landsat Data in ENVI
You will begin by creating a folder structure or "workspace" that will keep your files organized and prevent any confusion as you work with multiple datasets in the future. It is important to have the files you are working with on a local drive (C: in our case). Many processes in ENVI and ArcGIS do not work well or at all when data is stored in the cloud (i.e. Google Drive G: Drive) or on portable storage devices.
- Create a new folder on the desktop or documents for your lab data (recommend naming convention of the folder “GSP326_Lab_#”). Create three subfolders, original files, working and final.
When you are done, you will want to back up your final work onto a USB drive, or cloud based storage like Google Drive or Dropbox. The hard drives (including the desktop) on the lab computers will be deleted every 24 hours. Be sure to always save and backup your work!
- Open up your favorite web browser, log into myHumboldt and navigate to your Humboldt Google Drive, under "Shared with Me" you should be able to see a folder for GSP 326 Intermediate Remote Sensing, there is also a link to the Google Drive folder on the Canvas home page under Resources. All of the lab data can be found in the Lab Data folder. In the Lab Data folder navigate to the Lab 2 Data folder and download the Landsat "tarball" files (.tar).
- Use 7-Zip to extract the two Landsat files into your original data folder. Note that each of the files should be extracted into separate folders. When the processed is finished you should have two folders that each contain multiple TIF files and metadata files. Open ENVI (ENVI 5.6.2). This will open the ENVI software package.
- In ENVI go to File → Open and navigate to the location of the Lab 2 original data folder. Find the folder with the 2022 Landsat 8 data and select the metadata text file (it will end in "_mtl.txt") and click open.
- First we will calibrate the 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.
- In the Radiometric Calibration window we need to select the data for calibration, select the Landsat 8 multispectral image, it will end in "....._MTL_MultiSpectral" and click OK. This will radiometrically calibrate the seven reflective, multispectral bands of the Landsat 8 data.
- In the next window select "Reflectance" as the calibration type and keep the other defaults.. Save the calibrated image in your Working folder as "TOA_Reflectance.dat". TOA stands for Top of the Atmosphere, as this is the reflectance measured at the top of the atmosphere at the sensor (which includes the effects of atmospheric scattering). When the process is complete the calibrated image should automatically open.
View Image Statistics and Histograms
- Now we will calculate and view statistics for the image. Right click on the "TOA_Reflectance.dat" 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.
- 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.
- 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).

- Now we will view the histograms for all of the bands. In the upper left hand corner click "Select Plot"
and select "All Histograms". You should now see the histograms from all seven bands in the plot viewer. Select Options → Legend, this adds a legend for the seven different bands displayed on the histogram plot. The Y-axis is a count (the frequency or number of pixels with that particular value) and the X-axis displays the reflectance values. For example, if there is a large peak on the left hand side, that indicates that there are a lot of pixels with low reflectance values in that band of the image. Make note of the shape and distributions of the histograms. If you like, you can save the histogram by selecting Export → Image. Close the Statistics Window.
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.
- 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.
- In the Dark Subtraction Input File dialog select the file "TOA_Reflectance.dat" and click OK.
- 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 Step 12. 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.
- 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
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 diferent ways, using ROIs or the Build Raster Mask Tool. The next steps will go over both methods.
- 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 exlude these values. 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.
- In the ROI Tool, click the Threshold tab. Click the Add New Threshold Rule button
. In the File Selection dialog, select the Blue band associated with the Surface Reflectance file and click OK. A histogram of the band is displayed in the Choose Threshold Parameters dialog.
- 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.

- We will now use the ROI to mask the image. In the Main toolbar, select File → Save As → Save As.. (ENVI). In the Data Selection Window select the "surface_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.
- Set the data ignore value to 0 and save the file as SR_masked.dat in your final folder. Now the no data regions are no longer visible.
Compare the Data
- For comparison open the file L2_Surface_Reflectance.dat. This file is the Landsat Level-2 Surface Reflectance data that has been calibrated used the NASA/USGS algorithm. We will compare it to our processed data.
- In the Layer Manager make sure your have the masked Surface Reflectance data selected. Click the Spectral Profile icon
on the toolbar or select Display → Profiles → Spectral
from the menu bar. This opens the Spectral Profile window.
- 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 masked Surface Reflectance data. You should now see three spectral profiles in spectral profile plot.
- 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, Urban) by moving the cursor around the display window. Make note of any differences between the spectral profiles of the three different processed images.
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 masks and the next section will cover several.
Fmask Algorithm Cloud Mask
- 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.
- Click the Browse button next to the Input Rasters field.
- the File Selection dialog, select all datasets that correspond to the Landsat Level-1 files and click OK in the File Selection dialog.
- 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.
- 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 effectivness of the Fmask process.
View the Landsat QA Band
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.
- Now we will open the Landsat QA band, select file open and in your Originals folder and select the file "LC08_L1TP_....._pixel_qa.tif" and click OK. This is the Landsat Quality Assessment band.
- Use the cursor value tool 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 layers.
- Multiple ROIs can also be used to create a mask. Right click on the SR_Masked.dat file and select New Region of Interest. Experiement using different bands and the QA bands lds 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.
-
You can also use the following steps for the Build Raster Mask tool to create a binary raster from specific pixel values or ranges of pixel values or by selecting ROIs to create the mask. From the Toolbox, select Raster Management > Build Raster Mask. The Build Mask Input File dialog appears.
- 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. If the input file has a data ignore value, then the dialog opens with the values automatically entered in these fields.
- Add all of the selected attributes for the mask and same the files as mymask.dat in the working folder and click OK.
- Compare the Fmask and your mask results. Select the mask that best masks non-vegetation features for the next steps.
Calculate NDVI and Apply Mask
Metadata provide details about a dataset in general such as its source, data type, and projection. In ENVI the metadata is stored in the header file (.hdr). The metadata can be edited in the program or the header file can be edited using a text editing program like notepad.
- 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.
- In the Mask selection window select the mask from step 32 (either the Fmask or mymask that you created) and click OK.
- Now we will select the desired Spectral Index from the Spectral Index list: Normalized Difference Vegetation Index (NDVI). Name your output raster "NDVI.dat" and save it in the finals folder. Click OK and by default the NDVI image should appear in the viewer.
Review the NDVI Statistics and Histogram for the Image
Changing Band Combinations
- Right click on one of the files in the Layer Manager and select "Change RGB Bands". The "Change Bands" dialogue should now be open, here you can select what bands will be displayed in the three primary colors on the screen, in the order of Red, Green, Blue. Click the box on next to “NIR”, it should turn red after it has been selected. Next click the box next to “Red” and it should turn green and lastly click the box next to “Green” which will turn blue. Click "OK" and now you should see a NIR false color composite in your view.
- Try a few different false color composites with the different images. For a review and some common band combinations see this Natural and False Color Composites review lesson.
Select what ever composite you would like to move forward with or stick with a true color composite. You can always change this at any time.
Image Enhancement Controls
Enhancement tools interactively control the amount of brightness, contrast, stretch, and transparency for the selected image layer. For each tool you can click and drag the slider, or enter a value in the adjacent field. You can control the Brightness, Contrast, Sharpness and Transparency. You can also apply different stretch types to enhance the appearance of an image.
- Explore the Brightness, Contrast, Sharpness and Transparency image enhancements controls for the images. Setting can be reset to the defaults by clicking the
reset icon.
- Locate Contrast Stretch drop-down in the main toolbar and try all of the different contrast stretches. If you are unhappy with the contrast stretch you can always click the "Reset Stretch Type" icon
to restore the contrast to the default setting. The Custom Contrast Stretch
also allows you to apply custom contrast stretches using the histograms as a guide. This tool allows the
user to set the minimum and maximum value for each color channel (Red, Green, Blue) that the contrast stretch is applied. Experiment with the different contrast stretch types and select one (either custom or pre-set). Do this for both of the images.
Measure Lake Levels
If an image is georeferenced to a standard map projection, you can measure the distance between objects using the Mensuration tool.
- Use the "Go To" tool in the main toolbar to jump to a specific location in an image and to center the current image window view over that location. Enter the following coordinates in the Go To field,: 36.028622, -114.773579 and press enter. These coordinates are the rough location of the Hemenway Harbor Launch Ramp near the Hoover Dam.
- Adjust the transparency of the top layer so the difference in lake levels between the two images is visible.
- Click the Mensuration button
in the toolbar. Red crosshairs appear in the display, and the Cursor Value dialog appears. Click on the lower lake level first to start the measurement and drop a second point at the higher, historic lake level. Right click and select accept.
- The measurement will show up as an Annotation. You can see the measurement value in the Cursor Value menu and you can change the measurement units as you see fit. Write down or copy the measured valued. Close the cursor value window when you are done. You can uncheck the annotation or remove it in the Layer Manager if you would like.
Create ROIs and Calculate Area
Regions of Interest (ROIs) allow you to select specific areas of rasters. The ROIs can be saved and used for a variety of purposes, including calculating statistics, area and subsetting images. ROIs can be created from geometry or by pixels. ROIs are vector files, which are coordinate-based data models that represent geographic features as points, lines, and polygons. While ROIs are an ENVI data type, they can also be exported as Shapefiles.
- Right-click on one of the files in the Layer Manager, and select New Region of Interest. Name the ROI Lake_Mead_Year.
- We will use the Magic Wand tool to grow ROI polygons from one or more "seed" pixels. This tool facilitates drawing ROI polygons around complex objects such as clouds, tree crowns, and lakes. With the Region of Interest (ROI) Tool displayed, hold down the Ctrl key and click on a pixel inside of Lake Mead. An initial polygon is drawn, and the Magic Wand Parameters dialog appears. You can adjust the threshold and experiment with other parameters to better refine the shape of the object.
- Once you are happy with your ROI selection (aim to select the entire lake but no other features), right click and select "Accept Multipart". Click the area icon in the lower half of the ROI window and record the area in either acres or hectares.
- Repeat the process for the other year's image to delineate and calculate the area of the lake.
Export Images
- We will now learn to use the "Chip to View" option in ENVI to save the current view as an image. This option is very similar to taking a screenshot. Focus one of the views on Lake Mead area.
Include the ROIs showing the lake extent. You may adjust the color and transparency of the ROIs and image layers as you see fit. Go to File > Chip View To >File in ENVI. Select "JPEG" as the output file type and uncheck "Display Results."
Save the jpeg in your Lab 1 folder. File names should not include spaces or special characters, I recommend including either the location or description as well as a date in the name.
- Repeat the process for the other image, keep the extent and zoom level the same as the other image. The views will export exactly how they look on the screen in terms of zoom and size. For other export options see Saving and Export in Files in ENVI. Close ENVI when you are happy with your exported images.
- Back up your Finals folder. I recommend zipping the folder and then transferring to Google Drive or a USB storage device.
Turn In
(1) A Word document with:
- Table(s) showing the spectral/spatial resolution, date, sensor and projection/coordinate system of each of the images.
- Figures (2) showing Lake Mead with ROIs displaying lake extent for 1999 and 2022.
- The area in acres or hectares of the lake in 1999 and 2022
- The linear distance the lake has receded at the Hemenway Harbor Launch Ramp
(2) Submit your two edited ENVI header files (.hdr)