I'm trying to segment the football field. I'm following a research paper that suggests
- Convert to HSV
- Grab the Hue Channel
- Generate Histogram
- Grab Global and local maxima (Global max can be
max(hist)
) - If a local maxima is of 20% of the Global Maxima, Consider it
The issue is that I don't know how to get Local Maximas. I'm trying to capture a list of peaks in the histogram.
I have tried it on MatLab, it works quite well but I need to do it in python. I have tried libraries like peakutils but nothing is giving me desired results.
def field_area_mask(image):
# Convert to HSV
hsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
# Capture the Hue Channel
hue = hsv[:, :, 0]
# Generate Histogram
hist = cv2.calcHist([hue],[0],None,[256],[0,256])
# Capture range
hist_range = hist[:121] # 0-120
hist_range = hist_range.reshape(1, -1)[0]
Hmax = max(hist_range)
plt.plot(hist_range)
HiMax = [] # Need to populate the local maxima's list