This repository has been archived by the owner on Feb 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 73
/
multiPointSet_import.ijm
executable file
·64 lines (60 loc) · 1.79 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*
* @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}
ext = tmp[lengthOf(tmp)-1];
// parse text by lines
text = split(allText, "\n");
// define array for points
var xpoints = newArray;
var ypoints = newArray;
// in case input is in TXT format
if (ext=="txt") {
print("importing TXT point set...");
//these are the column indexes
//hdr = split(text[0]);
nbPoints = split(text[1]);
iX = 0; iY = 1;
// loading and parsing each line
for (i = 2; i < (text.length); i++){
line = split(text[i]," ");
setOption("ExpandableArrays", true);
xpoints[i-2] = parseInt(line[iX]);
ypoints[i-2] = parseInt(line[iY]);
print("p("+i-1+") ["+xpoints[i-2]+"; "+ypoints[i-2]+"]");
}
// in case input is in CSV format
} else if (ext=="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);