-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathmultiPointSet_import.ijm
50 lines (45 loc) · 1.33 KB
/
multiPointSet_import.ijm
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
/*
* @file import_MultipointSet.ijm
* @title Marco for exporting multi-point set
* @author Jiri Borovec
* @date 13/06/2014
* @mail [email protected]
*
* @brief: This macro does importing set of points from Multi-point tool
* from .csv and .txt files (the name is specified during exporting)
*/
// ask for a file to be imported
fileName = File.openDialog("Select the file to import");
allText = File.openAsString(fileName);
tmp = split(fileName,".");
// get file format {txt, csv}
posix = tmp[lengthOf(tmp)-1];
// parse text by lines
text = split(allText, "\n");
// define array for points
var xPoints = newArray;
var yPoints = newArray;
if (posix=="csv") {
print("importing CSV point set...");
//these are the column indexes
//hdr = split(text[0]);
if (text[0]==',X,Y' || text[0]==' ,X,Y') {
iLabel = 0; iX = 1; iY = 2;
} else {
iX = 0; iY = 1;
}
// loading and parsing each line
for (i = 1; i < (text.length); i++){
line = split(text[i],",");
setOption("ExpandableArrays", true);
xPoints[i-1] = parseInt(line[iX]);
yPoints[i-1] = parseInt(line[iY]);
print("p("+i+") ["+xPoints[i-1]+"; "+yPoints[i-1]+"]");
}
// in case of any other format
} else {
print("not supported format...");
}
// show the points in the image
makeSelection("point", xPoints, yPoints);
run("Point Tool...", "label");