Friday, 31 August 2007

Gliding at Upavon: Two PhotoOverlays

A shot of Upavon and my left knee from the cockpit of a DG1000 glider operated by the Wyvern Gliding Club.

I've compared two methods of embedding this image in a PhotoOverlay. The first kml file simply references the original photo. The second version references an ImagePyramid created from the photo.

The resolution of the image in the first method never equals that of the original photo, and appears blurred as you zoom in. The ImagePyramid version maintains high resolution as you'd expect. The odd thing is that you can zoom in on the plain, blurry image as far as you like, but the ImagePyramid version limits the amount of zoom you can achieve.



ImagePyramid Tiles from GMapImageCutter

For those without access to Photoshop, jpeg tiles for KML PhotoOverlays can be generated using the Google Maps Image Image Cutter by the UCL Centre for Advanced Spatial Analysis (CASA).

Pad your source image out so that it occupies the bottom left of a square image with a side length in pixels of a power of 2 (maximum size 8192x8192 pixels). Load it into Google Maps Image Cutter and set the 'Max Zoom Level' according to the image size as follows:

Size [px]Max Zoom Level
8192 x 81926
4096 x 40965
2048 x 20484
1024 x 10243

Create your tiles, which will be placed in a new folder.

All that is left to do is to run makepyr.bat from the same folder. It will create copies of the Image Cutter tiles, with names that are compatible with the KML2.2 ImagePyramid element. Ignore any file not found error messages.

One drawback with this approach is that it is likely to generate some unnecessary tiles at higher zoom levels from the image padding areas. These are pretty easy to spot (e.g. they are identical, uniform in colour and probably the smallest file size) and manually delete.

Photoshop Scripts for ImagePyramid Tiles

The KML2.2 PhotoOverlay supports ImagePyramid tiling, where large images are split into sets of 256x256 pixel tiles. Each set is at a different zoom level, with zoom level 0 containing a single tile with a small version of the whole image. Each increment of zoom level quadruples the number of tiles, until the highest level covers the entire image at full resolution. A better explanation is given in the Google Earth KML documentation.

As you can imagine, creating all those tiles can be something of a chore. For this reason I've tried my hand at writing Photoshop CS2 scripts to automate the task. Download MakeJPGImagePyramid.jsx and MakePNGImagePyramid.jsx and store them in your C:\Program Files\Adobe\Adobe Photoshop CS2\Presets\Scripts folder (or the equivalent Mac folder of course). Load your image, then run the png or jpg version of the script. Tiles will be placed in the same folder as the source image, with the source image file name postfixed with "_[level]_[row]_[col]".

The .png version will preserve any transparent areas of the image as transparent areas of the tiles.

These are the first Photoshop scripts I've attempted, so please forgive any silliness in their construction - I welcome any suggestions for their improvement!

The next stage is to do a script that saves in png when the tile has any non-opaque pixels and jpg otherwise. I'm not sure how to do this yet (check a histogram of the tile alpha channel perhaps, or select opaque pixels and check selection dimensions?), but I'll post it up when it's done.

Thursday, 30 August 2007

GE PhotoOverlays with Panoramic Spheres

For the last few days I've been experimenting in Google Earth 4.2beta with the KML2.2 PhotoOverlay element. I'll post some of the initial examples in the next few days, but I'll start with this evening's results.

A while ago Smithee over at Digital Urban came up with an excellent method of displaying 360x180 degree panoramic spheres in GE. I wondered what would happen if I tried to combine his panoramic spheres with the new PhotoOverlay element.

First download his Google Earth Trafalgar Square panorama and view it in GE. Then download this viewer photooverlay file, which has been set up with the same coordinates to place you at the centre of the sphere.

The results are a little disappointing, mainly because the implementation of spherical images in GE seems to be buggy. The image often moves jerkily and flips upside down when you stray too far from the neutral position. However, it does add an extra method of navigating the sphere and the ability to zoom in with the mouse wheel. I still much prefer viewing the spheres with a SpaceNavigator, but for those that don't have one this method gives an extra option.