Skip to content

Commit

Permalink
Add CMU background search
Browse files Browse the repository at this point in the history
Add new background search button.
Fix whitespace issues.
Move default prefix code back to HT prefix.
  • Loading branch information
jeffbaumes committed Jul 21, 2015
1 parent aabe437 commit a4a2a31
Show file tree
Hide file tree
Showing 11 changed files with 264 additions and 32 deletions.
7 changes: 7 additions & 0 deletions .jscs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"preset": "crockford",
"disallowDanglingUnderscores": null,
"validateQuoteMarks": null,
"requireMultipleVarDecl": true,
"requireCamelCaseOrUpperCaseIdentifiers": null
}
9 changes: 9 additions & 0 deletions imagespace/server/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
###############################################################################

import mako
from .imagebackgroundsearch_rest import ImageBackgroundSearch
from .imagefeatures_rest import ImageFeatures
from .imagepivot_rest import ImagePivot
from .imagesearch_rest import ImageSearch
Expand Down Expand Up @@ -57,6 +58,13 @@ class CustomAppRoot(object):
type="image/png"
href="${staticRoot}/img/Girder_Favicon.png">
<style id="blur-style">
img.im-blur {
-webkit-filter: blur(10px);
filter blur(10px)
}
</style>
</head>
<body>
<div id="g-global-info-apiroot" class="hide">${apiRoot}</div>
Expand Down Expand Up @@ -85,6 +93,7 @@ def GET(self):

def load(info):
# Bind our REST resources
info['apiRoot'].imagebackgroundsearch = ImageBackgroundSearch()
info['apiRoot'].imagesearch = ImageSearch()
info['apiRoot'].imagefeatures = ImageFeatures()
info['apiRoot'].imagepivot = ImagePivot()
Expand Down
53 changes: 53 additions & 0 deletions imagespace/server/imagebackgroundsearch_rest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

###############################################################################
# Copyright Kitware Inc.
#
# Licensed under the Apache License, Version 2.0 ( the "License" );
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
###############################################################################

from girder.api import access
from girder.api.describe import Description
from girder.api.rest import Resource
from girder import logger

import requests
import os


class ImageBackgroundSearch(Resource):
def __init__(self):
self.resourceName = 'imagebackgroundsearch'
self.route('GET', (), self.getImageSearch)

@access.public
def getImageSearch(self, params):
return self._imageSearch(params)

@access.public
def postImageSearch(self, params):
return self._imageSearch(params)

def _imageSearch(self, params):
print params
return [{'id': d[0], 'score': d[1]} for d in requests.post(
os.environ['IMAGE_SPACE_CMU_BACKGROUND_SEARCH'],
data=params['url'],
headers={
'Content-type': 'text',
'Content-length': str(len(params['url']))
},
verify=False)
.json()]
getImageSearch.description = Description('Searches images by background')
6 changes: 3 additions & 3 deletions imagespace/server/imagesearch_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@
import requests
import os


class ImageSearch(Resource):
def __init__(self):
self.resourceName = 'imagesearch'
self.route('GET', (), self.getImageSearch)


@access.public
def getImageSearch(self, params):
return self._imageSearch(params)
Expand All @@ -43,12 +43,12 @@ def _imageSearch(self, params):
limit = params['limit'] if 'limit' in params else '10'
if 'histogram' in params:
if 'IMAGE_SPACE_FLANN_INDEX' in os.environ:
logger.info('Using FLANN INDEX at '+os.environ['IMAGE_SPACE_FLANN_INDEX'])
logger.info('Using FLANN INDEX at ' + os.environ['IMAGE_SPACE_FLANN_INDEX'])
return requests.get(
os.environ['IMAGE_SPACE_FLANN_INDEX'] +
'?query=' + params['histogram'] + '&k=' + str(limit)).json()
logger.info('Using COLUMBIA INDEX at '+os.environ['IMAGE_SPACE_COLUMBIA_INDEX'] + '?url=' + params['url'] + '&num=' + str(limit))
return [{'id:' : d} for d in requests.get(
return [{'id' : d} for d in requests.get(
os.environ['IMAGE_SPACE_COLUMBIA_INDEX'] +
'?url=' + params['url'] + '&num=' + str(limit), verify=False).json()['images'][0]['similar_images']['image_urls']]

Expand Down
122 changes: 122 additions & 0 deletions imagespace/web_external/js/views/body/DisplayView.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
imagespace.views.DisplayView = imagespace.View.extend({
events: {
'click .im-add-user-data': function (event) {
var id = $(event.currentTarget).attr('im-id'),
image = this.imageIdMap[id];
imagespace.userDataView.addUserImage(image);
},

'click .im-details': function (event) {
var id = $(event.currentTarget).attr('im-id'),
image = this.imageIdMap[id];
this.imageDetailWidget = new imagespace.views.ImageDetailWidget({
el: $('#g-dialog-container'),
image: image,
parentView: this
});
this.imageDetailWidget.render();
},

'click .im-find-similar': function (event) {
var id = $(event.currentTarget).attr('im-id'),
image = this.imageIdMap[id];
$('.alert-info').html('Finding similar images <i class="icon-spin5 animate-spin"></i>').removeClass('hidden');
this.$('.btn-lg').addClass('disabled');
$(event.currentTarget).parent().find('.im-find-similar')
.html('<i class="icon-spin5 animate-spin"></i>');
if (image.histogram) {
this.findSimilarImages(image);
} else {
girder.restRequest({
path: 'imagefeatures',
data: {
url: image.imageUrl
},
method: 'POST'
}).done(_.bind(function (features) {
image.histogram = features.histogram;
this.findSimilarImages(image);
}, this));
}
},

'mouseover .im-image-area': function (event) {
$(event.currentTarget).find('.im-caption-content').removeClass('hidden');
},

'mouseout .im-image-area': function (event) {
$(event.currentTarget).find('.im-caption-content').addClass('hidden');
}
},

initialize: function (settings) {
girder.cancelRestRequests('fetch');
this.resLimit = 30;
this.imagePathRoot = '/data/roxyimages/';
// this.imagePathRoot = '/data/xdata/syria/syria_instagram_images/'
this.results = settings.results;
this.imageIdMap = {};
this.results.forEach(_.bind(function (result) {
result.imageUrl = result.id;
this.imageIdMap[result.id] = result;
}, this));

this.render();
},

render: function () {
this.$el.html(imagespace.templates.search({
results: this.results,
showText: true
}));
return this;
},

findSimilarImages: function (image) {
girder.restRequest({
path: 'imagesearch',
data: {
url: image.imageUrl,
histogram: JSON.stringify(image.histogram || []),
limit: this.resLimit
}
}).done(_.bind(function (results) {
var query = '(', count = 0;
results.forEach(_.bind(function (result, index) {
var parts = result.id.split('/'),
file = parts[parts.length - 1];
if (file.length < 30) {
return;
}
if (result.id.indexOf('cmuImages') !== -1) {
file = 'cmuImages/' + file;
}
file = this.imagePathRoot + file;
if (count < this.resLimit) {
query += 'id:"' + file + '" ';
count += 1;
}
}, this));
query += ')';
imagespace.router.navigate('search/' + encodeURIComponent(query), {trigger: true});

$('.btn-lg').removeClass('disabled');
$('.im-find-similar').html('<i class="icon-search"></i>');

$('.alert-info').addClass('hidden');
$('.alert-success').text('Search complete.').removeClass('hidden');
setTimeout(function () {
$('.alert-success').addClass('hidden')
}, 5000);

}, this));
}

});

imagespace.router.route('display/:content', 'display', function (content) {
$('.im-search').val(content);
girder.events.trigger('g:navigateTo', imagespace.views.DisplayView, {
results: JSON.parse(content)
});
});
6 changes: 3 additions & 3 deletions imagespace/web_external/js/views/body/SearchView.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ imagespace.views.SearchView = imagespace.View.extend({

initialize: function (settings) {
girder.cancelRestRequests('fetch');
this.resLimit = 30;
this.imagePathRoot = '/data/roxyimages/';
this.imagePathRoot = '/data/xdata/syria/syria_instagram_images/'
this.resLimit = 30;
this.imagePathRoot = '/data/roxyimages/';
// this.imagePathRoot = '/data/xdata/syria/syria_instagram_images/'
this.results = settings.results;
this.imageIdMap = {};
this.results.forEach(_.bind(function (result) {
Expand Down
20 changes: 17 additions & 3 deletions imagespace/web_external/js/views/layout/UserDataView.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,20 @@ imagespace.views.LayoutUserDataView = imagespace.View.extend({
this.searchBySizeWidget.render();
},

'click .im-blur': function () {
$('#blur-style').text('img.im-blur { -webkit-filter: blur(10px); filter blur(10px) }');
},

'click .im-unblur-hover': function () {
$('#blur-style').text(
'img.im-blur { -webkit-filter: blur(10px); filter: blur(10px) }'
+ '\nimg.im-blur:hover { -webkit-filter: blur(0px); filter: blur(0px) }');
},

'click .im-unblur': function () {
$('#blur-style').text('');
},

'click .im-search-by-serial-number': function () {
this.searchBySerialNumberWidget = new imagespace.views.SearchBySerialNumberWidget({
el: $('#g-dialog-container'),
Expand Down Expand Up @@ -119,9 +133,9 @@ imagespace.views.LayoutUserDataView = imagespace.View.extend({
},

initialize: function (settings) {
this.imagePathRoot = '/data/roxyimages/';
this.imagePathRoot = '/data/xdata/syria/syria_instagram_images/';
this.resLimit = 30;
this.imagePathRoot = '/data/roxyimages/';
// this.imagePathRoot = '/data/xdata/syria/syria_instagram_images/';
this.resLimit = 30;
this.imageIdMap = {};
girder.cancelRestRequests('fetch');
this.render();
Expand Down
46 changes: 31 additions & 15 deletions imagespace/web_external/js/views/widgets/ImageDetailWidget.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
*/
imagespace.views.ImageDetailWidget = imagespace.View.extend({
events: {
'click .im-search-mod': function(event) {
'click .im-search-mod': function (event) {
var query = $(event.currentTarget).attr('im-search');
this.$el.modal('hide');
imagespace.router.navigate('search/' + encodeURIComponent(query), {trigger: true});
},

'click .im-similar-images': function(event) {
'click .im-similar-images': function (event) {
this.$('.im-similar-images')
.addClass('btn-info disabled')
.removeClass('btn-default')
Expand All @@ -28,13 +28,29 @@ imagespace.views.ImageDetailWidget = imagespace.View.extend({
this.findSimilarImages();
}, this));
}
},

'click .im-similar-background-images': function (event) {
this.$('.im-similar-background-images')
.addClass('btn-info disabled')
.removeClass('btn-default')
.html('Finding images with similar background <i class="icon-spin5 animate-spin"></i>');
girder.restRequest({
path: 'imagebackgroundsearch',
data: {
url: this.image.imageUrl
}
}).done(_.bind(function (results) {
console.log(results);
imagespace.router.navigate('display/' + encodeURIComponent(JSON.stringify(results)), {trigger: true});
}, this));
}
},

initialize: function (settings) {
this.resLimit = 30;
this.resLimit = 30;
this.imagePathRoot = '/data/roxyimages/';
this.imagePathRoot = '/data/xdata/syria/syria_instagram_images/'
// this.imagePathRoot = '/data/xdata/syria/syria_instagram_images/'
this.image = settings.image || null;
this.title = settings.title || 'Image details';
},
Expand All @@ -53,7 +69,7 @@ imagespace.views.ImageDetailWidget = imagespace.View.extend({
return this;
},

findSimilarImages: function() {
findSimilarImages: function () {
girder.restRequest({
path: 'imagesearch',
data: {
Expand All @@ -66,16 +82,16 @@ imagespace.views.ImageDetailWidget = imagespace.View.extend({
this.$el.modal('hide');
var query = '(', count = 0;
results.forEach(_.bind(function (result, index) {
var parts = result.id.split('/'),
file = parts[parts.length - 1];
if (file.length < 30) {
return;
}
if (result.id.indexOf('cmuImages') !== -1) {
file = 'cmuImages/' + file;
}
file = this.imagePathRoot + file;
if (count < this.resLimit) {
var parts = result.id.split('/'),
file = parts[parts.length - 1];
if (file.length < 30) {
return;
}
if (result.id.indexOf('cmuImages') !== -1) {
file = 'cmuImages/' + file;
}
file = this.imagePathRoot + file;
if (count < this.resLimit) {
query += 'id:"' + file + '" ';
count += 1;
}
Expand Down
11 changes: 3 additions & 8 deletions imagespace/web_external/stylesheets/layout.styl
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ $portraitHeight = 38px
padding 20px 20px
margin-bottom 20px

.im-image-area
overflow-x hidden

.im-actions
padding-top 30px

Expand All @@ -181,14 +184,6 @@ img.im-image-thumbnail
img.im-image-detail
height 250px

img.im-blur
-webkit-filter blur(10px)
filter blur(10px)

img.im-blur:hover
-webkit-filter blur(0px)
filter blur(0px)

.im-caption
height 70px
overflow hidden
Expand Down
Loading

0 comments on commit a4a2a31

Please sign in to comment.