-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsentinel_funcs.py
27 lines (22 loc) · 1.02 KB
/
sentinel_funcs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# Import important packages
import numpy as np
import matplotlib.pyplot as plt
def calculate_NDVI(image):
""" This function calculates the Normalised Differential Vegetation Index for
the 4-band data provided in this exercise. A 2D array is returned"""
r = image[:,:,2]
ir = image[:,:,3]
return (ir-r)/(ir+r)
def image_histogram_equalization(image):
""" Image histogram equlisation"""
# from http://www.janeriksolem.net/2009/06/histogram-equalization-with-python-and.html
# get image histogram
image_histogram, bins = np.histogram(image.flatten(), 256, normed=True)
cdf = image_histogram.cumsum() # cumulative distribution function
cdf = (255-1) * cdf / cdf[-1] # normalize
# use linear interpolation of cdf to find new pixel values
image_equalized = np.interp(image.flatten(), bins[:-1], cdf)
if len(image.shape) == 3:
return image_equalized.reshape(image.shape).astype('uint8')[:,:,::-1]
else:
return image_equalized.reshape(image.shape).astype('uint8')