Skip to content
Permalink
Browse files

annotation_styles added to ImageInnotation

  • Loading branch information...
danlester committed Jun 12, 2019
1 parent 1f11295 commit 04d859530102cd6a1e532fe036df34e7685b5592
@@ -24,8 +24,6 @@ nb/*.html
nb/*.sh
nb/*.js

Example/bounding_boxes.csv

.idea
innotater-private
nodb-innotater-private
@@ -0,0 +1,3 @@
bounding_boxes.csv
*-Copy*.ipynb

@@ -97,6 +97,22 @@ Note that if a numpy array is provided channel-first, the Innotater
should detect this and automatically switch the channel to be the last
axis internally.

``annotation_styles`` is an optional dict to control how bounding
boxes are displayed to the user. Defaults will be used for any keys
omitted. For example:

::

ImageInnotation( images, annotation_styles = {
'color1': '#FF0000', /* strokeStyle in Javascript context */
'color2': '#00FF00', /* For second color of the dashed line */
'lineWidth': 5, /* lineWidth in JS context */
'lineDash': [10, 1, 5], /* Passed to setLineDash, can take one int instead of array */
'selected_color2': '#FFFFFF', /* color1 but for currently-selected box */
'selected_color2': '#0000AA', /* color2 for currently-selected box */
} )


BoundingBoxInnotation
^^^^^^^^^^^^^^^^^^^^^

@@ -260,36 +260,56 @@ var InnotaterImagePadView = widgets.DOMWidgetView.extend({
var r = _.clone(this.model.get('rects'));
var max_repeats = this.model.get('max_repeats');

var ann_styles = this.getAnnotationStyles();

for (var ri=0; ri < max_repeats; ri++) {
if (ri != rect_index || !self.isSelecting) {
self.drawBox(ctx, r[ri * 4], r[ri * 4 + 1], r[ri * 4 + 2], r[ri * 4 + 3], ri == rect_index);
self.drawBox(ctx, r[ri * 4], r[ri * 4 + 1], r[ri * 4 + 2], r[ri * 4 + 3], ann_styles, ri == rect_index);
}
}

if (self.isSelecting) {
self.drawBox(ctx, self.rectX, self.rectY, self.rectW, self.rectH, true);
self.drawBox(ctx, self.rectX, self.rectY, self.rectW, self.rectH, ann_styles, true);
}
}
},

drawBox: function(ctx, x,y,w,h, isdrawing) {
drawBox: function(ctx, x,y,w,h, ann_styles, isdrawing) {

ctx.save();
ctx.globalAlpha = 0.9;

ctx.beginPath();
ctx.strokeStyle = isdrawing ? "#008000" : "#FFFFFF";
ctx.strokeStyle = ann_styles[isdrawing ? 'selected_color1' : 'color1'];
ctx.lineWidth = ann_styles['lineWidth'];
ctx.rect(x*this.zoom, y*this.zoom, w*this.zoom, h*this.zoom);
ctx.stroke();

ctx.beginPath();
ctx.strokeStyle = "#000000";
ctx.setLineDash([isdrawing ? 2 : 5]);
ctx.strokeStyle = ann_styles[isdrawing ? 'selected_color2' : 'color2'];
ctx.lineWidth = ann_styles['lineWidth'];
var ld = ann_styles['lineDash'];
if (typeof ld == 'number') {
ld = [ld];
}
ctx.setLineDash(ld);
ctx.rect(x*this.zoom, y*this.zoom, w*this.zoom, h*this.zoom);
ctx.stroke();

ctx.restore();
},

getAnnotationStyles : function() {
return _.defaults(this.model.get('annotation_styles'), {
'color1': '#FFFFFF',
'color2': '#000000',
'lineDash': [2],
'lineWidth': 1,
'selected_color1': '#FFFFFF',
'selected_color2': '#008000',
});
},

remove: function() {
if (this.imgel.src) {
URL.revokeObjectURL(this.imgel.src);
@@ -120,6 +120,8 @@ def __init__(self, *args, **kwargs):

self.transform = kwargs.get('transform', None)

self.annotation_styles = kwargs.get('annotation_styles', {})

self.colorspace = 'BGR'
if 'colorspace' in kwargs:
self.colorspace = kwargs['colorspace']
@@ -131,7 +133,8 @@ def __init__(self, *args, **kwargs):
self.watchlist = WatchList()

def _create_widget(self):
return ImagePad(wantwidth=self.width, wantheight=self.height, layout=self.layout, disabled=self.disabled)
return ImagePad(wantwidth=self.width, wantheight=self.height, layout=self.layout, disabled=self.disabled,
annotation_styles=self.annotation_styles)

def update_ui(self, uindex):
if self.transform is None:
@@ -1,5 +1,5 @@
import ipywidgets as widgets
from traitlets import Unicode, Int, List, Bool
from traitlets import Unicode, Int, List, Bool, Dict


@widgets.register
@@ -19,6 +19,8 @@ class ImagePad(widgets.Image):
wantwidth = Int(0).tag(sync=True)
wantheight = Int(0).tag(sync=True)

annotation_styles = Dict({}).tag(sync=True)

is_bb_source = Bool(False).tag(sync=True)

def setRect(self, repeat_index, x,y,w,h):

0 comments on commit 04d8595

Please sign in to comment.
You can’t perform that action at this time.