Monday, December 29, 2014

Trainsity Osaka Android App

Find your way around Osaka city's subway using the high resolution vector maps of the train network. The following metro rail lines are available:

  • Midosuji, 
  • Tanimachi, 
  • Yotsubashi, 
  • Chuo, 
  • Sennichimae, 
  • Sakaisuji, 
  • Nagahori-Tsurumi-ryokuchi, 
  • Imazatosuji, 
  • Newtram Nanko Port Town, 
  • Kita Osaka Kyuko, 
  • Kintetsu Keihanna, 
  • Hankyu Kyoto, 
  • Hankyu Senri, 
  • Osaka Monorail, and 
  • Kitakyu Namboku lines. 
The maps have small file size footprints but with many levels of zoom and can work offline without connecting to the Internet. Users can click the train station box labels to open Google Maps or Google StreetView, where they can use all the functions of the Google apps to visualize the surrounding area and/or perform routing for directions. There is also an offline function to calculate the best way to travel from a station to another station with a direction breakdown and timings (which may vary from the actual travelling time).

On a mobile handset, the app will display a list of train maps, which when tapped will open up a detail view of the subway transit map, as shown below.

Tapping the station boxes will bring up an option menu where users can choose to display the station in Google Maps or Street View.

There is also an option to find the best direction to or from the tapped stations.

The app is also optimized for tablet sized devices. Both the list and the vector map are displayed at the same time, as shown below.

 The user can toggle the map to full screen mode by tapping the action bar icon at the top right corner.

The app can be downloaded from the Google Play Store. Just click the button below.
Get it on Google Play

Monday, December 15, 2014

Create a Colored Infra Red (CIR) image from a multi-channel RGBI TIFF file using ImageMagick

Some remote sensing imagery TIFF files contain multiple bands of data such as red, green, blue, and infra-red data. In order to visualize these bands, it is necessary to combine them into an RGB format such as what is called a Colored Infra Red (CIR) display. The open source software ImageMagick can be used to generate the CIR display from the multi-channel TIFF files.

This post illustrates how to create a CIR image from an input RGBI TIFF file. In order to generate a CIR image, the input channels - RGBI has to be reordered to IRG i.e.

  • the file's output red channel is replaced with the input Infra red channel, 
  • the output green channel is replaced with the input red channel, 
  • the output's green channel is replaced with the input green channel, 
  • and the input blue channel is essentially thrown away. 

The ImageMagick command to do this is quite simple, as shown below.

$ convert input_rgbi.tif -channel rgba -separate -swap 1,2 -swap 0,1 -swap 0,3 -channel rgb -combine output_cir.tif

Note: the sequence of options is important.

  • The option -channel rgba instructs the command to read in 4 channels.
  • The option -separate splits the input channels
  • The option -swap 1,2 swaps the 2nd and 3rd channels from RGBI to RBGI
  • The option -swap 0,1 swaps the 1st and 2nd channels from RBGI to BRGI
  • The option -swap 0,3 swaps the 1st and 4th channels from BRGI to IRGB
  • The option -rgb removes the 4th channel to become IRG
  • The option -combine merges all the 3 channels back
The input RGBI file (only the RGB channels are displayed)
The CIR image generated from ImageMagick

Monday, December 8, 2014

Correcting color cast problems in aerial photographs using curves in Gimp

In some cases, it may be necessary to correct color cast problems from aerial photographs due to atmospheric haze or sensor problems. An example of an image with a color cast problem is shown below. You can download the file from,_1966.jpg.

Note: aerial photograph courtesy of

The Curves correction function in just about any image processing software can be used to easily correct the color cast problem. The open source application Gimp is used in this example.

The key to solving the problem is to use the fact that the color gray has the same RGB values. If a gray colored feature in the image e.g. an asphalt road has unequal RGB values, than the image has a color cast problem. To correct the problem, all you have to do is to get the RGB values for that gray point in the image to be the same using the Curves function.  It may be necessary to do the correction in the middle, dark and light tones. The following example illustrates how to correct the color cast problem.

  1. Start Gimp and open the aerial photograph. Optional. Make a duplicate layer of the image.

  2. If the Pointer window is not displayed, then select Windows | Dockable Dialogs | Pointer.

    Note: the circled area displays the RGB in pixel or percentage values.
  3. Move the pointer around the mid tone gray colored feature e.g. paved road, as shown in the screenshot below. Observe the RGB values in the Pointer window.

    Note: in this example, the RGB values are 142, 140, 189 or 55%, 55%, 74%. The numbers say that there is a blue cast in the mid tone values i.e. the blue values are too high and will have to be lowered. The red and green values are okay. 
  4. Select Colors | Curves.

    The Adjust Color Curves dialog box appears.
  5. Since blue is the problem color, select Blue in the Channel field. Then drag down the blue curve at around 189 pixel value as shown in the screenshot below. You can also move the cursor to the mid tone gray feature and check the new RGB values in the Pointer window. The correction is complete when the RGB values are about equal.

    Note: if the preview is toggled on, the effect of the changes will be displayed in the image window.
  6. In this example, the light tones do not seem to show much color cast. However, the dark tones don't seem to have enough red values as shown in the screenshot below. The dark area under the bridge show the RGB values of 1, 18, 17 or 0%, 7%, 7%.

  7. In the Adjust Color Curves dialog box, change the Channel to Red. Click a point in the middle of the curve to anchor the mid and light tone red values since the problem is only in the dark tones. Then drag the 0 pixel curve point up to 17 pixel value.

    Note: after every change, always move the cursor to the dark area and check the RGB values in the Pointer window.
  8. When the numbers and preview look pleasing, click OK to confirm the changes.

    The image shows the corrected colors.

    Contrast this to the original color casted version.

Monday, December 1, 2014

After adding an Android Library Module to a project, Android Studio does not launch the default app activity

I was following the official Android Studio documentation on building an Android project with Gradle but every time I run the app on my device, the activity for the library module kept on appearing no matter what changes I made to the app's default activity. The instruction added a button to the default activity and I was expecting a button to appear but what came out was as shown below.

The documentation did not mention anything about this. And after thinking through the problem, I figured that the Run configuration in the Android Studio needs to be told to run the app's activity. The following steps show how to change the Run Configuration.

  1. In Android Studio, select Edit Configuration.

    The Run/Debug Configuration dialog box appears.

  2. In the Activity group box, toggle on Launch. Then click browse [...].

    The Select Activity Class dialog appears.

  3. Select the desired app's activity e.g. MainActivity. Click OK.

  4. Click OK.
  5. In Android Studio, run the app again.

    This time, the correct activity with the added button appears.