def find_palms2(uid,fieldid, templateName): import pandas as pd import numpy as np import rasterio import matplotlib.pyplot as plt from scipy import ndimage as ndi from skimage.feature import peak_local_max from skimage import exposure import cv2 templateName = 'template.png' filename = uid + '/highres_' +str(fieldid)+'.png' # loading the image - let's take a look at it img = cv2.imread(filename) #affine = img.transform p2, p98 = np.percentile(img, (2, 98)) img_rescale = exposure.rescale_intensity(img, in_range=(p2, p98)) image_max = ndi.maximum_filter(img, size=3, mode='constant') coordinates = peak_local_max(img, min_distance=2) X=coordinates[:, 1] y=coordinates[:, 0] #reproject data array into original dataset xs, ys = X, y # create some datasheet df = pd.DataFrame({'X':xs, 'Y':ys}) # count trees count = df['X'].count() print('Total trees : {i}'.format(i = count)) # also let's see how the countours are selected by plotting countours on the actual image.!! plt.axis('off') plt.imshow(img_rescale) #plt.show() fileName = uid +'/' + fieldid + '_highres_num.png' plt.savefig(fileName) return count