This repository was archived by the owner on Jun 27, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCutset.java
More file actions
147 lines (139 loc) · 4.75 KB
/
Copy pathCutset.java
File metadata and controls
147 lines (139 loc) · 4.75 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
import java.util.Arrays;
public class Cutset {
public static class ImageCutter{
private int next;
private int total;
private int r;
private int[][] img;
private Cutset.AbstractCutset cutter;
public ImageCutter(int[][] image, int range, Cutset.AbstractCutset cutset_spec){
img = image;
r = range;
cutter = cutset_spec;
next = 0;
total = cutter.numOfComponents(img);
}
public ClusterTree nextCluster(){
return cutter.getClusteredComponent(next++,img,r);
}
public boolean hasNext(){
return next<total;
}
public int size(){
return total;
}
}
public abstract static class AbstractCutset{
MRF mrf;
public AbstractCutset(MRF mrf_spec){
mrf = mrf_spec;
}
public abstract int numOfComponents(int[][] img);
public abstract ClusterTree getClusteredComponent(int inx, int[][] img, int range);
}
public static class StripCutset extends AbstractCutset{
private int thickness;
public StripCutset(MRF mrf_spec, int spacing){
super(mrf_spec);
thickness = spacing;
}
public int numOfComponents(int img[][]){
return (img[0].length-mrf.minRadius()) / (thickness+mrf.minRadius());
}
public ClusterTree getClusteredComponent(int inx, int[][] img, int r){
//System.out.println("\tstrip subgraph "+inx);
ImageMRFGraph g = makeSubGraph(inx+1,img,r);
System.out.println("NEW STRIP!");
g.print();
//System.out.println("\t\tgrabbing cutset");
SuperNode cutset = findCutset(g);
//System.out.println("\t\tclustering");
ClusterTree cluster = cluster(g);
//System.out.println("\t\tlinking");
linkAndCondition(cluster,cutset,g);
return cluster;
}
private ImageMRFGraph makeSubGraph(int inx, int[][] img, int r){
int[][] sub_img = new int[img.length][thickness+2*mrf.minRadius()];
int topInx = (inx-1)*(thickness+mrf.minRadius());
for(int i=0; i<img.length; i++)
sub_img[i] = Arrays.copyOfRange(img[i],topInx,topInx+thickness+2*mrf.minRadius());
ImageMRFGraph g = new ImageMRFGraph(sub_img,r);
g.makeMRF(mrf);
return g;
}
private SuperNode findCutset(ImageMRFGraph g){
SuperNode cutset = new SuperNode(-1,g.r);
for(int x=0; x<g.w; x++){
for(int y=0; y<mrf.minRadius(); y++)
cutset.V.add(g.img_nodes[x][y]);
for(int y=g.h-1; y>g.h-mrf.minRadius()-1; y--)
cutset.V.add(g.img_nodes[x][y]);
}
cutset.findInternalCliques(g.cliquesForSearch);
cutset.obs(); //<-- this is when we observe (encode) the cutset (conditioning happens here)
/* DEBUG OUTPUT SEQUENCE
System.out.println();
for(int i=0; i<cutset.V.size(); i=i+2)
System.out.print(cutset.V.get(i).VAL+" ");
System.out.println();
for(int i=1; i<cutset.V.size(); i=i+2)
System.out.print(cutset.V.get(i).VAL+" ");
System.out.println();
*/
return cutset;
}
private ClusterTree cluster(ImageMRFGraph g){
ClusterTree cluster = new ClusterTree();
for(int i=0; i*mrf.minRadius()<g.w; i++){
//----- make supernode
SuperNode newNode = new SuperNode(i,g.r);
for(int x=i*mrf.minRadius(); x<(i+1)*mrf.minRadius(); x++)
for(int y=mrf.minRadius(); y<mrf.minRadius()+thickness; y++)
newNode.V.add(g.img_nodes[x][y]);
newNode.findInternalCliques(g.cliquesForSearch);
//----- add supernode into list of supernodes in cluster
cluster.SV.add(newNode);
}
return cluster;
}
private void linkAndCondition(ClusterTree cluster, SuperNode cutset, ImageMRFGraph g){
SuperEdge newEdge;
for(int i=0; i<cluster.SV.size()-1; i++){
newEdge = new SuperEdge(cluster.SV.get(i),cluster.SV.get(i+1),g.cliquesForSearch,g.r);
newEdge.condition(cutset);
cluster.SE.add(newEdge);
}
for(int i=0; i<cluster.SV.size(); i++){
newEdge = new SuperEdge(cluster.SV.get(i),cutset,g.cliquesForSearch,g.r);
if(newEdge.C.size()==0)
newEdge.detach();
else
cluster.SE.add(newEdge);
}
//make pairwise neighbours
//make each supernode neighbours with cutset
// check if there are actually cliques between a supernode and cutset before adding neighbour
//process tri-cliques <-- add into special list in edges? perhaps this should be added into normal search to be more efficient
//epot procedure?
}
}
//need a conditioning function to condition on nearby nodes when "stripping"
/*
* 1) use minimum radius to determine spacing nodes
* 2) observe spacing nodes
* 3) return supernode of condition neighbours
* 4) return array of internal node
*/
/*
* 1) use minimum radius to determine minimum cluster width
* 2) systematically segment into supernodes
* 3) search for internal-cliques
* 4) pairwise attach superedges
* 5) search for cross-cliques
*
* supernodes add condition-node as a neighbour
* need to make cross-clique function in superedge more stringent
* superedges check to see if there are "tri-node" cliques
*/
}