A Growing Interest: Using Image Processing for Smart Agriculture

Agriculture is one of the key contributors to economies that have arable land to its resources. In this time that most industries are integrating smart technologies, agriculture cannot be left behind. I come from a country and a community where agriculture is the foundation to development thus talking about smart agriculture is close to my heart.
This article will discuss a simple way how we can use image processing to aid in smart agriculture. Specifically, we will try to localize crop trees to aid farmers in monitoring them by using morphological operations and blob detection. We will try it out with this specific image of a small farm in North Cotabato, Philippines:

First, we get differentiable features from the satellite image by performing morphological operations after we’ve transformed the image from RGB to gray:
from skimage.io import imread, imshow
from skimage.color import rgb2gray
import matplotlib.pyplot as pltplt.figure(dpi=200)
farm = rgb2gray(imread('farm.jpg'))
imshow(farm);

It looks like the best features to use for our purposes are the shadows. Personally, I prefer to work with white values rather than 0 values. Thus, we pass it through a threshold and any values that should pass the threshold will be converted to white values:
plt.figure(dpi=200)
farm_th = 1.0 * (farm < 0.25)
imshow(farm_th,cmap='gray');

For our morphological operations, we do dilation and erosion. We define multiple erosions and dilations as follows:
from skimage.morphology import erosion, dilationdef multi_dil(im,num):
for i in range(num):
im = dilation(im)
return imdef multi_ero(im,num):
for i in range(num):
im = erosion(im)
return im
First, we erode the image to get rid of unnecessary details a dilate for the pixels that remain:
plt.figure(dpi=200)
farm_ed = multi_dil(multi_ero(farm_th,7),5)
imshow(farm_ed);

Then, we use the Difference of Gaussian (DoG) in order to identify the blobs in the image:
from skimage.feature import blob_dog
from math import sqrtblobs_dog = blob_dog(farm_ed, max_sigma=20, min_sigma=15, threshold=.1)
blobs_dog[:, 2] = blobs_dog[:, 2] * sqrt(2)
Finally, we visualize the image with the identified shadows. But since we’re interested with the trees and we know the shadows will all project in one direction, we will just adjust the location of the circles to match the trees as well as enlarge it a little bit to cover the size of the tree:
fig, ax = plt.subplots(figsize = (20,15))
ax.imshow(imread('farm.jpg'), interpolation='nearest', cmap='gray')
index=0
for blob in blobs_dog:
y, x, r = blob
c = plt.Circle((x+25, y+25), r*1.3, color="blue", linewidth=2, fill=False)
ax.add_patch(c)
ax.text(x, y, f'{index}', c="white")
index += 1

So, there, trees identified. Farmer can use such detection to aid drones, for example in localizing which tree they want checked.
Additionally, one might say that a couple of trees weren’t identified at all. If I were the farmer, I would conclude that the trees have not grown tall enough to create a shadow. So, either the farmer can help these trees further grow as it might affect their produce.
What I like about this method is that, sometimes, we don’t have to use the object itself to identify it. Rather, we can use their different “effects” on their environment as well.