Hello,
I’m trying to remove the background from a dataset of leaves, during my research I found out this paper that describes the steps to extract the plant with respect to the background as below.
However, I cannot understand how to check if the pixel of If(x,y) is at the edge of Id.
So far, I have implement the previous steps:
import numpy as np
import cv2
import skimage.morphology as morph
image = cv2.imread(filename)
height, width, _ = image.shape
Ihsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
Is = Ihsv[:,:,2]
#Apply Spacial Gaussian Filter
trunc_val = 2
sigma_val = 2
k_size = int(sigma_val * trunc_val)
Ifg = cv2.GaussianBlur(Is, (k_size,k_size), sigma_val)
A = np.zeros((height, width), dtype=np.uint8)
for h in range(0, height):
for w in range(0, width):
if Ifg[h, w] > 0.23:
A[h, w] = 1
#Apply Morphological Operations
kernelD2 = morph.diamond(2)
kernelD3 = morph.diamond(3)
Ie = cv2.erode(A, kernelD2)
Id = cv2.dilate(Ie, kernelD3)
It would be so nice, if someone can help me.
Best Regards.
Tarcísio