|
|
|
|
@ -10,6 +10,7 @@ from django.http import HttpResponse
|
|
|
|
|
from django.shortcuts import render
|
|
|
|
|
# Create your views here.
|
|
|
|
|
from django.views.decorators.csrf import csrf_exempt
|
|
|
|
|
from pywt import dwt2, idwt2
|
|
|
|
|
|
|
|
|
|
PREFIX = 'media/'
|
|
|
|
|
|
|
|
|
|
@ -1052,5 +1053,35 @@ def filtration(request):
|
|
|
|
|
return HttpResponse('请使用POST方法')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@csrf_exempt
|
|
|
|
|
def wavelet(request):
|
|
|
|
|
if request.method == 'POST':
|
|
|
|
|
para = json.loads(request.body)
|
|
|
|
|
image = para['img']
|
|
|
|
|
img = cv2.imread(PREFIX + image, 0)
|
|
|
|
|
# 对img进行haar小波变换:
|
|
|
|
|
cA, (cH, cV, cD) = dwt2(img, 'haar')
|
|
|
|
|
# 小波变换之后,低频分量对应的图像:
|
|
|
|
|
low_name = getImageName() + DEFAULT_FORMAT
|
|
|
|
|
cv2.imwrite(PREFIX + low_name, np.uint8(cA / np.max(cA) * 255))
|
|
|
|
|
# 小波变换之后,水平方向高频分量对应的图像:
|
|
|
|
|
horizontal_high_name = getImageName() + DEFAULT_FORMAT
|
|
|
|
|
cv2.imwrite(PREFIX + horizontal_high_name, np.uint8(cH / np.max(cH) * 255))
|
|
|
|
|
# 小波变换之后,垂直平方向高频分量对应的图像:
|
|
|
|
|
vertical_high_name = getImageName() + DEFAULT_FORMAT
|
|
|
|
|
cv2.imwrite(PREFIX + vertical_high_name, np.uint8(cV / np.max(cV) * 255))
|
|
|
|
|
# 小波变换之后,对角线方向高频分量对应的图像:
|
|
|
|
|
diagonal_high_name = getImageName() + DEFAULT_FORMAT
|
|
|
|
|
cv2.imwrite(PREFIX + diagonal_high_name, np.uint8(cD / np.max(cD) * 255))
|
|
|
|
|
# 根据小波系数重构回去的图像
|
|
|
|
|
rimg = idwt2((cA, (cH, cV, cD)), 'haar')
|
|
|
|
|
refactor_name = getImageName() + DEFAULT_FORMAT
|
|
|
|
|
cv2.imwrite(PREFIX + refactor_name, np.uint8(rimg))
|
|
|
|
|
ret = [{"low": low_name, "horizontal_high": horizontal_high_name, "vertical_high": vertical_high_name,
|
|
|
|
|
"diagonal_high": diagonal_high_name, "refactor": refactor_name}]
|
|
|
|
|
return HttpResponse(ret)
|
|
|
|
|
return HttpResponse('请使用POST方法')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def r(request):
|
|
|
|
|
return render(request, 'upload.html')
|
|
|
|
|
|