Skip to content

Instantly share code, notes, and snippets.

@TomHortons
Last active July 19, 2017 06:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TomHortons/8d3de37dee1dc7962abe1380f0ff0395 to your computer and use it in GitHub Desktop.
Save TomHortons/8d3de37dee1dc7962abe1380f0ff0395 to your computer and use it in GitHub Desktop.
from skimage import io
image_paths = sorted(glob('../input/train-tif/*.tif'))[0:1000]
image_paths_jpg = sorted(glob('../input/train-jpg/*.jpg'))[0:1000]
imgs = [io.imread(path) / io.imread(path).max() for path in image_paths]
#r, g, b, nir = img[:, :, 0], img[:, :, 1], img[:, :, 2], img[:, :, 3]
ndvis = [(img[:,:,3] - img[:,:,0])/((img[:,:,3] + img[:,:,0])) for img in imgs]
n = 16
plt.figure(figsize=(12,8))
plt.subplot(131)
plt.imshow(ndvis[n], cmap='jet')
plt.colorbar()
plt.title('NDVI index')
plt.subplot(132)
plt.imshow(imgs[n])
plt.title('tiff image')
plt.subplot(133)
plt.imshow(plt.imread(image_paths_jpg[n]))
plt.title('jpg image')
plt.figure(figsize=(12,8))
plt.subplot(121)
plt.imshow(ndvis[32], cmap='jet')
plt.colorbar()
plt.title('NDVI index of cloudy image')
plt.subplot(122)
plt.imshow(imgs[32])
plt.figure(figsize=(12,8))
plt.subplot(121)
plt.imshow(ndvis[10], cmap='jet')
plt.colorbar()
plt.title('NDVI index of image with lots of vegetation')
plt.subplot(122)
plt.imshow(imgs[10])
import seaborn as sns
mndvis = np.nan_to_num([ndvi.mean() for ndvi in ndvis])
plt.figure(figsize=(12,8))
sns.distplot(mndvis)
plt.title('distribution of mean NDVIs')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment