-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmathbiol.filterShapes.js
36 lines (32 loc) · 1.28 KB
/
mathbiol.filterShapes.js
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
// ImageJS module to filter shapes
console.log('filtershapes library loaded');
// write module as a function call to avoid messing global scope
(function(){ // subsidiary module of mathbiol.countShapes
var id='filterShapes'; // name of the modules attribute where module-specific stuff will be stored
imagejs.modules[id]={ // this way all that pertains to the inner workings of this module stays in this branch
round:function(){
var S = imagejs.data.seg;
var z = jmat.size(imagejs.data.img);
imagejs.data.seg=S.map(function(si,i){
return si.map(function(pij,j){
if((i*j>0)&(i<z[0]-1)&(j<z[1]-1)){
if( (S[i][j]+S[i][j-1]+S[i][j+1]+S[i-1][j]+S[i-1][j-1]+S[i-1][j+1]+S[i+1][j]+S[i+1][j-1]+S[i+1][j+1])>4){return 1}else{return 0}
}
else{return 0} // Too lazy to wory about edges, be more industrius later
})
})
},
erode:function(){
var S = imagejs.data.seg;
var z = jmat.size(imagejs.data.img);
imagejs.data.seg=S.map(function(si,i){
return si.map(function(pij,j){
if((i*j>0)&(i<z[0]-1)&(j<z[1]-1)){
if( (S[i][j]+S[i][j-1]+S[i][j+1]+S[i-1][j]+S[i-1][j-1]+S[i-1][j+1]+S[i+1][j]+S[i+1][j-1]+S[i+1][j+1])>6){return 1}else{return 0}
}
else{return 0} // Too lazy to wory about edges, be more industrius later
})
})
}
}
})()