-
Notifications
You must be signed in to change notification settings - Fork 0
/
exportXML_ROIandCircle.m
231 lines (197 loc) · 9.6 KB
/
exportXML_ROIandCircle.m
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
function success = exportXML(fullname,scan_scale, task_id,workdir,Left, Top, roi_w, roi_h)
%EXPORTXML Summary of this function goes here
% process data
try
success = 0;
% square parameter
lengthSquare = 2*(roi_w + roi_h);
lengthSquareM = lengthSquare*scan_scale;
areaSquare= roi_w* roi_h;
areaSquareM= areaSquare * scan_scale *scan_scale;
x1Square = Left;
y1Square = Top;
x2Square = Left + roi_w;
y2Square = Top;
x3Square = Left + roi_w;
y3Square = Top + roi_h;
x4Square = Left;
y4Square = Top + roi_h;
diameter = 550;
lengthCircleM = pi*diameter;
lengthCircle = lengthCircleM/scan_scale;
areaCircleM= pi*(diameter/2)^2;
areaCircle= areaCircleM / scan_scale /scan_scale;
x1Circle = Left + roi_w/2 - diameter/2/scan_scale;
y1Circle = Top + roi_h/2 - diameter/2/scan_scale;
x2Circle = Left + roi_w/2 + diameter/2/scan_scale;
y2Circle = Top + roi_h/2 + diameter/2/scan_scale;
% indexslash = findstr(fullname, '\');
indexdot = findstr(fullname, '.');
% wsi_name = fullname((indexslash(end)+1):(indexdot(end)-1));
imageDir = fullname(1:(indexdot(end)-1));
% workdir = [workdir, 'Temporary_Task_Images\'];
% XMLfolder = [workdir, wsi_name,'XML\'];
% filename = [XMLfolder,task_id,'.xml'];
% XMLname = [workdir, wsi_name];
filename = [imageDir,'.xml'];
% if isdir(XMLfolder)
% delete(filename);
% else
% mkdir(XMLfolder);
% end
% generate xml
% annotation information
docNode = com.mathworks.xml.XMLUtils.createDocument('Annotations');
docRootNode = docNode.getDocumentElement;
docRootNode.setAttribute('MicronsPerPixel','0.250300');
% image information
entry_level_info = docNode.createElement('Image_information');
entry_level_info.setAttribute('Full_path',fullname);
docNode.getDocumentElement.appendChild(entry_level_info);
entry_level1 = docNode.createElement('Annotation');
entry_level1.setAttribute('MacroName','');
entry_level1.setAttribute('MarkupImagePath','');
entry_level1.setAttribute('Selected','1');
entry_level1.setAttribute('Visible','1');
entry_level1.setAttribute('LineColor','65280');
entry_level1.setAttribute('Type','4');
entry_level1.setAttribute('Incremental','0');
entry_level1.setAttribute('LineColorReadOnly','0');
entry_level1.setAttribute('NameReadOnly','0');
entry_level1.setAttribute('ReadOnly','0');
entry_level1.setAttribute('Name','');
entry_level1.setAttribute('Id','1');
docNode.getDocumentElement.appendChild(entry_level1);
entry_level1_1 = docNode.createElement('Attributes');
entry_level1.appendChild(entry_level1_1);
entry_level1_1_1 = docNode.createElement('Attribute');
entry_level1_1_1.setAttribute('Name','Description');
entry_level1_1_1.setAttribute('Id','0');
entry_level1_1_1.setAttribute('Value','');
entry_level1_1.appendChild(entry_level1_1_1);
entry_level1_2 = docNode.createElement('Regions');
entry_level1.appendChild(entry_level1_2);
entry_level1_2_1 = docNode.createElement('RegionAttributeHeaders');
entry_level1_2.appendChild(entry_level1_2_1);
entry_level1_2_1_1 = docNode.createElement('AttributeHeaders');
entry_level1_2_1_1.setAttribute('Name','Region');
entry_level1_2_1_1.setAttribute('Id','9999');
entry_level1_2_1_1.setAttribute('ColumunWidth','-1');
entry_level1_2_1.appendChild(entry_level1_2_1_1);
entry_level1_2_1_2 = docNode.createElement('AttributeHeaders');
entry_level1_2_1_2.setAttribute('Name','Length');
entry_level1_2_1_2.setAttribute('Id','9997');
entry_level1_2_1_2.setAttribute('ColumunWidth','-1');
entry_level1_2_1.appendChild(entry_level1_2_1_2);
entry_level1_2_1_3 = docNode.createElement('AttributeHeaders');
entry_level1_2_1_3.setAttribute('Name','Area');
entry_level1_2_1_3.setAttribute('Id','9996');
entry_level1_2_1_3.setAttribute('ColumunWidth','-1');
entry_level1_2_1.appendChild(entry_level1_2_1_3);
entry_level1_2_1_4 = docNode.createElement('AttributeHeaders');
entry_level1_2_1_4.setAttribute('Name','Text');
entry_level1_2_1_4.setAttribute('Id','9998');
entry_level1_2_1_4.setAttribute('ColumunWidth','-1');
entry_level1_2_1.appendChild(entry_level1_2_1_4);
entry_level1_2_1_5 = docNode.createElement('AttributeHeaders');
entry_level1_2_1_5.setAttribute('Name','Description');
entry_level1_2_1_5.setAttribute('Id','1');
entry_level1_2_1_5.setAttribute('ColumunWidth','-1');
entry_level1_2_1.appendChild(entry_level1_2_1_5);
% draw square
% square setting.
entry_level1_2_2 = docNode.createElement('Region');
entry_level1_2.appendChild(entry_level1_2_2);
entry_level1_2_2.setAttribute('Selected','0');
entry_level1_2_2.setAttribute('Type','1');
entry_level1_2_2.setAttribute('Id','1');
entry_level1_2_2.setAttribute('DisplayId','1');
entry_level1_2_2.setAttribute('Analyze','0');
entry_level1_2_2.setAttribute('InputRegionId','0');
entry_level1_2_2.setAttribute('NegativeROA','0');
entry_level1_2_2.setAttribute('Text','');
entry_level1_2_2.setAttribute('AreaMicrons',num2str(areaCircleM));
entry_level1_2_2.setAttribute('LengthMicrons',num2str(lengthCircleM));
entry_level1_2_2.setAttribute('Area',num2str(areaCircle));
entry_level1_2_2.setAttribute('Length',num2str(lengthCircle));
entry_level1_2_2.setAttribute('ImageFocus','-1');
entry_level1_2_2.setAttribute('ImageLocation','');
entry_level1_2_2.setAttribute('Zoom','0.022562');
% square position
entry_level1_2_2_1 = docNode.createElement('Attributes');
entry_level1_2_2.appendChild(entry_level1_2_2_1);
entry_level1_2_2_2 = docNode.createElement('Vertices');
entry_level1_2_2.appendChild(entry_level1_2_2_2);
entry_level1_2_2_2_1 = docNode.createElement('Vertex');
entry_level1_2_2_2.appendChild(entry_level1_2_2_2_1);
entry_level1_2_2_2_1.setAttribute('Z',num2str(0));
entry_level1_2_2_2_1.setAttribute('Y',num2str(y1Square));
entry_level1_2_2_2_1.setAttribute('X',num2str(x1Square));
entry_level1_2_2_2_2 = docNode.createElement('Vertex');
entry_level1_2_2_2.appendChild(entry_level1_2_2_2_2);
entry_level1_2_2_2_2.setAttribute('Z',num2str(0));
entry_level1_2_2_2_2.setAttribute('Y',num2str(y2Square));
entry_level1_2_2_2_2.setAttribute('X',num2str(x2Square));
entry_level1_2_2_2_3 = docNode.createElement('Vertex');
entry_level1_2_2_2.appendChild(entry_level1_2_2_2_3);
entry_level1_2_2_2_3.setAttribute('Z',num2str(0));
entry_level1_2_2_2_3.setAttribute('Y',num2str(y3Square));
entry_level1_2_2_2_3.setAttribute('X',num2str(x3Square));
entry_level1_2_2_2_4 = docNode.createElement('Vertex');
entry_level1_2_2_2.appendChild(entry_level1_2_2_2_4);
entry_level1_2_2_2_4.setAttribute('Z',num2str(0));
entry_level1_2_2_2_4.setAttribute('Y',num2str(y4Square));
entry_level1_2_2_2_4.setAttribute('X',num2str(x4Square));
% draw circle
% circle setting.
entry_level1_2_3 = docNode.createElement('Region');
entry_level1_2.appendChild(entry_level1_2_3);
entry_level1_2_3.setAttribute('Selected','1');
entry_level1_2_3.setAttribute('Type','2');
entry_level1_2_3.setAttribute('Id','2');
entry_level1_2_3.setAttribute('DisplayId','2');
entry_level1_2_3.setAttribute('Analyze','1');
entry_level1_2_3.setAttribute('InputRegionId','0');
entry_level1_2_3.setAttribute('NegativeROA','0');
entry_level1_2_3.setAttribute('Text','');
entry_level1_2_3.setAttribute('AreaMicrons',num2str(areaSquareM));
entry_level1_2_3.setAttribute('LengthMicrons',num2str(lengthSquareM));
entry_level1_2_3.setAttribute('Area',num2str(areaSquare));
entry_level1_2_3.setAttribute('Length',num2str(lengthSquare));
entry_level1_2_3.setAttribute('ImageFocus','-1');
entry_level1_2_3.setAttribute('ImageLocation','');
entry_level1_2_3.setAttribute('Zoom','0.022562');
% circle position
entry_level1_2_3_1 = docNode.createElement('Attributes');
entry_level1_2_3.appendChild(entry_level1_2_3_1);
entry_level1_2_3_2 = docNode.createElement('Vertices');
entry_level1_2_3.appendChild(entry_level1_2_3_2);
entry_level1_2_3_2_1 = docNode.createElement('Vertex');
entry_level1_2_3_2.appendChild(entry_level1_2_3_2_1);
entry_level1_2_3_2_1.setAttribute('Z',num2str(0));
entry_level1_2_3_2_1.setAttribute('Y',num2str(y1Circle));
entry_level1_2_3_2_1.setAttribute('X',num2str(x1Circle));
entry_level1_2_3_2_2 = docNode.createElement('Vertex');
entry_level1_2_3_2.appendChild(entry_level1_2_3_2_2);
entry_level1_2_3_2_2.setAttribute('Z',num2str(0));
entry_level1_2_3_2_2.setAttribute('Y',num2str(y2Circle));
entry_level1_2_3_2_2.setAttribute('X',num2str(x2Circle));
entry_level1_2_3 = docNode.createElement('plots');
entry_level1_2.appendChild(entry_level1_2_3);
xmlwrite(filename,docNode);
% delete the first line from XML file
fid = fopen(filename, 'r') ; % Open source file.
fgetl(fid) ; % Read/discard line.
buffer = fread(fid, Inf) ; % Read rest of the file.
fclose(fid);
fid = fopen(filename, 'w') ; % Open destination file.
fwrite(fid, buffer) ; % Save to file.
fclose(fid) ;
winopen(fullname);
% [status2,cmdout2]=system(fullname);
%[status2,cmdout2]=system(fullname,'-echo');
success = 1;
catch ME
error_show(ME)
end
end