Advertisement
Abhisek92

decomposition.py

May 22nd, 2022
988
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import numpy as np
  2. import rasterio as rio
  3.  
  4. def linearize(img):
  5.     return 10.0 ** (img / 10.0)
  6.  
  7. def make_mask(img, thresold=-20.0):
  8.     valid_mask = np.logical_not(
  9.         (img[0, :, :] > img[1, :, :]),
  10.         (img[0, :, :] > threshold)
  11.     )
  12.     return np.ma.masked_array(
  13.         img, np.logical_not(valid_mask), fill_value=np.nan
  14.     )
  15.  
  16.  
  17. def decompose(img):
  18.     q = img[1, :, :] / img[0, :, :]
  19.     x = (1 - q)
  20.     y = (1 + q)
  21.     m_c = x / y
  22.     theta_c = np.arctan((1 - (q ** 2)) / (x + (q ** 2)))
  23.     p1 = 1 / y
  24.     p2 = q * p1
  25.     h_c = -(p1 * np.log2(p1)) + (p2 * np.log2(p2))
  26.     return np.concatenate((m_c, theta_c, h_c), axis=0)
  27.  
Advertisement
RAW Paste Data Copied
Advertisement