import cv2
from matplotlib import *
from pylab import *
i = cv2.imread('C:/Users/fouza/OneDrive/Bureau/stage_pfe/data/test1.PNG')
# Function to map each intensity level to output intensity level.
def pixelVal(pix, r1, s1, r2, s2):
if (0 <= pix and pix <= r1):
return (s1 / r1)*pix
elif (r1 < pix and pix <= r2):
return ((s2 - s1)/(r2 - r1)) * (pix - r1) + s1
else:
return ((255 - s2)/(255 - r2)) * (pix - r2) + s2
pixelVal_vec = np.vectorize(pixelVal)
r1 = 126
s1 = 0
r2 = 120
s2 = 255
img = pixelVal_vec(i, r1, s1, r2, s2)
imshow(img)
This is the initial image.
This is the segmentation of my main image.
As you can see I want to calculate the number of palm trees in the image. But the problem is that I have in zones several palm trees grouped together so I can not work with the area of the zones.