完成选择类滤波器

master
charlie 4 years ago
parent 06c1ca4926
commit ea761245b7

@ -965,6 +965,50 @@ def process_median_sort(img):
return output
def process_high_choice(img, limit):
output = np.zeros(img.shape, np.uint8)
for i in range(img.shape[0]):
for j in range(img.shape[1]):
if img[i][j] > limit:
output[i][j] = img[i][j]
else:
output[i][j] = 0
return output
def process_low_choice(img, limit):
output = np.zeros(img.shape, np.uint8)
for i in range(img.shape[0]):
for j in range(img.shape[1]):
if img[i][j] < limit:
output[i][j] = img[i][j]
else:
output[i][j] = 0
return output
def process_pass_choice(img, min, max):
output = np.zeros(img.shape, np.uint8)
for i in range(img.shape[0]):
for j in range(img.shape[1]):
if min < img[i][j] < max:
output[i][j] = img[i][j]
else:
output[i][j] = 255
return output
def process_stop_choice(img, min, max):
output = np.zeros(img.shape, np.uint8)
for i in range(img.shape[0]):
for j in range(img.shape[1]):
if min < img[i][j] < max:
output[i][j] = 0
else:
output[i][j] = img[i][j]
return output
@csrf_exempt
def filtration(request):
if request.method == 'POST':
@ -987,6 +1031,21 @@ def filtration(request):
img = process_median_sort(img)
elif detail_type == 'min':
img = process_min_sort(img)
elif op == 'choice':
if detail_type == 'low':
limit = para.get('limit', 20)
img = process_low_choice(img, limit)
elif detail_type == 'high':
limit = para.get('limit', 200)
img = process_high_choice(img, limit)
elif detail_type == 'pass':
min_r = para.get('min', 20)
max_r = para.get('max', 200)
img = process_pass_choice(img, min_r, max_r)
elif detail_type == 'stop':
min_r = para.get('min', 20)
max_r = para.get('max', 200)
img = process_stop_choice(img, min_r, max_r)
filename = getImageName() + DEFAULT_FORMAT
cv2.imwrite(PREFIX + filename, img)
return HttpResponse(filename)

Loading…
Cancel
Save