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 pathImageOp.java
More file actions
55 lines (48 loc) · 1.69 KB
/
Copy pathImageOp.java
File metadata and controls
55 lines (48 loc) · 1.69 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
import java.util.HashMap;
public class ImageOp {
public static String dnVal(int x, int y, int[][] img, MRF mrf, int r){
String dnString = "";
dnString = dnString + img[x][y];
for(int[][] neighbours : mrf.n_struct.values())
for(int i=0; i<neighbours.length; i++)
dnString = dnString + neighbourVal(x,y,img,neighbours[i],r);
return dnString;
}
public static String neighbourVal(int x, int y, int[][] img, int[] offset, int r){
int dx = offset[0], dy = offset[1], w = img.length, h = img[0].length;
if(x+dx>-1 && y+dy>-1 && x+dx<w && y+dy<h)
return Integer.toString(img[x+dx][y+dy],r);
else
return "_";
}
public static int[] matchNodeVals(HashMap<Integer,Integer> map, int[][] cliqueGeo, int[] offset){
int[] nodeVals = new int[cliqueGeo.length];
for(int i=0; i<cliqueGeo.length; i++){
int[] coord = new int[2];
coord[0] = offset[0]+cliqueGeo[i][0];
coord[1] = offset[1]+cliqueGeo[i][1];
nodeVals[i] = map.get(pairHash(coord));
}
return nodeVals;
}
public static HashMap<Integer,Integer> genCoordMap(String dnString, MRF mrf, int r){
HashMap<Integer,Integer> coordVals = new HashMap<Integer,Integer>();
coordVals.put(0,Integer.parseInt(dnString.substring(0,1),r));
int inx = 1;
for(int[][] neighbours : mrf.n_struct.values())
for(int i=0; i<neighbours.length; i++)
if(dnString.charAt(inx)=='_')
coordVals.put(pairHash(neighbours[i]),-1);
else{
coordVals.put(pairHash(neighbours[i]),Integer.parseInt(dnString.substring(inx,inx+1),r));
inx++;
}
return coordVals;
}
public static int pairHash(int[] coord){
int x, y;
x = Utilities.map_ZtoN(coord[0]);
y = Utilities.map_ZtoN(coord[1]);
return Utilities.map_NxNtoN(x,y);
}
}