This tutorial describes the Docker container mort/crcdocker which encapsulates many of the Python scripts accompanying my textbook. The container eliminates completely the need to install Python dependencies on the client computer. It serves the scripts in an IPython notebook in the user's browser.
First of all, install Docker.
To pull the image from Docker Hub and start the container on a Linux host, run
sudo docker run -d -p 433:8888 -v yourImageFolder:/home/imagery --name=crc mort/crcdocker
Here, yourImageFolder is the location of your images. If you are running on Windows, use
sudo docker run -d -p 433:8888 -v //C/Users/yourImageFolder:/home/imagery --name=crc mort/crcdocker
You can stop and re-start the container with
sudo docker stop crc
sudo docker start crc
Point your browser to
http://localhost:433
to see the IPython Notebook main page. Then open (somewhat self-referentially) this tutorial notebook and list the contents of the home directory with
cd /home
ls -l
In addtion to the Python scripts, there are two directories imagery and tutorial. The former mirrors the host image directory and the latter contains this tutorial and a few sample images:
ls tutorial -l
The Ipython "magic" command %run, or also simply run, is used to run the Python programs, all of which are command-line scripts controlled with various option flags. For example, to get help with the principal components analysis script:
run /home/pca -h
Note that you can leave out the .py extension when running a script in this way.
We will do a PCA on a $400\times 400$ spatial subset of the landsat.tif image. First we can use the GDAL utility gdalinfo to get information about the image. We use the "bang" ! to tell Ipython that this is an OS command:
!gdalinfo /home/tutorial/landsat.tif
Then enable graphics and run the PCA script:
%matplotlib inline
%run /home/pca -d [0,0,400,400] tutorial/landsat.tif
If you wish to suppress graphical output, include the -n flag:
run /home/pca -d [0,0,400,400] -n tutorial/landsat.tif
The script dispms.py will generate RGB composite images of any three bands of a multispectral image. Up to two images can be placed side-by-side. Lower case options refer to the left hand image, upper case to the right hand image, if present:
run /home/dispms -f /home/tutorial/aster_1.tif -F tutorial/aster_2.tif -p [1,2,3] -e 1 -E 1
The images have been dispayed above in a 0-255 linear stretch ( flags -e 1 and -E 1 in order to highlight the radiometric differences between them.
We will now use th IR-MAD algorithm to locate invariant pixels for a relative radiometric normalization of the two aster images. First the IR-MAD transformation:
run /home/iMad /home/tutorial/aster_1.tif /home/tutorial/aster_2.tif
And next the normalization script:
run /home/radcal /home/tutorial/MAD(aster_1-aster_2.tif).tif
Comparing the images as before, we now see that the images are radiometrically similar:
run /home/dispms -f /home/tutorial/aster_1.tif -F /home/tutorial/aster_2_norm.tif -p [1,2,3] -e 1 -E 1
Now feel free to continue experimenting on your own: