Commit cb41c453 authored by luroth's avatar luroth
Browse files

.

parent 3f078248
...@@ -9,6 +9,7 @@ import math ...@@ -9,6 +9,7 @@ import math
import stl.base as stl import stl.base as stl
import numpy as np import numpy as np
from matplotlib import path from matplotlib import path
from osgeo import gdal
DELTA_x = 2693000 DELTA_x = 2693000
DELTA_y = 1256000 DELTA_y = 1256000
...@@ -96,3 +97,18 @@ def point_in_poly(x,y,poly): ...@@ -96,3 +97,18 @@ def point_in_poly(x,y,poly):
p1x,p1y = p2x,p2y p1x,p1y = p2x,p2y
return inside return inside
def create_GeoTiff(file_path, array, data_type):
driver = gdal.GetDriverByName('GTiff')
file = file_path + '.tif'
ds = driver.Create( file, array.shape[0], array.shape[1], 1, data_type)
band_1 = ds.GetRasterBand(1)
band_1.WriteArray(array)
band_1.SetNoDataValue(0)
ds = None
return file_path
...@@ -19,6 +19,8 @@ import sys ...@@ -19,6 +19,8 @@ import sys
import getopt import getopt
import csv import csv
from scipy import ndimage from scipy import ndimage
from Common import create_GeoTiff
import gdal
def main(argv): def main(argv):
camera_position_file = '' camera_position_file = ''
...@@ -76,19 +78,28 @@ def main(argv): ...@@ -76,19 +78,28 @@ def main(argv):
b= np.divide(B, (np.mean(R)+np.mean(G)+np.mean(B)), dtype=float) b= np.divide(B, (np.mean(R)+np.mean(G)+np.mean(B)), dtype=float)
ExG = 2* g - r - b ExG = 2* g - r - b
ExR = 1.4 * r - b
misc.imsave(os.path.join(output_directory, PhotoID + '_ExG.tif'), ExG.reshape(origin_shape[0], origin_shape[1])) misc.imsave(os.path.join(output_directory, PhotoID + '_ExG.tif'), ExG.reshape(origin_shape[0], origin_shape[1]))
misc.imsave(os.path.join(output_directory, PhotoID + '_ExR.tif'), ExR.reshape(origin_shape[0], origin_shape[1]))
ExG_soil = ExG[image_mask_soil==1] ExG_ExR = ExG - ExR
print(ExG_soil.size)
if ExG_soil.size ==0:
continue
ExG_threshold = np.percentile(ExG_soil, 99.95) plants = np.array(ExG_ExR>0)
soil = np.array(ExG > ExG_threshold) #gdalnumeric.SaveArray(1*(plants.reshape(origin_shape[0], origin_shape[1])), os.path.join(output_directory, PhotoID + '_segmented_ExG_ExR.tif'), format='GTiff')
create_GeoTiff(os.path.join(output_directory, PhotoID + '_segmented_ExG_ExR', ExG_ExR, gdal.GDT_Byte)
gdalnumeric.SaveArray(1*(soil.reshape(origin_shape[0], origin_shape[1])), os.path.join(output_directory, PhotoID + '_segmented_ExG.tif'), format='GTiff') #ExG_soil = ExG[image_mask_soil==1]
#print(ExG_soil.size)
#if ExG_soil.size ==0:
# continue
#ExG_threshold = np.percentile(ExG_soil, 99.95)
#soil = np.array(ExG > ExG_threshold)
#gdalnumeric.SaveArray(1*(soil.reshape(origin_shape[0], origin_shape[1])), os.path.join(output_directory, PhotoID + '_segmented_ExG.tif'), format='GTiff')
#misc.imsave(os.path.join(output_directory, PhotoID + '_segmented_ExG.tif'), soil.reshape(origin_shape[0], origin_shape[1])) #misc.imsave(os.path.join(output_directory, PhotoID + '_segmented_ExG.tif'), soil.reshape(origin_shape[0], origin_shape[1]))
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment