Você está na página 1de 9

Principal Component Analysis (PCA) using ILWIS open source software

Posted by F on July 13, 2012

Bismillah, Today we will learn how to employ PCA in ILWIS opensource software environment, OK lets begin: 1. Our study area is around Kurdistan, Iran. We will use Landsat 5TM image from USGS, the acquisition date is July 5th, 2011. Firstly, open your ILWIS software and import all your tiff images into ILWIS format using the following algorithm:

import tiff file 2. Double click Principal Components in the Operation-List window (left side), the following window will appear, if you dont have MapList, create MapList first with click the yellow button, and input from band B1-B5 and B7

PCA window and create MapList 3. The following window (Principal Component Coefficients) will appear when you click Show.

4. Write down in your paper the eigenvalues from b1-b7 (right window), and calculate the PC1-PC3 using the algorithm in the left window The first two or three components will carry most of the real information of the original data set, while the later components describe only the minor variations (sometimes only noise). Therefore, only by keeping the first few components most of the information is kept. These components can be used to generate an RGB color composite, in which component 1 is displayed in red and component 2 and 3 in green and blue respectively. Such an image contains more information than any combination of the three original spectral bands. Through this type of image transformation the relationship with raw image data is lost. The basis is the covariance matrix from which the eigenvectors and eigenvalues are mathematically derived. It should be noted that the covariance values computed are strongly depending on the actual data set or subset used, therefore the atmospheric correction is mandatory for images with too much noise. 5. Create a color composite of the PC1 (Red), PC2 (Green), PC3 (Blue)

PCA color composite 6. Filter your PC-RGB data using Majority model to reduce spatial frequency of your data

Right click on your PCA-RGB data and choose Image Processing-Filter, then choose Majority 7. Create; a. RGB from the original spectral bands (742 band false color); b. 432 false color. Just double click Color Composite in the Operation List window on the left side of the software, and input your data. 8. Compare the result with composite of the PC1 (Red), PC2 (Green), PC3 (Blue)

Compare these three color composite maps.

fatwa@zasuko.com

Unsupervised Classfication using ER Mapper


If you haven't copied any datasets you plan to use to your Q folder, do that now because you'll be re-writing the header files. Because it is a smaller dataset, you might want to copy the small_VA_TM.ersdataset for this exercise.

Getting Ready
Open a new RGB algorithm. When it asks for the dataset, find the piece of the dataset newly copied to your own directory. Adjust the transform by clicking on the "GO with 99% clip on limits" button and then save it as an algorithm (e.g., small_Va_RGB321.alg) in your home directory. Then you must calculate the statistics that cover the seven bands in this region (min, max, mean, variance, etc) These are used by the classification process. From the Proces Menu choose Calculate Statistics, select your small_Va.ers dataset, choose a resampling of 1 and click the "force recalculation button" on black). Click ok. When it's done, close the box by clicking cancel (you may get an error message).

Classification:
From the Process Menu, Click on "classfication" and choose "ISOCLASS Unsupervised Classfication" You will be presented with a box in which to make 6 changes 1. Input Dataset: Open the samll_Va_TM.ers in your directory 2. Bands to use: It says all, but we don't want band six. Click on the folder next to the band box a list of the possible bands comes up. To get rid of band six click and drag through all seven bands to select them and then hold the control key down and click on band six to de-select it. Then click ok. The box should now read 1-5,7. 3. Ouput Dataset: Give it a descriptive name like "sm_Va_isoclass_10.ers" (for 10 classes). 4. Max Number of Classes: You want a maximum of 10 classes for this exercise (normally you don't want to constrain this) 5. Minimum members in class (%): You normally don't want very narrowly defined classes, choose 1%. 6. Desired percent unchanged: choose 90% Click ok. Watch the process to see what's happening.

Display your classification. 1. Open a new pseudocolor algorithm. 2. Change the layer type to Classification Display (in the middle of the layer stack). 3. Add your newly created dataset and click GO. NOTE ! it doesn't make any sense to use a 99% click on classified data...right? Don't use that button. 4. From the Edit menu, select Edit Class/Region Color and Name 5. Choose the colors that you want to have displayed for each of these regions. 6. If you want to know where you are, display band 5 from the small_Va.ers dataset on top of the classification layer (chooose Add and put in a new Pseudocolor layer) and then find out what's underneath by showing the pixel values. Right click on the image or from the View menu choose the Cell Value option (near the bottom). You can also use the transparency change technique.

Return to the Tutorial Page

Supervised Classification in ER Mapper


Make sure that you copy any dataset that you're going to classify tto your own directory before you begin this process. The reason for doing this is that when you complete this process you change the "header" file (the .ers file) by writing the training region data to it. Copy both the dataset (big file, no .xxx at the end of the name) and the header (.ers file) that share the same name. Here are the steps for classification using the raw TM data bands. 1. Start ER Mapper and open a new RGB algorithm. Load your copy of the Small_Va_TM dataset (or any other dataset), make it RGB321 and save it as an algorithm named small_Va_RGB321.alg in your home directory under /dataset. 2. All classification depends on the distribution of the cell data so you must first calculate the statistics. To do this, choose Calculate Statisitcs from the Process Menu. When you get the options box, set the resampling to 1, and click the "force recalculation" button. Then click ok and wait. 3. Getting ready to draw the training regions. What you're doing first is making a new annotation layer that shows vector outlines of features of your

choosing. This vector outline is used to make a new set of rasterized regions that define the cells of your training region. This is a several step process a. From the Edit Menu choose the Edit/ Create Regions option. b. Two boxes will come open. One is for the page setup, click on the page setup button and when the page setup box comes open, choose Auto Vary: Borders from the Constraints menu c. Click ok when you're done and you should see the second box that idenitifies a new raster region annotation layer. Click ok and you will get a new toolbar and a new layer in your algorithm. d. Save As...this algorithm using the main ER Mapper menu (not the new tools menu) using a name such as "small_Va_RGB321_with_landuse" 4. Drawing the training regions a. Open the Geoposition tool under the View menu. b. Using the zoom and pan buttons, zoom in on BV. c. From the tools menu, choose the polygon tool it looks like this.

d. Outline the residential part of BV and double-click on the last point to close the area.

e. Double-click on the polygon tool and an options box will come open. Use it to set color.. of the line (and enclosed region). From the View menu of this set color box you can choose the "named colors" option, it's easier to use. Click ok when you've got a color you like. f. Now click on the text/attribute button (this one)

and give this region a name. If you want to outline other areas of the same type, just outline them later and use the same name. g. From the tools palette choose the save as... button. Make sure that it is saving the information to the small_Va_TM dataset. This will add the region definition information. I recommend that you click on the save button of the tools menu after working with each region outline. h. Zoom out using the All datasets button on the geoposition menu box and then zoom in on a area of pasture.

Repeat 4.a to 4.7, then zoom out again. Find the lynchburg reservoir.... etc. 5. Evaluating your training regions a. Make usre that you have both saved the region annotation to your small_Va.ers dataset (using the tools palette) and save the algorithm using the main ER Mapper save button. To either view the raw statistics or the histograms, I refer you to the tutorial manuals. The following instructions apply only to the scattergram method. b. From the View Menu, choose the scattergram option. It may ask you to confirm some setup information. click ok. You should see a density plot of band 1 vs band 2 data. To see how good your training regions are, open the setup box and click on the "show means and 95 confidence intervals near the bottom AND open the dataset "small_Va.ers" with the open dialog box at the bottom. c. All of your training regions, in appropirate colors, should appear as "x's" with elipses around them. Change bands in the setup box and use the "limits to actual" button to zoom in. If you don't like some of your training regions you can delete them using the "scissors" keys in the tools palette (click on them first). 6. Classifying the data based on your training regions.

a. From the Process Menu choose Classification then Supervised Classification. b. Select the Output Dataset option and enter a name like small_Va_sup_class. Make sure that it goes into your home directory. c. Click the classification type drop-down menu and choose Maximum Likelihood then Maximum Likelihood Standard d. When the setup box opens, un-select the typicality and posterior probability options. They add a lot of time to the processing and space to the dataset. e. Click ok and wait. 7. Viewing the classified image. a. Close all the windows and/or open a new pseudocolor image window. b. Change the pseudocolor layer type (in the middle) to "classfication display." c. From the process stream at the bottom, load in your new dataset "small_Va_sup_class.ers" and hit GO. d. If you don't like the colors, choose the Edit Class/Region Color and Name option from the Edit Menu. 8. Subsetting the classified image. If you want to display a map with just one or more of the classification layers, but not all, follow these steps. a. Close all the windows and open a new Pseudocolor algorithm. b. Change the layer type to Classification. c. Load your new classified dataset into the algorithm. d. From the process stream, choose the equation editor and enter the following equation if you want to display class number 1
if input1=1 then 1 else null

or...input1=2, etc for other classes and then click the apply button and the GO button. e. From the process stream change the color. f. You may add as many classification layers as you wish, and you may display them over a RGB image if you want Classifying data other than raw TM bands 1. Make the virtual dataset using ratios and/or principal components. 2. Run statistics on the new virutal dataset using the Process menu and Calculate Statisitcs options 3. Add the old training layers to the new dataset by opening up a new annotation layer (edit/create regions under the Edit Menu) and "save as" them from the Tools palette to the new dataset (this rewrites the header file).

4. Rerun the statistics. 5. Now you can evaluate then classify the image as above, now using the newly created virtual dataset.

Você também pode gostar