To receive notifications about scheduled maintenance, please subscribe to the mailing-list gitlab-operations@sympa.ethz.ch. You can subscribe to the mailing-list at https://sympa.ethz.ch

Commit f95f3afb authored by luroth's avatar luroth
Browse files

leaf extraction improvement

parent b57c21f7
......@@ -211,16 +211,22 @@ def extract_for_plot(plot_UID, path_plot_images, path_plot_shapes, path_output,
# axs[1].imshow(skeleton_pruned)
# draw.overlay_euclidean_skeleton_2d(skeleton_pruned, branch_data_orig[is_in_poly>0], skeleton_color_source='branch-type', axes=axs[2])
number_of_isolated_branches = np.sum(branch_data['branch_type'] == 0)
number_of_skeleton_branches = np.sum(branch_data['branch_type'] == 1)
number_of_skeleton_segments = np.sum(branch_data['branch_type'] == 2)
leaf_length_total = branch_data_for_type['branch_distance'].sum()
no_of_leaves = leaf_length_total / leaf_length_median
no_of_leaves = 0 if np.isnan(no_of_leaves) else no_of_leaves
df_.loc[df_['type']==type, "LL_total"] = leaf_length_total
df_.loc[df_['type']==type, "LL_per_leaf"] = leaf_length_median
df_.loc[df_['type']==type, "no_leaves"] = no_of_leaves
df_.loc[df_['type'] == type, "no_of_leaves"] = no_of_leaves
df_.loc[df_['type']==type, "number_of_isolated_branches"] = number_of_isolated_branches
df_.loc[df_['type'] == type, "number_of_skeleton_branches"] = number_of_skeleton_branches
df_.loc[df_['type'] == type, "number_of_skeleton_segments"] = number_of_skeleton_segments
print("Type: " + type)
print("No. of leaves: " + str(float(df_['no_leaves'][df_['type']==type])))
print("Total leaf length: " + str(float(df_['LL_total'][df_['type']==type])))
dfs.append(df_)
......
......@@ -49,7 +49,7 @@ path_segmented_images = Path("_TestData/canon_EOS_5D_II/2018/Plots")
def detect_and_write_plot_shape(path_segmented_images, date, path_output, path_seg_sticks=False):
images = sorted([a for a in path_segmented_images.glob("*" + date + ".tif")])
images = sorted([a for a in path_segmented_images.glob("*" + date + ".tif")], reverse=True)
for image in images:
detect_and_write_plot_shape_for_image(path_segmented_images, image, path_output, path_seg_sticks)
......
# Author: Lukas Roth, lukas.roth@usys.ethz.ch
# load packages
import math
from collections import Counter
import imageio
import rawpy
import numpy as np
import pandas as pd
import geopandas as gpd
import matplotlib as mpl
from matplotlib import path
from matplotlib.patches import Polygon
from matplotlib.collections import PatchCollection
from Common import GISfunctions
#mpl.use('Qt5Agg')
mpl.use('TkAgg')
from matplotlib import pyplot as plt
from pathlib import Path
from skimage import color
from skimage import exposure
import exifread
import cv2
import shapely
from multiprocessing import Process, Manager
from Common import Imagefunctions
PLOT_W = 1000
PLOT_L = 1500
plt.interactive(False)
# Main processing function
def manual_reference_sticks(plot_UID, path_image_folders,
date,
path_output):
# Get paths to RAW images
print(plot_UID + ":: " + "==============================================================")
print(plot_UID + ":: " + "Search images for plot " + plot_UID)
path_image = path_image_folders / (plot_UID + "_" + date + ".tif")
# Extract name and date
image_name = path_image.name[:-4]
image_date = date
print(plot_UID + ":: " + "Image " + image_name, " found")
# Get 8bit image
a_RGB_8bit = imageio.imread(path_image)
fig, ax = plt.subplots()
ax.imshow(a_RGB_8bit)
if (path_output / (plot_UID + "_" + image_date + "_sticks.csv")).exists():
df_all = pd.read_csv(path_output / (plot_UID + "_" + image_date + "_sticks.csv"))
ax.scatter('X_stick', 'Y_stick', data=df_all, marker='+', color='white',
s=50)
plt.interactive(True)
plt.show(block=True)
plt.interactive(False)
return (True)
fig.canvas.toolbar.push_current()
tb = plt.get_current_fig_manager().toolbar
points_ref_list = []
# Function to capture plot corner coordinates
def get_corner(event):
if tb.mode == '':
# On left mouse click (button==1)
if event.button == 1:
if event.inaxes is None:
return(0)
# Add point coordinates to list
points_ref_list.append([event.xdata, event.ydata])
# Add point to plot
fig.canvas.draw()
ax.scatter('x', 'y', data=pd.DataFrame({'x': [event.xdata], 'y': [event.ydata]}), marker='+', color='white',
s=50)
ax.text(event.xdata+10, event.ydata+10, len(points_ref_list))
fig.canvas.toolbar.push_current()
ax.set_title(plot_UID)
# Handler mouse click events
fig.canvas.mpl_connect('button_press_event', get_corner)
# Start GUI
figManager = plt.get_current_fig_manager()
#figManager.window.state('zoomed')
figManager.resize(*figManager.window.maxsize())
fig.canvas.manager.set_window_title(plot_UID)
plt.interactive(True)
plt.show(block=True)
plt.interactive(False)
if len(points_ref_list) == 2:
df_src = pd.DataFrame(points_ref_list, columns=("X_stick", "Y_stick"))
df_src.to_csv(path_output / (plot_UID + "_" + image_date + "_sticks.csv"))
return(True)
else:
print(plot_UID + ":: " + "Number of marked corners not correct")
return(False)
if __name__ == "__main__":
print("Test run")
path_public = Path("P:/")
path_public = Path("/home/luroth/public")
path_images_folder = path_public / "Evaluation" / "FIP" / "Analysis" / "2019" / "WW024" / "RGB_Referencing" / "processed"
path_output = path_public / "Evaluation" / "FIP" / "Analysis" / "2019" / "WW024" / "RGB_Referencing" / "stick_shapes"
plot_numbers = sorted(np.arange(36, 72+1), reverse=True)
plot_UIDs = ["FPWW024{:04d}".format(nr) for nr in plot_numbers]
for plot_UID in plot_UIDs:
manual_reference_sticks(path_image_folders=path_images_folder, plot_UID = plot_UID, date = "20181105", path_output=path_output)
\ No newline at end of file
Markdown is supported
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