Intro.As discussed in the "NØIB (Norske Øer Ice Barrier)" thread, Landsat images available in viewers are not the best for those who like to be as close to the ice as possible (without going there):
- image format is JPEG. When zooming in to the details, the artifacts become apparent;
- resolution is far worse(180m) than the native resolution from the Landsat imager (30 meters for most channels and one 15 meter pan-chromatic (B&W) channel);
- the images are false colors based on two infrared and one visible (red) channel. Fine for land images with vegetation, but not for images with lots of water, ice and snow.
Applicable pages from the USGS Landsat FAQ's:
What are the best spectral bands to use for my study?What band combination is used for Landsat browse images? How does Landsat 8 differ from previous Landsat satellites? Step 0: Get a registration on
the web site of the US Geological Survey.
This is required if you want to download image files in the process that I am now describing. If you just want to explore the images available, skip this step.
Registration is free, and takes entering email+password, and responding to the confirmation email. Save the password somewhere when you consider using the bulk downloading app, you need to enter the password there as well.
Step 1: Find suitable Landsat images with the
LandsatLook Viewer.
- Locate the spot of interest. You can use a name (Paris, France, or even Tobias, Greenland) or longitude,latitude coordinates.
- Zoom in sufficiently until a button "Select Scenes" appear in the selection box
- Press "Advanced Query". Make sure the OLI sensor is selected. OLI is Landsat 8, that is latest and greatest but only available in 2013 (and later, later). Select other sensors if pre-2013 data is of interest. Also set "Maximum Cloud Cover" to something high, sometimes partly clouded scenes have a clear view i just the thing that is interesting. Press Apply.
- Select "Only One" under the date slider.
-With the date slider, view the different images that are available in your area of interest.
Step 2. Order and download the Landsat data.
Convinced that the image in the viewer is worth doing some more effort on? Has your computer enough RAM, physical and swap, installed to handle 800 MB images? Recommended is 16 GB physical RAM and perhaps double of that virtual. Then you can continue for some serious computing.
Press the button "Metadata", a box appears with some detailed information on the selected image.
- Press "Add To Cart". You can do this actually several times before proceeding, but here I assume only one image is what we want;
- Press "View Cart"
- in the "Cart" select the image and press "Get Landsat Data";
- confirm that you go to " USGS EarthExplorer" (where you can check out);
- at some point you may be required to log in (see Step 0), unless like me you have selected the "keep logged in" option;
- a new browser window is opened with a list called "Pending Scenes". There should be only one "Scene", our image. Click on its "Entity Id";
- A new page opens with lots of details of our image, but at the bottom is a button "download". Just click on it, if you haven't yet done so (
*);
- In the last page, click on the "download" button that says "Level 1 GeoTIFF Data Product";
- Select the location where you want the file and start the download;
*) If the Level 1 data seems not available, look
hereStep 3: Unpack the "Level 1 GeoTIFF Data Product"
The downloaded file is a compressed archive called something like LC80030042013267LGN00.tar.gz. I recommend unpacking the archive in to an empty directory. Use your favorite software, under Linux the command is:
tar xzf LC80030042013267LGN00.tar.gzOnce unpacked you have a directory with these files:
-rw-r--r-- 1 168288198 sep 24 20:14 LC80030042013267LGN00_B1.TIF
-rw-r--r-- 1 168288198 sep 24 20:14 LC80030042013267LGN00_B2.TIF
-rw-r--r-- 1 168288198 sep 24 20:14 LC80030042013267LGN00_B3.TIF
-rw-r--r-- 1 168288198 sep 24 20:14 LC80030042013267LGN00_B4.TIF
-rw-r--r-- 1 168288198 sep 24 20:14 LC80030042013267LGN00_B5.TIF
-rw-r--r-- 1 168288198 sep 24 20:14 LC80030042013267LGN00_B6.TIF
-rw-r--r-- 1 168288198 sep 24 20:14 LC80030042013267LGN00_B7.TIF
-rw-r--r-- 1 672931638 sep 24 20:14 LC80030042013267LGN00_B8.TIF
-rw-r--r-- 1 168288198 sep 24 20:14 LC80030042013267LGN00_B9.TIF
-rw-r--r-- 1 168288198 sep 24 20:15 LC80030042013267LGN00_B10.TIF
-rw-r--r-- 1 168288198 sep 24 20:15 LC80030042013267LGN00_B11.TIF
-rw-r--r-- 1 168288198 sep 24 20:15 LC80030042013267LGN00_BQA.TIF
-rw-r--r-- 1 7676 sep 24 20:15 LC80030042013267LGN00_MTL.txt
All files start with the image identifier, the Bxx means "spectral band xx". Bands, and their use are listed
here For this discussion B2, B3 and B4 are important as they are the visible light bands Blue, Green and Red 30 m images. The B8 is the panchromatic B&W hi-res image, with the 15 m resolution.
Of course all other bands can be experimented with for the more advanced studies. Here we aim at a simple natural looking image.
Step 4: Inspecting the image files and introducing ImageMagick.
At this stage you might fire up your favorite image editor (the Gimp, Photoshop etc.) to look what is in those files. When I was experimenting that is what I did myself. But because the processing of these "spectral band images" is highly repeatable, I use a command line tool for that.
The free tool is
ImageMagick and available for Unix, Windows, Mac and even iOS. I am using these every day, for instance to produce the ice animations in the amsr2 thread.
Make sure the software is installed and open the terminal.
Imagemagick is a set of different programs, each with an unbelievable set of options. For introduction start with
identify, used to
describe the format and attributes of an image:
$ identify LC80030042013267LGN00_B2.TIF
LC80030042013267LGN00_B2.TIF TIFF 9171x9171 9171x9171+0+0 16-bit Grayscale DirectClass 168.3MB 0.010u 0:00.089
For now it is important to note that the file is a 16 bit TIF image, with size 9171 pixels width and height. Different Landsat scenes may have slightly different sizes, something that will slightly complicate out processing later on.
When ImageMagick reads the TIF files from LandSat it prints several warnings:
identify.im6: LC80030042013267LGN00_B2.TIF: unknown field with tag 33550 (0x830e) encountered. `TIFFReadDirectory' @ warning/tiff.c/TIFFWarnings/768.
As far as understand these warnings are harmless, concerning non image data embedded in the files, and can be suppressed by adding an option
-quit on the command line.
Get the image information of the Panchromatic channel:
$ identify -quiet LC80030042013267LGN00_B8.TIF
LC80030042013267LGN00_B8.TIF TIFF 18341x18341 18341x18341+0+0 16-bit Grayscale DirectClass 672.9MB 0.000u 0:00.060Because this channel is 15 m instead of 30 m, the width and height in pixels has doubled but not exacly! Actually one pixel is missing in both directions, a fact that we have to solve in the next section.
The last ImageMagick tool that I would like to introduce here is [ur=http://www.imagemagick.org/script/convert.phpl]convert[/url], the work horse of the set. With an almost infinite set of options it can
convert between image formats as well as resize an image, blur, crop, despeckle, dither, draw on, flip, join, re-sample, and much more.
$ convert -quiet LC80030042013267LGN00_B8.TIF LC80030042013267LGN00_B8.pngConverting the TIFF file to a png file format. Png is much more efficient in disk space:
-rw-r--r-- 1 672931638 sep 24 20:14 LC80030042013267LGN00_B8.TIF
-rw-r--r-- 1 285094673 nov 6 12:53 LC80030042013267LGN00_B8.png
This is the file from which I showed selections in the "NØIB (Norske Øer Ice Barrier)" thread.
Step 5: Process the image files with ImageMagick commands.
Ready for the magick? Here we go.
Combine the Read, Green and Blue images to one (composite) natural color image:
$ convert -quiet LC80030042013267LGN00_B4.TIF LC80030042013267LGN00_B3.TIF LC80030042013267LGN00_B2.TIF -channel RGB -combine out-nat-30.png
Producing an intermediate file out-nat-30.png, containing a perfectly usable natural color image with 30 m resolution.
But we go for the 15 m resolution, because it is there. In order to do that we must resample the image for the increased width and height:
$ convert out-nat-30.png -filter Point -resize 200% -crop 18341x18341+0+0 out-nat-15.tmp.png
The -filter option prevents that ImageMagick does some "smart" pixel interpolating when resizing and just doubles the number of pixels (in each direction).
The -crop option is nescessary because the 15 m panchromatic image had not exactly twice the size. The -crop 18341x18341+0+0, trims the result to the same size. The "+0+0" gives the offset from where to crop, this means count from the upper left corner which is what we want.
The result is a natural color image that has the correct number of pixels, but effectively the resolution is not changed because every cluster-of-four pixels has the same RGB value. The trick is to get the 15 m panchromatic information in.
Next step is to separate the RGB values into another
color space called HSL, consisting of Hue, Saturation and Lightness:
convert out-nat-15.tmp.png -colorspace HSL -separate separate_HSL_%d.png
Producing three (intermediate) files called separate_HSL_0.png, separate_HSL_1.png and separate_HSL_2.png. Each has 15 m pixels but an effective resolution of 30 m. The trick is to replace the Lightness image by our panchromatic (B8) channel. Here is the command to rebuild the image this way:
convert -quiet separate_HSL_0.png separate_HSL_1.png LC80030042013267LGN00_B8.TIF -set colorspace HSL -combine -colorspace RGB out-nat-15.png
Which produces the final result a 15 m hires natural color image. Only at the highest magnification where individual pixels are visible, the 30 m color resolution becomes visible.
The image is quite large:
-rw-r--r-- 1 716890168 nov 7 10:01 out-nat-15.pngA reflection of the amount of information in the image. Please don't convert to JPEG, or perhaps until you made the final cut and adjustments. Then convert with the highest quality settings.
Step 5a: Some optimizations.
In the previous section I have shown the procedure in a number of small steps. That is good for an explanation, showing what is done without the clobber of a number of simultanious things.
In this section are the commands that I actually use. You may skip it altogether if you like.
First there is the problem that I already mentioned that the size of the Landsat scenes are not always the same. Since we need it for the "-crop" option, we have to extract it form the files.
Under a Unix compatible shell (Linux, Mac and Windows using
CygWin) it goes like this:
cropsize=`identify -quiet LC80030042013267LGN00_B8.TIF | cut -d ' ' -f 4`
This creates from the output of the identify command a variable named
cropsize with a value:
$ echo $cropsize
18341x18341+0+0A further complication is that I wrote the commands with full file names. If these files are the only similar named files, we can use wildcards. So instead of:
LC80030042013267LGN00_B8.TIFwrite:
*_B8.TIFThis makes the command independent from the actual Landsat scene.
Lastly, not all intermediate files are needed. I have not tried (yet) to squeeze everything on a single line but this is the current script (three lines):
cropsize=`identify -quiet *_B8.TIF | cut -d ' ' -f 4`
convert -quiet *_B4.TIF *_B3.TIF *_B2.TIF -channel RGB -combine -filter Point -resize 200% -crop $cropsize -colorspace HSL -separate separate_HSL_%d.png
convert -quiet separate_HSL_0.png separate_HSL_1.png *_B8.TIF -set colorspace HSL -combine -colorspace RGB out-nat-15.png
The script takes about 5 minutes here. I see the memory monitor for the process
convertspike at 13 GB. This will give problems when you thought 8 GB was plenty or RAM.
Step 6: Final processing.
The conversion is done, but if we look at it the image is not very brilliant, lacking contrast. It is also far too big to share on the web.
The final edit are currently done in the image editor, I am using
the Gimp , but I don't expect that is critical (provided it is 64 bits and can handle the sizes).
In the Gimp, I enhance the image with the automatic white balancing tool:
Colors->Auto->White Balance
The cutting can be done with the crop tool or use a selection tool followed by choosing "Crop to Selection" from the image menu.
Further.The procedure described above, is not finished. I am thinking:
- the HSL color separation is just one of several slightly different possibilities. HSL is the first one I tried, I have no idea if it is the best one;
- What about other spectral bands? Does infrared carry useful information that helps understanding the scenes;
- The "white balance" solution to get brilliant colors should be explored further;
- perhaps there are other ideas, I'd like to hear them.