Lab 4: Pixel Based Image Classification
Introduction
There are two main procedures 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
- Learn how to conduct an unsupervised classification procedure in ENVI
- Learn how to collect training data
- Conduct a supervised classification procedure in ENVI
- Analyze classification results, including labeling and color coding classes
- Analyze statistics related to classes
About the Data
The primary data in this lab is Sentinel-2 Level2A data. This is data has been processed to bottom of the atmosphere (BOA) reflectance, (or surface reflectance). The specific image used in this lab was acquired June 6th, 2022 over Hokkaido, Japan. Data should be stacked and masked (for clouds/clouds shadows) 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.
- 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 Sentinel-2 stack and mask that were created in the previous lab to your originals folder.
- Start ENVI (ENVI 5.6.2) and open the Sentinel-2 stack and mask files.
- We will start with Unsupevised Classification. Select the K-Mean Classification tool in the toolbox under Unsupervised Classification.
- In the Classification Input Window select the Sentinel-2 stack as the input file and select the cloud mask under the select mask band.
- 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.

- 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.
- 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.
- Select the Sentinel-2 stack as the Input Raster and set the mask to be the cloud mask. Click OK.
- 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
- Visually inspect the two classification results and compare them to each other and to the satellite imagery. Make note of similarities and differences.
- We can also examine the statistics for the classes for each of the classifications. Under the Post Classification heading select Class Statistics.
- In the Classification Input File Window select the k-means classification file and click OK.
- In the Statistics Input File select the Sentinel-2 stack. In the Class Selection window select Classes 1-10. This will compute the statistics for each band for every class.
- 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.
- 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.
- 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.
- Select with 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.
- 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.
- 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.
- Right click on the classification file and select Edit Class Names and Colors.
- 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").
- Select the drop down Color, and select an appropriate color for the class. I suggest using an intuitive color (i.e. blue for water).
- 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.
- Use the Combine Classes tool (Classification → Post Classification →Combine Classes) to group two or more classes together.
- 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.
- 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.
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.
- Based on the results of the unsupervised classification, identify 5-7 classes to collect training data for. Right click on the Sentinel-2 stack 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 should have multiple polygons to collect training data.
- In the ROI Tool window change the ROI Name from the default to "Water" and change the color as appropriate. The color selected will be the color assigned to this class once the classification process is complete.
- Training classes are selected by creating selecting several representative polygons or sample areas for each class. Locate a region that is water in the image. Draw a polygon to select the area as a training area that represent water. Repeat this process, creating a total a minimum of five polygons that represent water. Try to sample areas that are in different regions of the image to capture a range of water types.
- 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 (use the same classes you identified in the unsupervised classification). You may want to research the area, use the reference map and/or other maps like Google Maps to help identify appropriate training data.
- 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 file in the Final folder.
- 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.

- Make sure you have the Sentinel-2 stack selected in the layer manager then click the Scatter Plot Tool icon from the main toolbar.
- 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.
- From the Toolbox, select Classification → Classification Workflow. The File Selection panel appears. Click Browse. The File Selection dialog appears. Select the Sentinel-2 image and click OK. In the second tab select the mask layer you created in the previous lab.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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".
- Click "Finish" to complete the classification and save the classification files.
- 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.
Select the classification results that you think are best and use this data to create a land cover map (final step).
Create a Map Showing the Classification Results
- Use ArcMap or ArcGIS Pro (or QGIS!) to create a map showing the results of the preferred classification. Include a legend, north arrow and scale bar.
Turn In - Worksheet and Text file
Upload to Canvas
- Completed Lab 4 Questions (see Canvas)
- Land Cover Map
- Classified Image (your choice unsupervised/supervised)
- Legend
- North arrow
- Scale Bar
- Title