|
|
|
|
@ -729,13 +729,52 @@ def smooth(request):
|
|
|
|
|
d0 = para.get('d0', 20)
|
|
|
|
|
img = filter_use_smooth(img, gauss_low_pass_filter(img, d0))
|
|
|
|
|
else:
|
|
|
|
|
return 0
|
|
|
|
|
size = para['size']
|
|
|
|
|
if filter == 'average':
|
|
|
|
|
img = cv2.blur(img, (size, size))
|
|
|
|
|
elif filter == 'median':
|
|
|
|
|
img = cv2.medianBlur(img, size)
|
|
|
|
|
filename = getImageName() + DEFAULT_FORMAT
|
|
|
|
|
cv2.imwrite(PREFIX + filename, img)
|
|
|
|
|
return HttpResponse(filename)
|
|
|
|
|
return HttpResponse('请使用POST方法')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def process_roberts(img):
|
|
|
|
|
kernelx = np.array([[-1, 0], [0, 1]], dtype=int)
|
|
|
|
|
kernely = np.array([[0, -1], [1, 0]], dtype=int)
|
|
|
|
|
x = cv2.filter2D(img, cv2.CV_16S, kernelx)
|
|
|
|
|
y = cv2.filter2D(img, cv2.CV_16S, kernely)
|
|
|
|
|
# 转uint8
|
|
|
|
|
absX = cv2.convertScaleAbs(x)
|
|
|
|
|
absY = cv2.convertScaleAbs(y)
|
|
|
|
|
return cv2.addWeighted(absX, 0.5, absY, 0.5, 0)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def process_sobel(img):
|
|
|
|
|
x = cv2.Sobel(img, cv2.CV_16S, 1, 0) # 对x求一阶导
|
|
|
|
|
y = cv2.Sobel(img, cv2.CV_16S, 0, 1) # 对y求一阶导
|
|
|
|
|
absX = cv2.convertScaleAbs(x)
|
|
|
|
|
absY = cv2.convertScaleAbs(y)
|
|
|
|
|
return cv2.addWeighted(absX, 0.5, absY, 0.5, 0)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def process_prewitt(img):
|
|
|
|
|
kernelx = np.array([[1, 1, 1], [0, 0, 0], [-1, -1, -1]], dtype=int)
|
|
|
|
|
kernely = np.array([[-1, 0, 1], [-1, 0, 1], [-1, 0, 1]], dtype=int)
|
|
|
|
|
x = cv2.filter2D(img, cv2.CV_16S, kernelx)
|
|
|
|
|
y = cv2.filter2D(img, cv2.CV_16S, kernely)
|
|
|
|
|
# 转uint8
|
|
|
|
|
absX = cv2.convertScaleAbs(x)
|
|
|
|
|
absY = cv2.convertScaleAbs(y)
|
|
|
|
|
return cv2.addWeighted(absX, 0.5, absY, 0.5, 0)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def process_laplacian(img):
|
|
|
|
|
dst = cv2.Laplacian(img, cv2.CV_16S, ksize=3)
|
|
|
|
|
return cv2.convertScaleAbs(dst)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@csrf_exempt
|
|
|
|
|
def sharpen(request):
|
|
|
|
|
if request.method == 'POST':
|
|
|
|
|
@ -757,7 +796,14 @@ def sharpen(request):
|
|
|
|
|
d0 = para.get('d0', 20)
|
|
|
|
|
img = filter_use_sharpen(img, gauss_high_pass_filter(img, d0))
|
|
|
|
|
else:
|
|
|
|
|
return 0
|
|
|
|
|
if filter == 'Roberts':
|
|
|
|
|
img = process_roberts(img)
|
|
|
|
|
elif filter == 'Sobel':
|
|
|
|
|
img = process_sobel(img)
|
|
|
|
|
elif filter == 'Prewitt':
|
|
|
|
|
img = process_prewitt(img)
|
|
|
|
|
elif filter == 'Laplacian':
|
|
|
|
|
img = process_laplacian(img)
|
|
|
|
|
filename = getImageName() + DEFAULT_FORMAT
|
|
|
|
|
cv2.imwrite(PREFIX + filename, img)
|
|
|
|
|
return HttpResponse(filename)
|
|
|
|
|
|