4

I am quite new at Python programming and I need your help. I always do a research for my problem first before posting.

I have SAR dual polarization image (2^16 gray level values) in tiff format. In this tiff image there are two bands. The first band (HH_band) is a horizontal polarization channel and the second one (HV_band) is the vertical polarization channel. I want to create an RGB composite image. For this to happen, I need to layer stack the two channels as follows:

  1. get the first band (HH_band)
  2. get the second band (HV_band)
  3. get the ratio (HH_band/HV_band)

I know that there are many people posting about sometime similar to this (RGB composite image of natural colors). I tried to use cv2.merge or cv2.split from openCV library but didn't work. I thought it would be relatively easy to create a SAR RGB image in Python (as I have seen a few post about creating RGB image of LANDSAT) but I got stuck in my case.

I would much appreciate any help.

0

2 Answers 2

3

Here is a possible way to accomplish the band composition programmatically:

import numpy as np

tif = io.imread('dual_polarization_image.tif')

band = {'HH': 0, 'HV': 1}

r = tif[:, :, band['HH']]
g = tif[:, :, band['HV']]

hh = r.astype(np.float64)
hv = g.astype(np.float64)

b = np.divide(hh, hv, out=np.zeros_like(hh), where=hv!=0)

rgb = np.dstack((r, g, b.astype(np.uint16)))

Remarks:

  • It would be possible to deal with different arrangements of the bands in the TIFF image by simply redefining the values of the dictionary band.
  • Prior to calculating the band ratio is necessary to convert data to np.float64.
  • I have taken advantage of the where option for universal functions to avoid zero division warnings.
  • In order for the composition to be possible, the band ratio (blue channel) has to be converted back to the same type (i.e. np.uint16) as the original bands (red and green channels).
1
  • That's amazing. Great answer. Thank you
    – Johny
    Mar 17, 2017 at 14:23
1

It's difficult to test without sample images, but you should be able to do this simply at the commandline with ImageMagick which is included in most Linux distributions and is available for OSX and Windows.

The command will look like:

convert HH.tif HV.tif \( -clone 0 -clone 1 -compose divide -composite \) \
   -combine -auto-level result.png
1
  • Thank you for your suggestion. I appreciate it
    – Johny
    Nov 11, 2016 at 14:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.