Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Neuroblocks #3

Open
wants to merge 22 commits into
base: large_data_performance
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
f9ab483
Add first neuroblocks classes.
haehn Mar 10, 2015
ddc7ba7
Connection with neuroblocks DB successful.
haehn Mar 10, 2015
4133d53
Add save state icon which transfers merge table and viewport to the s…
haehn Mar 10, 2015
20e2383
Allow running dojo with an absolute location.
haehn Mar 10, 2015
70596a6
Storing and restoring states work.
haehn Mar 11, 2015
a867071
Add neuroblocks 2d picking when passing &pick2d to the url.
haehn Mar 20, 2015
35a38d5
Add support for passing &activeId as a parameter to show one id.
haehn Mar 20, 2015
b0342c2
If activeId is a URL parameter, merge mode only highlights it.
haehn Mar 20, 2015
07706c6
Add storing merges into segmentationLog when using neuroblocks.
haehn Mar 20, 2015
89ce3d7
Add 3D only viewer for Dojo data.
haehn Mar 20, 2015
59aea73
Fix bug where zooming was not possible when an activeId was present.
haehn Mar 20, 2015
22dad3c
Make sure threeD gets initialized when using threeD.html.
haehn Mar 20, 2015
f7bfb5d
Add threeD websocket connection to receive ids.
haehn Mar 23, 2015
148dd05
Some test.
haehn Mar 23, 2015
fb79ab2
Save screenshot (100pixel largest dimension) when saving a state.
haehn Mar 25, 2015
f059d50
Use 200px instead.
haehn Mar 25, 2015
4eb12b9
Do not serialize image_id.
haehn Mar 30, 2015
f5105ed
Enable slicing when single segment mode is active.
haehn Mar 30, 2015
44e2a3a
After picking just show the picked segment.
haehn Mar 30, 2015
f5d402d
Support single segment for 3D view.
haehn Mar 30, 2015
fc52a43
fixed bug with data loading having to do with files starting with "."
Jul 27, 2015
c48110c
fixed a small bug in neuroblocks merging updates
Awami Jul 28, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .ipynb_checkpoints/Untitled0-checkpoint.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"metadata": {
"name": "",
"signature": "sha256:75ae90dd9efb8c17f74ffbcf0b84c75bf22ce3964745d68eb6461b00d14cc1b7"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": []
}
60 changes: 60 additions & 0 deletions Untitled0.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{
"metadata": {
"name": "",
"signature": "sha256:f811fc625a7ce723c171d5490cda4d9b8501943811abe69feb9e028db8bdf7fc"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "code",
"collapsed": false,
"input": [
"data_dir = '/Users/d/Desktop/data/Alyssa/Scan1/021/000001'\n",
"import os\n"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 12
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"level = 0\n",
"for root, dirs, files in os.walk(data_dir):\n",
" if 'image_coordinates.txt' in files:\n",
" print level\n",
" level += 1\n",
" \n",
" "
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"0\n"
]
}
],
"prompt_number": 13
},
{
"cell_type": "code",
"collapsed": false,
"input": [],
"language": "python",
"metadata": {},
"outputs": []
}
],
"metadata": {}
}
]
}
1 change: 1 addition & 0 deletions _dojo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
from websockets import Websockets
from controller import Controller
from database import Database
from neuroblocks import Neuroblocks
73 changes: 71 additions & 2 deletions _dojo/controller.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import datetime
import h5py
import os, errno
import json
Expand All @@ -11,7 +12,7 @@

class Controller(object):

def __init__(self, mojo_dir, out_dir, tmp_dir, database):
def __init__(self, mojo_dir, out_dir, tmp_dir, database, neuroblocks=None, neuroblocks_project_id=None):
'''
'''
self.__websocket = None
Expand All @@ -32,6 +33,10 @@ def __init__(self, mojo_dir, out_dir, tmp_dir, database):

self.__database = database

self.__neuroblocks = neuroblocks

self.__neuroblocks_project_id = neuroblocks_project_id

if self.__database:
self.__largest_id = self.__database.get_largest_id()
else:
Expand Down Expand Up @@ -63,7 +68,12 @@ def send_welcome(self):
output = {}
output['name'] = 'WELCOME'
output['origin'] = 'SERVER'
output['value'] = ''

config = {}
config['neuroblocks'] = self.__neuroblocks != None
config['neuroblocks_project_id'] = self.__neuroblocks_project_id

output['value'] = config

self.__websocket.send(json.dumps(output))

Expand Down Expand Up @@ -127,6 +137,19 @@ def send_problem_table(self, origin):
self.__websocket.send(json.dumps(output))


def send_restore_state(self, origin, state_id):
'''
'''

output = {}
output['name'] = 'RESTORE_STATE'
output['origin'] = origin
output['value'] = self.__neuroblocks.get_state(state_id)

self.__websocket.send(json.dumps(output))



def on_message(self, message):
'''
'''
Expand All @@ -137,6 +160,14 @@ def on_message(self, message):

self.__users.append(input['origin'])

#
# let's check if we should restore a neuroblocks state
#
state_id = input['value']['neuroblocks_state_id']
if state_id:
# we do have a state restore request
self.send_restore_state(input['origin'], state_id)

elif input['name'] == 'MERGETABLE':
self.__merge_table = input['value']

Expand Down Expand Up @@ -178,6 +209,44 @@ def on_message(self, message):
elif input['name'] == 'SAVE':
self.save(input)

elif input['name'] == 'SAVE_STATE':
self.save_state(input)

elif input['name'] == 'SAVE_PICK2D':
self.save_pick2d(input)

elif input['name'] == 'SAVE_ACTION':
self.save_action(input)

def save_action(self, input):
'''
'''
values = input['value']
values['on'] = datetime.datetime.utcnow()

self.__neuroblocks.save_action(values)


def save_pick2d(self, input):
'''
'''
values = input['value']
values['on'] = datetime.datetime.utcnow()

self.__neuroblocks.save_pick2d(values)


def save_state(self, input):
'''
'''
values = input['value']
values['on'] = datetime.datetime.utcnow()


new_id = self.__neuroblocks.save_state(values)

print 'Stored state', new_id


def adjust(self, input):
'''
Expand Down
7 changes: 7 additions & 0 deletions _dojo/datasource.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,16 @@ def get_volume(self, zoomlevel):
tile_files = []

for d in dirs:
if d.startswith('.'):
continue

files = os.listdir(os.path.join(w_path,d))

for f in files:

if f.startswith('.'):
continue

# check if we have an updated version for this tile
if os.path.exists(os.path.join(w_path_tmp, d, f)):
tile_files.append(os.path.join(w_path_tmp, d, f))
Expand Down
98 changes: 98 additions & 0 deletions _dojo/neuroblocks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import pymongo
from bson.objectid import ObjectId

class Neuroblocks(object):

DATABASE = 'meteor'

def __init__(self, server):
'''
'''
if server:
try:
self._connection = pymongo.Connection('mongodb://'+server+'/meteor')
self._db = self._connection[Neuroblocks.DATABASE]
print 'Connected to Neuroblocks.'
except:
print 'Connection to Neuroblocks failed.'


else:
self._connection = None

def get_segmentation(self, id):
'''
'''

return self._db.segmentation.find_one({"_id": id})

def get_segmentation_log(self, id):
'''
'''
return self._db.segmentationLog.find_one({"_id": id})

def save_state(self, state):
'''
'''

# first store the screenshot
screenshot = state['screenshot']
# delete state['screenshot'];
state.pop('screenshot', 0)

screenshot_id = self._db.screenshotsApps.insert({'img':screenshot, 'type':''})

state['img_id'] = screenshot_id

return self._db.appStates.insert(state)

def save_pick2d(self, values):
'''
'''
return self._db.appPickSegment.insert(values)

def save_action(self, values):
'''
'''

db = self._db

project_id = values['projectId']
user_id = values['userId']
segmentId2 = values['values'][0]
segmentId1 = values['values'][1]
date = values['on']


segment1 = db.segmentation.find_one({"projectId":project_id, "id":segmentId1});

segment2 = db.segmentation.find_one({"projectId":project_id, "id":segmentId2});

db.segmentationLog.insert({'objId':segment1['_id'],
'projectId':project_id,
'operation':'merge',
'by':user_id,
'on': date,
'obj': segment1,
'objId2': segment2['_id'],
'obj2':segment2 });

voxelsSum = segment1['voxels'] + segment2['voxels'];
db.segmentation.update({'_id':segment1['_id']},
{'$set':{'voxels': voxelsSum, 'merged':2, 'lastUpdateOn': date, 'lastUpdateBy':user_id}});
db.segmentation.update({'_id':segment2['_id']},
{'$set':{ 'merged':1, 'lastUpdateOn': date, 'lastUpdateBy':user_id}});

print 'stored neuroblocks action'


def get_state(self, state_id):
'''
'''

state = self._db.appStates.find_one({"_id": ObjectId(state_id)})
state['_id'] = str(state['_id'])
state['img_id'] = str(state['img_id'])
state['on'] = str(state['on'])

return state
8 changes: 8 additions & 0 deletions _dojo/scripts/iframe.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<html>

<body>

<iframe width=400 height =400 src='http://140.247.106.194:8000/dojo/?userId=mJdCbW76FjejQLxQi&userName=haehn' name='test' id='testid'></iframe>

</body>
</html>
29 changes: 29 additions & 0 deletions _dojo/scripts/sub.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import cv2
import numpy as np
import sys


factor = int(sys.argv[2])

out = np.zeros((16384/factor,16384/factor), dtype=np.uint8)


img = cv2.imread(sys.argv[1], cv2.CV_LOAD_IMAGE_GRAYSCALE)

k = 0
l = 0

for i in range(16384):
if i % factor == 0:

for j in range(16384):
if j % factor == 0:

out[k][l] = img[i][j]

l += 1

l = 0
k += 1

cv2.imwrite('/tmp/subplain.jpg', out)
11 changes: 11 additions & 0 deletions _dojo/scripts/subcv.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import cv2
import numpy as np
import sys


factor = int(sys.argv[2])


img = cv2.imread(sys.argv[1], cv2.CV_LOAD_IMAGE_GRAYSCALE)
# img = cv2.resize(img, (16384/factor, 16384/factor))
# cv2.imwrite('/tmp/subcv.jpg', img)
4 changes: 1 addition & 3 deletions _dojo/viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def __init__(self):
'''
self.__query_viewer_regex = re.compile('^/dojo/.*$')

self.__web_dir = '_web/'
self.__web_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), '../_web/')

def content_type(self, extension):
'''
Expand Down Expand Up @@ -45,8 +45,6 @@ def handle(self, request):
requested_file = self.__web_dir + url.replace('/dojo/', '')
extension = os.path.splitext(requested_file)[1]



if not os.path.exists(requested_file):
return 'Error 404', 'text/html'

Expand Down
Loading