Lab VI: Image Segmentation Preliminaries in ENVI
Last Updated: 10/27/2009
Note that I have already done EVERYTHING listed below for you. I have included this file just to give provide instructions in case you want to repeat this for a different part of the image at some point in the future as part of an independent project.
Outline of the document (Click on links to jump to a section below):
Step1: Getting data out of ENVI - Creating a TIFF file
Step 2: Import TIFF and create file for use by SPRING
Step 3: Open file in SPRING
Create a SPRING database
Create a SPRING project
Create a SPRING data model
Import image
View image
Step 4: Image segmentation
Step 1: Getting data out of ENVI; Create a TIFF file.
Get yourself a copy of wwu2004cir_1m_utm.img. From the ENVI main menu, go to File-Open Image File and select this file. Also from the ENVI main menu bar, go to File-Save File As-TIFF/GeoTIFF. In the Output to TIFF/GeoTIFF Input Filename dialog box, select “wwu2004cir_1m_utm.img” and then click OK. In the Output File to TIFF/GeoTIFF dialog box, select an output folder and filename, then click OK. This will create a *.tif file (containing the image) and a *.tfw file (tiff world file containing some coordinate information).
Go to the output folder you specified and confirm that your tiff file now exists.
Back to Outline
Step 2: Use IMPIMA to import your TIFF file and create a .spg (Note that v5.0.4 created a .grb file; v5.1.3 seems to create a .spg file instead; not sure what the difference is). SPRING actually consists of a set of three programs:
SPRING – the image processing and GIS package;
IMPIMA – for image import and export;
SCARTA – for generating and printing maps (we will not be using this package).
We need to begin by using IMPIMA to bring our TIFF file into a format called GRIB that is used by SPRING.
Begin by starting the IMPIMA-5.1.3 software. From the main toolbar, go to File-Open and select your TIFF file. Assorted file parameters will now be visible in the Input Image Parameters section including:
Col x Lin: 3301, 3301 (this is the number of columns and lines in the file)
ResX: 1.00 ResY: 1.00 (this is the pixel size: 1m by 1m)
Highlight one of the Bands in the Input Image Parameters section and then go to Apply-Draw or push .
In the Output Image Parameters section, click on all 3 bands and change the Sampling to 1. This will retain the same 1m by 1m pixel size in the output image. Now go to File-Save As or push and select a destination and output filename. Two output files will be created; one small file with a *.dsc extension and another much large file (about the same size as your *.tiff file) with a *.spg extension. Note that it will take some time to create these output files. In my case, with a *.tiff file of about 32 Mbytes, it took about 15 minutes to create the output files. While these files are being created, the programs provides no feedback to indicate progress and the task manager indicates that IMPIMA is “not responding.” Be patient!
After your output files are generated, go to File-exit to close IMPIMA.
Back to Outline
Step 3: Open your file in SPRING. Start the SPRING-5.1.3 software. After closing the “News” panel, the initial window looks like this:
Create a SPRING Database: We need to begin by creating something called a SPRING Database. My working folder for this lab is c:/temp/wallin09/segwwu. I have placed my wwu2004cir_1m_utm.img, wwu2004cir_1m_utm.tif, wwu2004cir_1m_utm.spg and wwu2004cir_1m_utm.dsc files in this folder. Under segwwu, I have created another folder which I called springdb. This is where my SPRING database will reside. From the Databases dialog box, Click on Directory and navigate to the springdb folder (mine is c:/temp/wallin09/segwwu/springdb). Enter a name for your database (I used “wwu_db”) and select “Access” as the database type (this is called the “Manager” for some reason).
Click Create. When asked if you want this database to have a password, select No. Finally, click on Apply in the Databases dialog box. The dialog box will disappear.
Back to Outline
Create a SPRING Project: The SPRING Project defines the projection and bounding box (location and spatial extent) of your image. From the main SPRING toolbar, go to File-Project. From the Projects dialog box, enter a Name, then click on the Projection button.
In the Projections dialog box enter:
Systems: UTM
Earth Models: Ellipsoid->Clarke-1866 (use this if NAD27, use Datum of ITRF(WGS84) or NAD83 otherwise)
Origin
Long: w 123 0 0.00 (note that the format here is very important; pay attention to spaces) (not sure but this seems to fill in automatically when you input the zone?)
Zone: 10
then Apply and the Projections dialog box will disappear.
Back in the Projects dialog box, set the Coordinates checkbox to Planes (to enable us to use UTM coordinate rather than latitude/longitude) ((Note: If I click on Geographic here instead of Planes, I can enter lat/long instead and I think ENVI easily gives lat/long for all 4 corners; need to check this)) and enter the coordinates of the lower left (x1, y1) and upper right (x2, y2) of your image. These can be obtained in ENVI by opening your starting image file (wwu2004cir_1m.img). In the Available Bands List dialog, right-click on the image and go to Edit Header. In the Header Info dialog box, note the number of samples (e.g. columns) and lines (e.g. rows) in the image. Now go to Edit Attributes-Map Info. Under Map Coordinate of Tie Point you can obtain the UTM coordinates of the CENTER of the pixel in upper UPPER LEFT corner of the image. It should look like this:
Unfortunately, SPRING needs the coordinates of the LOWER LEFT AND UPPER RIGHT! Like this:
Although it is not entirely clear to me, I think that the coordinate given by ENVI above represents the CENTER of the pixel in the upper left corner of the image. Similarly, although it is not clear, I think that SPRING also needs the coordinates of the CENTER of the pixels in the lower left and upper right corners. So, I have calculated the inputs for SPRING as:
For the WWU scene:
X1 = 536300
Y1 = 5400000 – (3301 -1) = 5396700
X2 = 536300 + (3301-1) = 539600
Y2 = 5400000
For the WorldView-2 scene of Acme (R1C1 from Erica’s data), here is the header info from ENVI:
Note that the coordinates for the UL pixel are different in the Available Bands List vs. the Edit Map Information dialog. I suspect that the coordinate in the EMI window is for the center of the 2 m pixel and the coordinate in the ABL is for the upper left corner of the pixel but not sure. Still not sure if Spring wants the coordinates for the center or corner of the pixel. I will assume that SPRING wants the center of the pixel. So:
X1 = 558380 +1 = 558381
Y1 = 5398410 – (2048*2) -1 = 5394313
X2 = 558380 + (2048*2) – 1 = 562475
Y2 = 5398410 -1 = 5398409
Select the Northern Hemisphere (BOTH PLACES!!!). Then click on Create, then Load.
Back to Outline
Create a Data Model: From the main SPRING toolbar, select File-Data Model. From the Data Model dialog box, under Categories select the CAT_Image. Then click on Apply and Close. It will appear as if nothing has happened. Trust me, all is well.
Back to Outline
Import the image (finally!): From the main SPRING toolbar, select File-Import-Import Registrated (sic) Image. This brings up the Import Registered Images dialog box. Click on the Directory button and navigate to the folder containing your .spg file (the .spg file was created from the .tiff file in IMPIMA). Your .spg file will show up in the Files window and the individual bands will show up in the Images window. It is not entirely clear to me but it appears that the layers in the Images window come from the .tiff file rather than from the .spg file. At any rate, click on the first band (wwu2004cir_1m_utm_ENVI-B1 in my case) and, next to the Category button, make sure that it is set to CAT_Image. If it isn’t click on the Category button to bring up the Category List dialog box. Select CAT_Image, and Apply
Back in the Import Registered Images dialog box, click on the System Correction box, then click on Apply.
A box will pop up informing you that you have an “Image without control points!” Click OK to dismiss this window. Another window may pop up informing you that you have an “Invalid threshold.” Click OK to dismiss this window. I have no idea what these messages really mean. At any rate, at this point, your first band should not appear in the Available Infolayers window of the Control Panel.
Back in the Import Registered Images dialog box, repeat this process for your other bands, then close the Import Registered Images dialog.
Back to Outline
View your image (finally!): In the Available Infolayers window of the Control Panel you will see a list of all three bands in the image. Highlight band 1 (recall that this is the near-IR band; see the tech specs at the beginning of this lab), then click on the R checkbox. This will load band 1 into the red color gun. Then load band 2(recall that this is the red band) in the green color gun (G checkbox) and finally band 3 (recall that this is the green band) in the blue color gun (B checkbox). Your display should now look something like this:
How about that! OK, I know this was seems like a ton of work just to display an image. I don’t know why they make it this hard but they do. I told you that the learning curve on SPRING was steep! Trust me, the segmentation and classification part of SPRING will be easier.
If the image doesn’t fill up the SPRING display window, you might try clicking on the Zoom to Infolayer button . If you’d like, you can spend some time playing around with the other zoom functions but let’s move on.
Back to Outline
Step 4: Image Segmentation. From the main SPRING toolbar, go to Image-Segmentation
In the Segmentation dialog box, highlight all 3 bands (in the Bands box at the top of the dialog box) by clicking on them one at a time, set the Method box to Region Growing, set the Similarity box to 10 and the Area(pixels): box to 25 (use 10 pixels for Acme WV image). This Areas(pixels) sets the smallest region (polygon) that will be delineated in the image. Since we have 1m by 1m pixels, a polygon that has 25 pixels will be 5 m by 5m or 25 m2 ; hence our minimum mapping unit is 25 m2 . In the Segmented Image box, enter a filename; something like “wwu2004seg10_25” might be good. This indicates a segmented image with a similarity of 10 and a minimum region size of 25 pixels. Set the Arc Smoothing checkbox to yes and click on Apply.
Spring 5.1.3
For the Acme WV-2 image, I want to do two segmentations. The first using all 8 bands (I’ll call this acmeseg10_10_8b) and the second using just the 4 bands that are similar to TM Bands 1-4 (I’ll call this acmeseg10_10_4b).
Spring 5.1.7
It may take minutes to hours for the segmentation to run. Be patient! With this image of 3300 rows and 3300 columns and three bands, it took about 15 minutes on a computer with a single 3.2 Ghz. Processor and 2 Mbytes of RAM.
For Acme image (2048 rows and 2048 columns) and all 8 bands, this took 62 minutes on my machine (dual core 2.9 GHz. Processor and 4 Gbytes of RAM).
For Acme image (2048 rows and 2048 columns) and only 4 bands, this took 72 minutes on my machine.
Go take a break.
Back to Outline
Return to Image Segmentation Lab