Exemple #1
0
    #print('3',three)

    #total pixel count
    total = len(pix_val)

    #Percentage of each value
    a = (five * 100 / total)
    b = (seven * 100 / total)
    c = (four * 100 / total)
    d = (three * 100 / total)
    if (a + c == 100 or a + c == 99):
        print("Good")

    if ((a > c > d > b or a > d > c > b)):
        sd_file = os.path.join(sd_dir2, os.path.basename(in_file))
        raster.WriteRaster(reading, sd_file)
        print(sd_file)
    elif (c > a > d > b or c > d > a > b):
        sd_file = os.path.join(sd_dir2, os.path.basename(in_file))
        raster.WriteRaster(reading, sd_file)
        print(sd_file)
    elif (d > a > c > b or d > c > a > b):
        sd_file = os.path.join(sd_dir2, os.path.basename(in_file))
        raster.WriteRaster(reading, sd_file)
        print(sd_file)

    elif (c > b > a):
        sd_file = os.path.join(sd_dir2, os.path.basename(in_file))
        raster.WriteRaster(reading, sd_file)
        print(sd_file)
    elif (a > b > c):
in_files.sort()
sd_dir = "/home/pavithra/Desktop/Rasterimages/NEW_SD/SD_B12"

for in_file in in_files:
    r_band = raster.ReadRaster(in_file)
    data = r_band.data

    out_sd = ndimage.generic_filter(data, np.var, size=3)**0.5

    sd_file = os.path.join(sd_dir, os.path.basename(in_file))

    r_band_sd = raster.Raster(out_sd,
                              extent=r_band.extent,
                              projection=r_band.projection)

    raster.WriteRaster(r_band_sd, sd_file)

    print(sd_file)

#Applying Guassian filter

in_dirtwo = "/home/pavithra/Desktop/Rasterimages/NEW_SD/SD_B12/*.tif"
in_filestwo = glob.glob(in_dirtwo)
in_filestwo.sort()
sd_dirtwo = "/home/pavithra/Desktop/Rasterimages/NEW_Sharpened_data/B12"

for in_file in in_filestwo:
    r_bandtwo = raster.ReadRaster(in_file)
    datatwo = r_bandtwo.data

    blurred_f = ndimage.gaussian_filter(datatwo, 2)
im = raster.ReadRaster(
    '/home/pavithra/Desktop/Rasterimages/NEW_Feature_data/B02/T14QQF_20181220T165719_B02_10m.tif'
)

sd_dir = "/home/pavithra/Desktop/Satyukt"

data = im.data

print(data[1][2])

print(data.shape)

#955 is the number of pixels in row and 1190 in the column

for i in range(0, 955):
    for j in range(0, 1190):
        if (data[i][j] <= 65):
            data[i][j] = 255
        else:
            data[i][j] = 0

print(data)

sd_file = os.path.join(sd_dir, os.path.basename('20th Dec 2018_B2.tif'))

r_band_sd = raster.Raster(data, extent=im.extent, projection=im.projection)

raster.WriteRaster(r_band_sd, sd_file)
print(sd_file)
    for ik_file in sd_files:
        one = os.path.basename(in_file)
        on = one.rsplit('_',2)
        two = os.path.basename(ik_file)
        tw = two.rsplit('_',2)
        if(on[0] == tw[0]):
           r_band = raster.ReadRaster(ik_file)
           data = r_band.data
           #data1 = r_band.astype(np.uint8)
           for i in range(len(data)):
               for j in range(len(data[0])):
                   if(data[i,j]>3000):
                      data[i,j] = np.nan
                   else:
                      data[i,j] = data[i,j]
          
           sd_file = os.path.join(sd_datacc, os.path.basename(ik_file))
           r_band_cc = raster.Raster(data, extent=r_band.extent, projection=r_band.projection)
           raster.WriteRaster(r_band_cc, sd_file)
           print(sd_file)                          
        else:
           print('file not matched')