Python Forum
Automate the calculus of NDVI index on a 100 images
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Automate the calculus of NDVI index on a 100 images
#1
Hello.
I want to automate this code below for other 99 images, the problem that I have is that each image is in its specific folder as it's mentioned in the picture below.[Image: MpG3ZxS] the images are very big and I want to clip them in a specific area, is that possible to make it automatic also ?
import rasterio
import os
from rasterio import plot
import matplotlib.pyplot as plt
import numpy as np

os.chdir(r'Z:\New folder\S2\L1C_T29SPR_A003995_20160328T111353_2016-03-28\New folder\CLIP')

band4 = rasterio.open(r'Z:\New folder\S2\L1C_T29SPR_A003995_20160328T111353_2016-03-28\New folder\CLIP\clip_RT_L1C_T29SPR_A003995_20160328T111353_B04.tif') #red
band5 = rasterio.open(r'Z:\New folder\S2\L1C_T29SPR_A003995_20160328T111353_2016-03-28\New folder\CLIP\clip_RT_L1C_T29SPR_A003995_20160328T111353_B08.tif') #nir

plot.show(band5)
band4.dtypes

red = band4.read(1).astype('float32')
nir = band5.read(1).astype('float32')

ndvi=np.where(
    (nir+red)==0.,
    0,
    (nir-red)/(nir+red))
ndvi[:5,:5]

plot.show(ndvi)
plt.colorbar (ndvi) #I have also a problem with colorbar as it didn't show properly
Thank you
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  1. How can I automate this batch creation of documents? 2. How can I automate posting SamLearnsPython 2 3,423 Jul-02-2018, 11:36 AM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020