Coyote's Guide to IDL Programming

Overlaying a 24-Bit Image on a Map Projection

QUESTION: I've read your article on overlaying a 2D image on a map projection, but I have a 24-bit image and Map_Image and Map_Patch only seem to accept 8-bit images. How can I overlay my 24-bit image onto a map projection?

ANSWER: I this case you are going to have to use Map_Image or Map_Patch to warp each individual color plane of your 24-bit image. Then reconstruct the warped image planes into a 24-bit warped image for display. The only really tricky part is to be sure you have set color decomposition on when you display the image.

Here is IDL code that first constructs a 24-bit color image from an 8-bit image found in the IDL distribution, then warps it onto a map projection.

   PRO Map_Image24

      ; Color decomposition off

   Device, Decomposed=0

      ; Read the data file.
      
   filename = Filepath(SubDirectory=['examples','data'], 'worldelv.dat')
   OpenR, lun, filename, /Get_Lun
   image2D = BytArr(360, 360)
   ReadU, lun, image2D
   Free_Lun, lun
   image2D = Shift(image2d, 180, 0)

      ; Construct a 24-bit color image.

   LoadCT, 5
   TVLCT, r, g, b, /Get
   image24 = BytArr(360, 360, 3)
   image24[*,*,0] = r[image2D]
   image24[*,*,1] = g[image2D]
   image24[*,*,2] = b[image2D]

      ; Create a map projection.
      
   TVLCT, 80, 80, 80, !P.Background  ; Charcoal background.
   TVLCT, 0, 255, 0, !P.Color        ; Green annotation color.
   Map_Set, /Sinusoidal

      ; Warp each image plane into map coordinate space. The
      ; missing color is set to the RGB value for Charcoal.
      
   warp_r = Map_Image(Reform(image24[*,*,0]), xx, yy, Missing=80, Compress=1)
   warp_g = Map_Image(Reform(image24[*,*,1]), xx, yy, Missing=80, Compress=1)
   warp_b = Map_Image(Reform(image24[*,*,2]), xx, yy, Missing=80, Compress=1)

      ; Construct the 24-bit warped image.
      
   s = Size(warp_r, /Dimensions)
   warp24 = BytArr(3, s[0], s[1])
   warp24[0, *, *] = warp_r
   warp24[1, *, *] = warp_g
   warp24[2, *, *] = warp_b

      ; Display the 24-bit image.
      
   Device, Decomposed=1
   TV, warp24, xx, yy, True=1
   Device, Decomposed=0

      ; Add the map projection information.
      
   Map_Set, /Sinusoidal, /Continents, /Grid, /Label, /NoErase

   END

This is an example of what the map projection looks like.

Map projection with 24-bit image overlaid on top.

Google
 
Web Coyote's Guide to IDL Programming