Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from django.shortcuts import render
- from image.models import fva
- from PIL import Image
- from PIL import ImageStat
- from PIL import ImageFilter
- from math import log
- import mysql.connector
- def homepage(request):
- return render(request,'index.html',{})
- def rootmeansquare( im_file ):
- im = Image.open(im_file).convert('L')
- stat = ImageStat.Stat(im)
- return stat.rms[0]
- def average( im_file ):
- im = Image.open(im_file)
- stat = ImageStat.Stat(im)
- return stat.mean[0]
- def varaince( im_file ):
- im = Image.open(im_file)
- stat = ImageStat.Stat(im)
- return stat.var[0]
- def standarddeviation( im_file ):
- im = Image.open(im_file)
- stat = ImageStat.Stat(im)
- return stat.stddev[0]
- def edgedetection( im_file ):
- im = Image.open(im_file)
- im = im.filter(ImageFilter.FIND_EDGES)
- stat = ImageStat.Stat(im)
- return stat.mean[0]
- def histogramvalue( im_file):
- im = Image.open(im_file)
- hist=im.histogram()
- sumhist=sum(hist)
- lenhist=len(hist)
- avghist=float(sumhist/lenhist)
- return avghist
- def entropy( im_file ):
- img = Image.open(im_file)
- histogram=img.histogram()
- log2 = lambda x:log(x)/log(2)
- total = len(histogram)
- counts = {}
- for item in histogram:
- counts.setdefault(item,0)
- counts[item]+=1
- ent = 0
- for i in counts:
- p = float(counts[i])/total
- ent-=p*log2(p)
- return -ent*log2(1/ent)
- def upload(request):
- filename = request.FILES['search_field']
- #return render(request,'temp.html',{'A': filename})
- #conn=mysql.connector.connect(user="root",password="28091994",host="localhost",database="images")
- #mycursor=conn.cursor()
- rms=rootmeansquare(filename)
- var=varaince(filename)
- #sd=standarddeviation(filename)
- #edge=edgedetection(filename)
- #histv=histogramvalue(filename)
- #ev=entropy(filename)
- #fvsum=rms+sd+edge+histv+ev
- fvavg=float(rms/7)
- #mycursor.execute("INSERT INTO fva(img,fvavg) VALUES (%s, %s)", (filename, fvavg))
- #conn.commit()
- #a=fva(img=filename,fvavg=fvavg)
- #a.save()
- return render(request,'index.html',{})
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement