Commit 28120d50 authored by luroth's avatar luroth
Browse files

processing of missing images

parent 1104c92d
......@@ -168,58 +168,59 @@ class Workflow():
image_paths[image_name] = image_path
# Job and results queue
m = Manager()
jobs = m.Queue()
results = m.Queue()
processes = []
# Progress bar counter
max_jobs = len(image_paths)
count = 0
# Build up job queue
for image_name, image_path in image_paths.items():
print(image_name, "to queue")
job = dict()
job['image_name'] = image_name
job['image_path'] = image_path
jobs.put(job)
# Init progress bar
progress = ProgressBar(min_value=0, max_value=max_jobs)
# Start processes, number of CPU - 1 to have some left for main thread / OS
number_of_cpu = multiprocessing.cpu_count() - 1
for w in range(number_of_cpu):
p = Process(target=prepare_descriptor_worker,
args=(jobs, results, self.read_raw_func, self.enhanced_raw_func,
self.preview_func,
self.path_workspace_descriptors,
self.path_workspace_previews,
self.border_pixels))
p.daemon = True
p.start()
processes.append(p)
jobs.put('STOP')
print("jobs all started")
progress.update(0)
# Get results and increment counter with it
while count < (max_jobs):
descriptor_names = results.get()
progress.update(count)
count += 1
progress.finish()
for p in processes:
p.join()
np.save(self.path_workspace_descriptors / ('descriptor_names.npy'),descriptor_names)
if len(image_paths)>0:
# Job and results queue
m = Manager()
jobs = m.Queue()
results = m.Queue()
processes = []
# Progress bar counter
max_jobs = len(image_paths)
count = 0
# Build up job queue
for image_name, image_path in image_paths.items():
print(image_name, "to queue")
job = dict()
job['image_name'] = image_name
job['image_path'] = image_path
jobs.put(job)
# Init progress bar
progress = ProgressBar(min_value=0, max_value=max_jobs)
# Start processes, number of CPU - 1 to have some left for main thread / OS
number_of_cpu = multiprocessing.cpu_count() - 1
for w in range(number_of_cpu):
p = Process(target=prepare_descriptor_worker,
args=(jobs, results, self.read_raw_func, self.enhanced_raw_func,
self.preview_func,
self.path_workspace_descriptors,
self.path_workspace_previews,
self.border_pixels))
p.daemon = True
p.start()
processes.append(p)
jobs.put('STOP')
print("jobs all started")
progress.update(0)
# Get results and increment counter with it
while count < (max_jobs):
descriptor_names = results.get()
progress.update(count)
count += 1
progress.finish()
for p in processes:
p.join()
np.save(self.path_workspace_descriptors / ('descriptor_names.npy'),descriptor_names)
def init_images(self):
df_images = pd.DataFrame()
......@@ -257,9 +258,12 @@ class Workflow():
df_images = df_images.append(images_data, ignore_index=True)
df_images.set_index('id')
if len(df_images)>0:
df_images.set_index('id')
self.df_images = df_images
self.df_images = df_images
else:
self.df_images = None
def init_sample_masks(self):
......@@ -620,36 +624,39 @@ class Workflow():
print("Done")
def segment_images(self):
if self.df_images is not None:
# iterate over images
for index, row in self.df_images.iterrows():
# iterate over images
for index, row in self.df_images.iterrows():
tic = timeit.default_timer()
tic = timeit.default_timer()
image = row
print("Predict " + image.at['image_name'])
image = row
print("Predict " + image.at['image_name'])
# load numpy array
print("Load...", end="")
enhanced_raw = np.load(self.path_workspace_descriptors / (image.at['image_name'] + '.npy'))
mask = np.load(self.path_workspace_descriptors / (image.at['image_name'] + '_mask.npy'))
print(timeit.default_timer() - tic, "seconds")
# load numpy array
print("Load...", end="")
enhanced_raw = np.load(self.path_workspace_descriptors / (image.at['image_name'] + '.npy'))
mask = np.load(self.path_workspace_descriptors / (image.at['image_name'] + '_mask.npy'))
print(timeit.default_timer() - tic, "seconds")
print("Predict...", end="")
# Round to 0 (soil) or 1 (plants)
image_seg = self.clf.predict(enhanced_raw.reshape(-1, enhanced_raw.shape[-1])).reshape((enhanced_raw.shape[0], enhanced_raw.shape[1]))
print(timeit.default_timer() - tic, "seconds")
print("Predict...", end="")
# Round to 0 (soil) or 1 (plants)
image_seg = self.clf.predict(enhanced_raw.reshape(-1, enhanced_raw.shape[-1])).reshape((enhanced_raw.shape[0], enhanced_raw.shape[1]))
print(timeit.default_timer() - tic, "seconds")
print("Postrocess...", end="")
image_seg = np.uint8(np.round(image_seg) * 255)
image_seg = np.ma.masked_array(image_seg, mask, fill_value=128).filled()
print(timeit.default_timer() - tic, "seconds")
print("Postrocess...", end="")
image_seg = np.uint8(np.round(image_seg) * 255)
image_seg = np.ma.masked_array(image_seg, mask, fill_value=128).filled()
print(timeit.default_timer() - tic, "seconds")
print("Save...", end="")
imageio.imsave(self.path_workspace_predicts / (image.at['image_name'] + '_predict.tif'), image_seg)
print(timeit.default_timer() - tic, "seconds")
print("Save...", end="")
imageio.imsave(self.path_workspace_predicts / (image.at['image_name'] + '_predict.tif'), image_seg)
print(timeit.default_timer() - tic, "seconds")
print("Done")
print("Done")
else:
print("No images to segment")
def predict_image(self, args):
......
......@@ -345,10 +345,14 @@ def zonal_stat(output_path, band_index, raster_path=None, raster_ds=None, shape_
# Read raster as arrays
dataraster = None
i = 1000
while (dataraster is None) and i>0:
if (dataraster is None):
dataraster = raster_band.ReadAsArray(xoff, yoff, xcount, ycount)
i -= 1
if (dataraster is None):
print("skipping plot, not readable:", plot_label)
continue
# Create mask of plot
# Create coordinate matrix to check if image pixel in plot polygon
east = np.linspace(xmin_inc_border, xmin_inc_border + dataraster.shape[0] * pixelWidth, dataraster.shape[1])
......
......@@ -2,7 +2,7 @@ from GroundAerialCoverage import CanopyAnalysis
from pathlib import Path
path_p = Path("P:")
path_p = Path("/home/luroth/public")
#path_p = Path("/home/luroth/public")
if __name__ == "__main__":
......@@ -19,4 +19,4 @@ if __name__ == "__main__":
if int(campaign_date) <= 20180420:
print("Processing", campaign_date)
CanopyAnalysis.process_NadirCC_LCCC_LA_AI(path_campaign, campaign_date, GSD)
\ No newline at end of file
CanopyAnalysis.process_NadirCC_LCCC_LA_AI(path_campaign, GSD)
\ No newline at end of file
......@@ -3,7 +3,7 @@ from pathlib import Path
if __name__ == "__main__":
dates = [
dates_done = [
'20190322',
'20190324',
'20190327',
......@@ -27,6 +27,10 @@ if __name__ == "__main__":
'20181112'
]
dates = [
'20190422',
'20190501']
for date in dates:
......@@ -42,9 +46,11 @@ if __name__ == "__main__":
subplots = 20
buffer = 0
'''
GroundAerialCoverageSegmentation.process_multiview_images_generation(path_processed, design_label, nx=nx, ny=ny,
subplots=subplots, buffer=buffer, rmdest=True)
GroundAerialCoverageSegmentation.process_CC_AC_calc(path_processed, design_label)
'''
# Others
......@@ -62,6 +68,7 @@ if __name__ == "__main__":
GroundAerialCoverageSegmentation.process_multiview_images_generation(path_processed, design_label, nx=nx, ny=ny , subplots=None, buffer=buffer)
GroundAerialCoverageSegmentation.process_CC_AC_calc(path_processed, design_label)
'''
# small plots:
design_labels = ['FPWW025_lot2', 'FPWW026_lot2', 'FPWW027_lot2', 'FPWW028_lot2', 'FPWW029_lot2', 'FPWWE03_lot2']
......@@ -76,3 +83,5 @@ if __name__ == "__main__":
GroundAerialCoverageSegmentation.process_multiview_images_generation(path_processed, design_label, nx=nx, ny=ny , subplots=None, buffer=buffer)
GroundAerialCoverageSegmentation.process_CC_AC_calc(path_processed, design_label)
'''
\ No newline at end of file
......@@ -65,6 +65,10 @@ if __name__ == "__main__":
r'O:\UAV\_Processed_\ETHZ_eschikon_FPWW024_lot2\20190415\28m_M600P',
r'O:\UAV\_Processed_\ETHZ_eschikon_FPWW024_lot2\20190418\28m_M600P']
paths = [
r'O:\UAV\_Processed_\ETHZ_eschikon_FPWW024_lot2\20190422\28m_M600P',
r'O:\UAV\_Processed_\ETHZ_eschikon_FPWW024_lot2\20190501\28m_M600P']
for path in paths:
print("Process", path)
......
......@@ -84,9 +84,12 @@ if __name__ == '__main__':
'20190409',
'20190412',
'20190415',
'20190418'
'20190418',
'20190422',
'20190501'
]
for date in dates:
process(date)
\ No newline at end of file
......@@ -3,7 +3,7 @@ from pathlib import Path
if __name__ == "__main__":
dates = [
dates_done = [
'20190228',
'20190306',
'20190313',
......@@ -25,6 +25,10 @@ if __name__ == "__main__":
'20190226'
]
dates = [
'20190422',
'20190501']
for date in dates:
......@@ -47,6 +51,7 @@ if __name__ == "__main__":
GroundAerialCoverageSegmentation.process_multiview_images_generation(path_processed, design_label, nx=nx, ny=ny , subplots=None, buffer=buffer)
'''
# Small plots
design_labels = ['FPWW025_lot4', 'FPWW026_lot4', 'FPWW027_lot4', 'FPWW028_lot4', 'FPWW029_lot4', 'FPWWE03_lot4']
......@@ -60,3 +65,5 @@ if __name__ == "__main__":
ny, nx = (round((2 - (2 * 0.3)) / GSD_output), round((1.5 - (2 * 0.3)) / GSD_output))
GroundAerialCoverageSegmentation.process_multiview_images_generation(path_processed, design_label, nx=nx, ny=ny , subplots=None, buffer=buffer)
'''
\ No newline at end of file
......@@ -68,6 +68,10 @@ if __name__ == "__main__":
paths = [
r'O:\UAV\_Processed_\ETHZ_eschikon_FPWW024_lot4\20181105\28m_M600P']
paths = [
r'O:\UAV\_Processed_\ETHZ_eschikon_FPWW024_lot4\20190422\28m_M600P',
r'O:\UAV\_Processed_\ETHZ_eschikon_FPWW024_lot4\20190501\28m_M600P']
for path in paths:
print("Process", path)
......
......@@ -86,9 +86,10 @@ if __name__ == '__main__':
'20190215',
'20190219',
'20190222',
'20190226'
'20190226',
'20190422',
'20190501'
]
for date in dates:
process(date)
\ No newline at end of file
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