Masthead

Lab 4: Pixel Based Image Classification

Introduction

There are two main workflows used to classify pixels using a computer: unsupervised and supervised classification. Unsupervised classification is essentially computer automated. It allows you to specify parameters that the computer will use to automatically cluster or group the data. Supervised classification uses the spectral signatures obtained from training samples to classify an image. Training samples are used to collect spectral signatures from representative areas of land cover that the user designates as a certain class (e.g. water or agricultural). The computer uses the user’s specified signatures to classify all of the pixels in a scene. In this lab we will evaluate various pixel based classification technique to classify a multiband Sentinel-2 image. More information about ENVI's Classification Tools

Learning Outcomes

About the Data
The primary data in this lab is Sentinel-2 Level2A data. This is data has been processed to surface reflectance. The data used in this lab is imagery of Sonoma County captured in June 2024.. Data should be stacked, mosaiced and masked created prior to conducting the classification exercise (see Lab 3).

Unsupervised Classification in ENVI

Unsupervised classification can be ran through the Classification Workflow or by selecting either K-Means or IsoData classification under the Unsupervised Classifications tools. The unsupervised classification algorithm in the Classification Workflow is IsoData. The workflow also includes optional clean-up filtering to smoothing and aggregation.

  1. Create a new folder on the desktop or documents for your lab data (recommend naming convention of the folder “GSP326_Lab_#”). Create three subfolders, for original files, working files and final processed files. Transfer the masked (to Sonoma County) Sentinel-2 mosiac that was created in the previous lab to your originals folder.
  2. Start ENVI and open the Sentinel-2 mosaic from the previous lab exercise.
  3. We will start with Unsupervised Classification. Select the K-Mean Classification tool in the toolbox under Unsupervised Classification.
  4. In the Classification Input Window select the Sentinel-2 stack as the input file. After selecting the file you can choose to classify a subset of the data or apply a mask. For this exercise we want to mask the Data Ignore values (no-data regions of the image). This can be done by selecting a pre-made no-data mask or by having ENVI create on as part of the classification procedure. Click on the Mask Option button and select Mask Data Ignore Vales [All Bands]. This will build a no data raster mask that will be applied to the data prior to classification.Build Mask
  5. In the next window you can specify the K-means parameters. For this exercise set the number of classes to 10, the change threshold to 5% and the maximum iterations to 10. Save the file as "kmeans.dat" in your working folder.k-means
  6. The K-means classifier will start, it may take awhile to run through the iterations of the algorithm. The classification results will appear when complete.
  7. Now we will repeat the unsupervised classification process but this time with the Isodata algorithm. Select the IsoData Classification tool in the toolbox under Unsupervised Classification.
  8. Select the Sentinel-2 stack as the Input Raster and set the mask to be the data ignore mask that was created in the previous step. Click OK.
  9. Use the same number of classes, change threshold percent and iterations as the K-means (step 5) and save the output raster as isodata.dat in your working folder.

View Image Classification Statistics and Histograms

  1. Visually inspect the two classification results and compare them to each other and to the satellite imagery. Make note of similarities and differences between the classifications.
  2. We can also examine the statistics for the classes for each of the classifications. In the toolbox under the Post Classification heading select Class Statistics.
  3. In the Classification Input File Window select the k-means classification file and click OK.
  4. In the Statistics Input File select the Sentinel-2 mosaic. In the Class Selection window select Classes 1-10. This will compute the statistics from the Sentinel-2 data for each of the classes.
  5. In the parameters windows select Basic Stats, Histograms, Covariance. Check the boxes to Output the data to the screen as well to text file (.txt) in your finals folder (Saving the Statistics (.sta) is optional). Click OK to run the statistics.
  6. The statistics window will show general class summary, including the pixel count for each of the classes. You can also view the spectral data, including the mean and standard deviation for each of the classes. This will give you an idea of the spectral profile and data ranges for each class. It will also provide some information on the variability of each class.
  7. Repeat the process for the IsoData classification file (steps12-16). You may want to save some screenshots of the charts for reference.

Interpreting, Labeling and Changing Colors of Classes

After performing an unsupervised classification you need to interpret your results. This includes determining the associated land cover type of each class, labeling the classes and changing the color on the classes. You will want to combine some of your classes, aim to have 5-7 general land cover classes, for example: Developed, Forest, Agriculture, Bare Ground and Water.

  1. Select the IsoData or K-Means image to work from, whichever you think best classified the data. Remove the classification other from your viewer to make the next steps easier. In the Layer Manager you will see each of the classes listed separately under the classification files. Right click on "Classes" and select " Hide All Classes" and then click on the image in the viewer. All of the classes are now no longer visible. We will now turn on the classes one at a time.
  2. In the Layer Manager click the box next to Class 1 to turn it back on. Compare the class to the satellite image to determine the land cover type. You can either turn the class on and off in the Layer Manager or use Blend, Flicker or Swipe tools to compare the class to the satellite image. You also might want to turn on the Reference Map Link to view higher resolution imagery of the area and/or Google Maps or other online resources.
  3. Continue this process for the remaining classes. I suggest viewing one class at a time as it is easy to visually compare. Write down the class number and corresponding land cover type for all classes. We will update the names and colors in the next steps. If some classes are similar, you may want to label as "Forest1", "Forest2" for example and combine these classes in the next step. Note that the class names must be unique (i.e. two classes can't be named "forest"). Label the classes to the best of your ability.
  4. Right click on the classification file and select Edit Class Names and Colors.
  5. The Class Name and Color Editing window is now open. Here you can change the names and colors associate with each class. Start with Class 1 by clicking on "Class 1" in the list. Under Class Name update the name to the land cover type (for example "Water" or "Developed").
  6. Select the drop down Color, and select an appropriate color for the class. I suggest using an intuitive color (i.e. blue for water).
  7. Repeat this for all classes (you can leave unclassified and masked pixels as-is). Once you are done click OK. The classes should now be renamed and have new colors.
  8. Use the Combine Classes tool (Classification → Post Classification →Combine Classes) to group two or more classes together.
  9. Select the classified image to combine classes. In the next window select a class you want to combine from the Input Classes list. The selected class name appears in the Input Class field. Select an output class by clicking on a class name in the Output Classes list. When both the input and output classes are selected, click Add Combination to finalize the selection. The new, combined class to create is shown in the Combined Classes list at the bottom of the dialog. To deselect combined classes, select the name in the Combined Classes list. You can combine multiple classes this way. Click OK when done.
  10. The Combine Classes Output dialog appears. Change the Remove Empty Classes to Yes and save the cleaned-up classification output file in your finals folder.

Create Mask for Vegetation

For the supervised classification in the next step we aim to perform a vegetation classification. To improve the classification, we will mask all areas that aren't vegetated by creating a vegetation mask,

  1. Create a mask that masks all non-vegetated areas in the image and the areas outside of Sonoma County. Use any technique that you like to accomplish this. First identify the vegetated/non-vegetated areas using either the Sentinel-2 provided scene classification images (provided with the original data), relfectance values or spectral index like NDVI.
  2. Use the Build Raster Mask Tool to create a mask that masks both: non-vegetated areas and areas outside of Sonoma County (data ignore areas). Build and save your mask in your working folder.

Collect Training Data and Run Supervised Classification

Supervised classification clusters pixels in a dataset into classes based on user-defined training data. The training data can come from an imported ROI file, or from regions you create on the image. The training data must be defined before you can continue in the supervised classification workflow. In this lab we will define out training data first and then import the training data ROIs into the classification workflow. We will use the satellite imagery to visual identify appropriate training areas. You may also want to research more about the region and use online resources to help you with your classification.

In this exercise we will apply one of the masks created in the previous exercise to limit our classification to either hydrologic features or vegetation. Choose which

  1. Based on the results of the unsupervised classification, identify 5-7 classes to collect training data for vegetation types. Right click on the Sentinel-2 mosaic file and select New Region of Interest. We will create a separate ROI for each of the classes we want in our classification. Each ROI will have multiple polygons to collect training data. Use a combination of the reference map, Google Earth and other online resources to help you collect approriate training data.
  2. In the ROI Tool window change the ROI Name from the default to your first class name (e.g. "Deciduous Forest," "Agriculture') and change the color as appropriate. The color selected will be the color assigned to this class once the classification process is complete. Creating a minimum of five polygons that represent each class. Try to sample areas that are in different regions of the image to capture a range of the cover types.
  3. Click the New ROI icon in the ROI Tool Window. This will be the ROI for the seconds class. Repeat steps for the next class.
  4. Repeat steps above to create ROIs and collect training data for all of the classes. You should have between ~5-7 classes total. Once all of the training data has been collected, in the ROI Tool window select File →Save As. Select the all of the training data ROIs and save the training data file in the Final folder. This will allow you to re-use and edit your training data.
  5. In the Layer Manager right click where it says Regions of Interest and select Statistics for all ROIs. Take a look at the average spectral profiles and standard deviation for the various training data ROIs. This is one way to asses your training data before classification. Close the window when you are done.You may want to collect additional training data or change your classes based on the statistics.
  6. Make sure you have the Sentinel-2 mosaic selected in the layer manager then click the Scatter Plot Tool icon from the main toolbar.
  7. In the scatterplot window select File > Import ROIs. Select the desired ROIs and click OK. You can change the bands plot and ROI classes that you want to look at. Explore some of the class data, scatterplots and associated image data. Close the window when you are done.
  8. Scatter plot
  9. From the Toolbox, select Classification → Classification Workflow. The File Selection panel appears. Click Browse. The File Selection dialog appears. Select the Sentinel-2 image as the Input Raster. In the second tab select the appropriate mask layer (for vegetation) you previously created.Workflow
  10. Click Next in the File Selection dialog. The Classification Type panel appears. Select "Use Training Data" and click Next. This will start the Supervised Classification workflow. If prompted for ROI visualization layer, select the masked file. This will only show the Sentinel-2 areas within the mask.
  11. The Define Training Data will open. All of the ROIs should be listed in the Training Data window. Remove any unwanted ROIs by clicking the red "X". If the training data ROIs don't automatically populate, you can click the "Load Training Data Set" folder icon and find the training data file. ENVI can import training data stored as either XML files or Shapefiles.
  12. Next you will preview the classification results, based on the training data you provided. Enable the Preview option to open a Preview Window that shows the classification result using the training data that you created. If ENVI crashes at this point you will have to restart the classification workflow. As long as the training sites have been saved you can simply import the existing sites by clicking the "Open" icon in the training sites window.
  13. In the same window click on the algorithm tab. With the preview enabled change the algorithm. There are four supervised classification algorithms to select. Try all of them with the default settings and select one for the classification. Click Next.
  14. When supervised classification is complete, the classified image loads in the Image window, and the Cleanup panel appears. In the Cleanup panel, keep the default settings. Click Next.
  15. The Export window is now open. Uncheck the "Export Classification Vector" box but keep the "Export Classification Image" box checked. Under "Export Classification Image" save the file in your "Final" folder as "supervised.dat".
  16. Click "Finish" to complete the classification and save the classification files.
  17. The supervised classified image should now be in your viewer. Visually compare the supervised and unsupervised classification by turning the layers on/off or using the Blend, Flicker and Swipe tools. Make sure all of your data is saved before moving on to the final step.

Create a Map Showing the Classification Results

  1. Use ArcGIS Pro (or QGIS!) to create a two maps: 1) showing the results of the preferred unsupervised classification (all cover classes) and 2) The results of the supervised classification showing either vegetation features or hydrologic features. Include a legend, north arrow and scale bar.

Turn In - Worksheet and Text file

Upload to Canvas





Contact Info

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

© Copyright 2020 HSU - All rights reserved.