You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/Tutorials/ROI analysis.md
+65-5Lines changed: 65 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -87,8 +87,10 @@ for (const roi of biggestRois) {
87
87
This provides us with a code like this:
88
88
89
89
```ts
90
-
const rois =roiMap.getRois({ kind: 'black' }); // In this example we specifically calculate the average surface of rois,
91
-
//so we don't use minSurface option here.
90
+
const rois =roiMap.getRois({ kind: 'black' });
91
+
// In this example we want to specifically calculate
92
+
//the average surface of rois, so we don't use
93
+
// minSurface option here.
92
94
93
95
let surfaceSum =0;
94
96
for (const roi ofrois) {
@@ -129,17 +131,75 @@ There you will have other two parts: one part will be comprised of a map with fi
129
131
130
132
### Getting extra data
131
133
132
-
Within metadata, you might be wondering what is this huge mix of letters and numbers:
134
+
Within metadata, you might be wondering what this huge mix of letters and numbers represents:
133
135
134
136

135
137
136
138
These are custom fields added with additional information about an image that the user. For instance, in this case you can get information about the microscope that was used, or the magnification level or the electrometric tension that was used while the image was taken. However, this data needs to be parsed, because it difficult to decipher it in its raw format.
137
-
To do so you need to split the lines first:
139
+
To do so you need to identify what is the key id of this text. In our case it is 34682, but it might not always be the case so check it beforehand.
138
140
139
-
```
141
+
Next thing we need to do is to parse this text.
140
142
143
+
```ts
144
+
let metaMisc = [];
145
+
146
+
let lines =image.meta.tiff.fields.get(34682).split('</Data><Data>');
147
+
//We split each line into three elements:
148
+
//key(name of the tag)
149
+
//value(value of the tag)
150
+
//unit(units in which the value is measured).
151
+
lines.forEach((a) => {
152
+
var fields =a.split(/<\/Label><Value>|<\/Value><Unit>/);
153
+
fields[0] =fields[0].replace(/^.*>/, '');
154
+
fields[2] =fields[2].replace(/<.*$/, '');
155
+
metaMisc.push({
156
+
key: fields[0],
157
+
value: fields[1],
158
+
unit: fields[2],
159
+
});
160
+
});
141
161
```
142
162
163
+
With this the data should be parsed.
164
+
143
165

144
166
145
167
### Getting pixel size
168
+
169
+
In this specific scenario we would also like to tell you about the way to calculate image's pixel size. Pixel size can be one of metadata fields but if this isn't the case we would like to show you how you can calculate it from existing data.
170
+
171
+
If there is no such field as "Pixel size" you can calculate DPI resolution and apply it with magnification.
172
+
DPI resolution represents the number of dots per inch. To calculate it we need to look at three lines in our parsed extra data: XResolution, YResolution and ResolutionUnit.
173
+
X and Y resolutions are the number of dots per inch on X and Y axes. So, if they are equal, then DPI resolution equals to one of these values. However, this value might not be measured in inches. To check that we need to look at ResolutionUnit.
174
+
If its value equals to 2 then the X and Y resolutions are measured in inches.If it's 3 then it's in centimeters and has to be converted.
175
+
176
+
**image of three extra data fields**
177
+
178
+
```ts
179
+
const DPIResolution =0;
180
+
const metaTags =image.meta.tiff.tags;
181
+
if (metaTags.XResolution==metaTags.YResolution&&metaTags.XResolution) {
182
+
switch(metaTags.ResolutionUnit)
183
+
case 2:
184
+
DPIResolution = metaTags.XResolution;
185
+
break;
186
+
case 3:
187
+
//converted from centimeters to inches
188
+
DPIResolution = metaTags.Xresolution*2.54;
189
+
break;
190
+
default:
191
+
break;
192
+
}
193
+
```
194
+
195
+
After that we need to get the magnification. In our case it is already known.
196
+
**get magnification image**
197
+
198
+
All is left is to calculate it through the formula.
0 commit comments