Tree / Crop Counting and Classification with Python and Scikit-Image - Tutorial

Cropcounting2.png

Lately there has been a wide source of spatial photogrametry available for agriculture. Available submetric images can be found in Google Earth, and drone images can increase the ortophoto resolution to the order of centimeters. Most of this data gives us a new perspective of the spatial distribution and stage of the crops, however a real spatial analysis of crop metrics have not been widely performed due to limitations on the images and software involved. 

Right now we live in a world of emerging technologies where new machine learning and artificial intelligence software is being launched every year at not cost. Even for profesional in the field of spatial analysis it is difficult to track the latest developments in software. Every time you search in Google, Twitter or other sources you will find something new and more important, something useful.

We tried to make this tutorial with the popular library OpenCV, however the installation process was tedious in Windows. Then we shifted to Scikit-Image, a image processing library in Python that comes already installed on the Anaconda software. The process for image analysis required intermediate Python and GIS skills, but most important a strong criteria of the algorithm inputs, options and results.

 

Data processing and analysis

Quality of image interpretation cannot be better than the input images. The input image was a screenshot from Google Earth selected as the most clear photo with the less amount of crop shadows because shadow makes more difficult the image interpretation. Area of study is a olive farm located in Bella Union, Caravelí, Peru. 

The selected tool from Scikit-Image library was Template Matching. This tool identify the ocurrence of a patch in a image. It return a matrix where the maximum value corresponds to the image location. For this tutorial a threshold on the ocurrence value has been adopted to classify the crops in between small, medium, large and extra.

From the results and analysis of this tutorial, as long as the crop is regular and isolated from other parts, the algorithm will work better. There is a special dependency on the crop stage if we deal with temporal crops as pineapple or lettuce. NDVI or infrared images can help and improve the image interpretation.

 

Tutorial

 

Input data

Download the required data for the tutorial on this link.

Saul Montoya

Saul Montoya es Ingeniero Civil graduado de la Pontificia Universidad Católica del Perú en Lima con estudios de postgrado en Manejo e Ingeniería de Recursos Hídricos (Programa WAREM) de la Universidad de Stuttgart con mención en Ingeniería de Aguas Subterráneas y Hidroinformática.

 

Suscribe to our online newsletter

Subscribe for free newsletter, receive news, interesting facts and dates of our courses in water resources.