Skip to content

Commit

Permalink
Merge branch 'cropping'
Browse files Browse the repository at this point in the history
  • Loading branch information
dcunhas committed Aug 3, 2016
2 parents cb0577e + 683258f commit a4a05d8
Show file tree
Hide file tree
Showing 13 changed files with 290 additions and 168 deletions.
8 changes: 7 additions & 1 deletion agdss/settings/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'DIRS': [BASE_DIR + '/templates'],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
Expand Down Expand Up @@ -123,9 +123,15 @@
USE_TZ = False


#Login
LOGIN_REDIRECT_URL = '/webclient'



# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.9/howto/static-files/
STATIC_URL = '/static/'
#STATIC_ROOT = "C:/Users/Sandeep/Dropbox/kumar-prec-ag"
#STATIC_ROOT = "/home/sdcunha/Dropbox/kumar-prec-ag"


14 changes: 14 additions & 0 deletions agdss/templates/registration/login.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{#% extends 'base.html' %#}

{% block title %}Login{% endblock %}

{% block content %}
<h2>Login</h2>
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<button type="submit">Login</button>
</form>
{% endblock %}

<a href ='/register'>Register</a>
9 changes: 9 additions & 0 deletions agdss/templates/registration/logout.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{#% extends 'base.html' %#}

{% block title %}Logout{% endblock %}

{% block content %}
<h2>Logged out</h2>
<p>You have been successfully logged out.</p>
<p><a href="{% url 'login' %}">Log in</a> again.</p>
{% endblock %}
12 changes: 12 additions & 0 deletions agdss/templates/registration/register.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{#% extends 'base.html' %#}

{% block title %}Register{% endblock %}

{% block content %}
<!--<h2>Register</h2> -->
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<button type="submit">Login</button>
</form>
{% endblock %}
16 changes: 16 additions & 0 deletions agdss/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,25 @@

from django.conf.urls import include, url
from django.contrib import admin
from django.views.generic.edit import CreateView
from django.contrib.auth.forms import UserCreationForm
from django.views.generic import RedirectView
from django.conf import settings

urlpatterns = [
url(r'^grappelli/', include('grappelli.urls')), # grappelli URLS
url(r'^webclient/', include('webclient.urls')),
url(r'^admin/', admin.site.urls),

url('^', include('django.contrib.auth.urls')),

url('^register/', CreateView.as_view(
template_name='registration/register.html',
form_class=UserCreationForm,
success_url= '/login'
)),
url(r'^accounts/', include('django.contrib.auth.urls')),

url(r'^$', RedirectView.as_view(url='/webclient/')),

]
30 changes: 27 additions & 3 deletions image_ops/crop_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
#import scipy
import random


NUM_WINDOW_ROWS = 4
NUM_WINDOW_COLS = 4
WINDOW_PADDING = 20
NUM_LABELS_PER_WINDOW = 3

def calculate_entropy_map(image, category):
images = ImageLabel.objects.all().filter(categoryType=category)
#aggregrate_array = numpy.full((241,386, len(images)), 255, dtype=numpy.uint8)
Expand Down Expand Up @@ -38,8 +44,8 @@ def calculateEntropy(arr):
return #[[scipy.stats.entropy(y) for y in x] for x in probArr]


def getImageWindow(image):
return getGeometricImageWindow(image)
def getImageWindow(image, user):
return getPaddedWindow(image, user)

def getRandomImageWindow(image):
retDict = {'width':300, 'height': 300}
Expand All @@ -57,4 +63,22 @@ def getGeometricImageWindow(image):
numLabels = len(ImageLabel.objects.all().filter(parentImage=image))
topLeft = topLeftArr[numLabels % len(topLeftArr)]
windowDict['x'], windowDict['y'] = topLeft
return windowDict
return windowDict


def getPaddedWindow(image, user):
#Crop out sidemost pixels
windowWidth = (image.width - 2* WINDOW_PADDING)/NUM_WINDOW_COLS
windowHeight = (image.height - 2* WINDOW_PADDING)/NUM_WINDOW_ROWS
windowDict = {'width': windowWidth, 'height': windowHeight,
'padding': WINDOW_PADDING}

for x in range(WINDOW_PADDING, image.width - WINDOW_PADDING, windowWidth):
for y in range(WINDOW_PADDING, image.height - WINDOW_PADDING, windowWidth):
labels = image.imagelabel_set.all().filter(imageWindow__x=x, imageWindow__y=y)
print labels
if len(labels) < NUM_LABELS_PER_WINDOW and all(label.labeler.user != user for label in labels):
windowDict['x'], windowDict['y'] = (x,y)
print windowDict
return windowDict
return None
114 changes: 112 additions & 2 deletions webclient/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,124 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.7 on 2016-07-26 20:37
# Generated by Django 1.9.6 on 2016-07-29 20:56
from __future__ import unicode_literals

from django.db import migrations
import datetime
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
import webclient.models


class Migration(migrations.Migration):

initial = True

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]

operations = [
migrations.CreateModel(
name='CategoryType',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('category_name', models.CharField(default='unknown', max_length=100, unique=True)),
('pub_date', models.DateTimeField(blank=True, default=datetime.datetime.now)),
],
),
migrations.CreateModel(
name='Image',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=200)),
('path', models.CharField(max_length=500)),
('description', models.CharField(max_length=500)),
('pub_date', models.DateTimeField(blank=True, default=datetime.datetime.now)),
('width', models.PositiveSmallIntegerField(default=1920)),
('height', models.PositiveSmallIntegerField(default=1080)),
('categoryType', models.ManyToManyField(to='webclient.CategoryType')),
],
),
migrations.CreateModel(
name='ImageFilter',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('brightness', models.DecimalField(decimal_places=1, default=1, max_digits=3)),
('contrast', models.DecimalField(decimal_places=1, default=1, max_digits=3)),
('saturation', models.DecimalField(decimal_places=1, default=1, max_digits=3)),
],
),
migrations.CreateModel(
name='ImageLabel',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('labelShapes', models.TextField(max_length=10000)),
('pub_date', models.DateTimeField(blank=True, default=datetime.datetime.now)),
('ip_address', models.GenericIPAddressField(blank=True, default=None, null=True)),
('categoryType', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='webclient.CategoryType')),
],
),
migrations.CreateModel(
name='ImageSourceType',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('description', models.CharField(default='unknown', max_length=200, unique=True)),
('pub_date', models.DateTimeField(blank=True, default=datetime.datetime.now)),
],
),
migrations.CreateModel(
name='ImageWindow',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('x', models.PositiveSmallIntegerField()),
('y', models.PositiveSmallIntegerField()),
('width', models.PositiveSmallIntegerField()),
('height', models.PositiveSmallIntegerField()),
],
),
migrations.CreateModel(
name='Labeler',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
),
migrations.AlterUniqueTogether(
name='imagewindow',
unique_together=set([('x', 'y', 'width', 'height')]),
),
migrations.AddField(
model_name='imagelabel',
name='imageWindow',
field=models.ForeignKey(default=webclient.models.getDefaultImageWindowId, on_delete=django.db.models.deletion.CASCADE, to='webclient.ImageWindow'),
),
migrations.AddField(
model_name='imagelabel',
name='labeler',
field=models.ForeignKey(blank=True, default=None, null=True, on_delete=django.db.models.deletion.CASCADE, to='webclient.Labeler'),
),
migrations.AddField(
model_name='imagelabel',
name='parentImage',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='webclient.Image'),
),
migrations.AddField(
model_name='imagefilter',
name='imageLabel',
field=models.ForeignKey(blank=True, default=None, null=True, on_delete=django.db.models.deletion.CASCADE, to='webclient.ImageLabel'),
),
migrations.AddField(
model_name='imagefilter',
name='labeler',
field=models.ForeignKey(blank=True, default=None, null=True, on_delete=django.db.models.deletion.CASCADE, to='webclient.Labeler'),
),
migrations.AddField(
model_name='image',
name='source',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='webclient.ImageSourceType'),
),
migrations.AlterUniqueTogether(
name='image',
unique_together=set([('name', 'path')]),
),
]
125 changes: 0 additions & 125 deletions webclient/migrations/0002_auto_20160726_2037.py

This file was deleted.

Loading

0 comments on commit a4a05d8

Please sign in to comment.