-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathmorphomarkers.js
More file actions
56 lines (51 loc) · 2.04 KB
/
morphomarkers.js
File metadata and controls
56 lines (51 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Main Menu functions
// This is also a good template for writing imagejs modules.
// The main thing is to keep your code within a function call and not generate global variables.
// use instead imagejs.modules[yourModule] to store parameters and functions.
(function(){
imagejs.msg('morphomarkers v0.1 loaded.'); // to notify via console and div#msg
// code module
// production url 'http://morphomarkers.imagejs.googlecode.com/git/morphomarkers.js';
// development url 'http://localhost:8888/imagejs/morphomarkers/morphomarkers.js'
var url='morphomarkers.js';
imagejs.modules[url]={
dist:function(dt,px){ //distance between image data and a pixel
if(px.length==2){px=dt[px[0]][px[1]]} // in case the pixel coordinates rather than the pixel is being submitted as px
//console.log(px);
return jmat.imMap(dt,function(xy){
// Euclidean distance
// notice how elegantly the px pixel value is passed to the function through a closure :-)
return Math.pow(jmat.sum(xy.slice(0,3).map(function(xyi,i){return Math.pow((xyi-px[i]),2)})),1/2);
})
},
start:function(){
jmat.gId('cvTop').onclick=function(evt){ // click on top for things hapenning in cvBase
//imagejs.msg('Morphomarker acquisition ...');
var x = evt.clientX-evt.target.offsetLeft;
var y = evt.clientY-evt.target.offsetTop;
//console.log(x,y);
imagejs.msg('('+x+','+y+')');
var dt = jmat.cloneArray(imagejs.data.dt0);
//var yx=dt[y][x];
if (jmat.max(dt[y][x].slice(0,3))>150){dt[y][x]=[0,0,0,dt[y][x][3]]}
else{dt[y][x]=[255,255,255,dt[y][x][3]]}
jmat.imwrite(this,dt);
//imagejs.msg('acquiring ('+x+','+y+') done ');
}
},
end:function(){jmat.gId('cvBase').onclick=null}
}
// create menu to operate module
var menu={
Start:function(){
imagejs.msg('Morphomarker acquisition active');
imagejs.modules[url].start();
},
End:function(){
imagejs.msg('Morphomarker acquisition ended');
imagejs.modules[url].end();
}
}
var name= 'Morphomarkers v0.1';
jmat.gId('menu').appendChild(imagejs.menu(menu,name));
})()