-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPolarHeightFilter.py
34 lines (27 loc) · 1.07 KB
/
PolarHeightFilter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import cv2
import numpy as np
class PolarHeightFilter:
@staticmethod
def filterHeight(inputImage, threshold = 30):
'''
filter the area whose height is less than the threshold
'''
height = inputImage.shape[0]
width = inputImage.shape[1]
blackColor = np.zeros((1, 3), np.uint8)
for i in xrange(width):
prevColor = blackColor
currentColor = inputImage[height - 1, i, :]
currentHeight = 0
for j in reversed(xrange(height)):
if inputImage[j, i, :].all() == currentColor.all():
currentHeight += 1
else:
if currentHeight < threshold and prevColor.all() != blackColor.all():
print j, i, currentHeight
for k in xrange(j - currentHeight, j):
inputImage[k, i] = prevColor
prevColor = currentColor
currentColor = inputImage[j, i, :]
currentHeight = 1
return inputImage