|
|
|
|
@ -2,6 +2,7 @@ import json
|
|
|
|
|
import uuid
|
|
|
|
|
|
|
|
|
|
import cv2
|
|
|
|
|
import matplotlib.pyplot as plt
|
|
|
|
|
import numpy as np
|
|
|
|
|
from django.http import HttpResponse
|
|
|
|
|
from django.shortcuts import render
|
|
|
|
|
@ -402,5 +403,41 @@ def affine(request):
|
|
|
|
|
return HttpResponse('请使用POST方法')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def hist_cover_gray(img, fileName):
|
|
|
|
|
plt.figure(fileName, figsize=(16, 8))
|
|
|
|
|
hist = cv2.calcHist([img], [0], None, [256], [0, 255])
|
|
|
|
|
plt.plot(hist)
|
|
|
|
|
plt.xlim([0, 255])
|
|
|
|
|
plt.savefig(fileName)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def hist_cover_rgb(img, fileName):
|
|
|
|
|
color = ["r", "g", "b"]
|
|
|
|
|
b, g, r = cv2.split(img)
|
|
|
|
|
img = cv2.merge([r, g, b])
|
|
|
|
|
for index, c in enumerate(color):
|
|
|
|
|
hist = cv2.calcHist([img], [index], None, [256], [0, 255])
|
|
|
|
|
plt.plot(hist, color=c)
|
|
|
|
|
plt.xlim([0, 255])
|
|
|
|
|
plt.savefig(fileName)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@csrf_exempt
|
|
|
|
|
def histogram(request):
|
|
|
|
|
if request.method == 'POST':
|
|
|
|
|
para = json.loads(request.body)
|
|
|
|
|
image = para['img']
|
|
|
|
|
img = cv2.imread(PREFIX + image)
|
|
|
|
|
color = para['color']
|
|
|
|
|
histogram_name = getImageName() + DEFAULT_FORMAT
|
|
|
|
|
if color:
|
|
|
|
|
hist_cover_rgb(img, histogram_name)
|
|
|
|
|
else:
|
|
|
|
|
img_gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
|
|
|
|
|
hist_cover_gray(img_gray, PREFIX + histogram_name)
|
|
|
|
|
return HttpResponse(histogram_name)
|
|
|
|
|
return HttpResponse('请使用POST方法')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def r(request):
|
|
|
|
|
return render(request, 'upload.html')
|
|
|
|
|
|