# To install watermark extension execute: # %install_ext https://raw.githubusercontent.com/HyperionAnalytics/watermark/master/watermark.py %load_ext watermark %watermark -v -m -p numpy,scikit-image,matplotlib import numpy as np from skimage import io, exposure from matplotlib import pyplot as plt from IPython.display import Image %matplotlib inline def read_band(n): """ Load Landsat 8 band Input: n - integer in the range 1-11 Output: img - 2D array of uint16 type """ if n in range(1, 12): tif_list = !ls *.TIF band_name = 'B' + str(n) + '.TIF' img_idx = [idx for idx, band_string in enumerate(tif_list) if band_name in band_string] img = io.imread(tif_list[img_idx[0]]) return img else: print('Band number has to be in the range 1-11!') def color_image_show(img, title): """ Show image Input: img - 3D array of uint16 type title - string """ fig = plt.figure(figsize=(10, 10)) fig.set_facecolor('white') plt.imshow(img/65535) plt.title(title) plt.show() cd /Users/kronos/gis/l8/guinea_bissau/ b2 = read_band(2) b3 = read_band(3) b4 = read_band(4) img432 = np.dstack((b4, b3, b2)) %reset_selective -f b color_image_show(img432, '4-3-2 image, data set LC82040522013123LGN01') fig = plt.figure(figsize=(10, 7)) fig.set_facecolor('white') for color, channel in zip('rgb', np.rollaxis(img432, axis=-1)): counts, centers = exposure.histogram(channel) plt.plot(centers[1::], counts[1::], color=color) plt.show() img432_ha = np.empty(img432.shape, dtype='uint16') lims = [(7100,14500), (8200, 14000), (9200,13500)] for lim, channel in zip(lims, range(3)): img432_ha[:, :, channel] = exposure.rescale_intensity(img432[:, :, channel], lim) color_image_show(img432_ha, '4-3-2 image, histogram equilized') img432_ha[:, :, 1] = exposure.adjust_gamma(img432_ha[:, :, 1], 0.65) img432_ha[:, :, 2] = exposure.adjust_gamma(img432_ha[:, :, 2], 0.75) color_image_show(img432_ha, '4-3-2 image, histogram equilized, color gamma adjusted') Image('http://www.esa.int/var/esa/storage/images/esa_multimedia/images/2014/01/' 'guinea-bissau_and_the_bissagos_islands/13474677-1-eng-GB/' 'Guinea-Bissau_and_the_Bissagos_islands_node_full_image_2.jpg')