Dec 27, 2007

Working with image: Mosaic images

Creating the image mosaic can be very easy in Mathematica.

First, what's inside the image?
Import["mnt.png", "Elements"]]

{"BitDepth", "ColorMap", "ColorSpace", "Data", "DataType", "Graphics", "GrayLevels", "ImageSize", "RawData", "RGBColorArray"}

We only need use the "Data": Import["mt.png","Data"]

Here we "steal" some images from Almighty Google as the example.
Import the following four images (a0,a1,a2,a3)
a0: http://mt0.google.com/mt?n=404&v=ap.66&x=0&y=0&zoom=16
a1: http://mt1.google.com/mt?n=404&v=ap.66&x=1&y=0&zoom=16
a2: http://mt1.google.com/mt?n=404&v=ap.66&x=0&y=1&zoom=16
a3: http://mt3.google.com/mt?n=404&v=ap.66&x=1&y=1&zoom=16
See these two guides for details on Quadtree coordinate system used by Google.
Coordinate systems for Google Maps and Google Satellite Images

Then create the data matrix for the new image:
mosaicimg=ArrayFlatten[{{a0, a1}, {a2, a3}}];

Draw the new image and export it:
Graphics[Raster[Reverse[mosaicimg]/255, ColorFunction -> RGBColor],
PlotRange -> {{0, 511}, {0, 511}}, ImageSize -> {512, 512}]
Export["earth.png",%,"PNG"]

This is the image used in Fun with image overlay: Google Map

No comments: