Skip to content

Commit 63a2f96

Browse files
author
hackermd
committed
Fix three-dimensional spatial coordinates
* Add offsets to x and y coordinate * Set z offset to zero instead of one (projected onto the glass slide)
1 parent 74ba718 commit 63a2f96

File tree

4 files changed

+79
-61
lines changed

4 files changed

+79
-61
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "dicom-microscopy-viewer",
3-
"version": "0.4.2",
3+
"version": "0.4.3",
44
"description": "Interactive web-based viewer for DICOM Microscopy Images",
55
"main": "build/dicom-microscopy-viewer.js",
66
"scripts": {

src/api.js

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ function _scoord3d2Geometry(scoord3d, pyramid) {
132132
[
133133
(point1[0] + point2[0]) / parseFloat(2),
134134
(point1[1] + point2[1]) / parseFloat(2),
135-
1
135+
0
136136
],
137137
point2
138138
];
@@ -163,35 +163,53 @@ function _scoord3dCoordinates2geometryCoordinates(coordinates, pyramid) {
163163
* slide coordinate system
164164
*/
165165
function _coordinateFormatGeometry2Scoord3d(coordinates, pyramid) {
166-
if(coordinates.length === 3){
166+
let transform = false;
167+
if(!(coordinates[0] instanceof Array)) {
167168
coordinates = [coordinates];
169+
transform = true;
168170
}
169-
coordinates.map(coord =>{
170-
const pixelSpacing = _getPixelSpacing(pyramid[pyramid.length-1]);
171-
const x = (coord[0] * pixelSpacing[0]).toFixed(4);
172-
const y = (-(coord[1] - 1) * pixelSpacing[1]).toFixed(4);
173-
const z = (1).toFixed(4);
174-
coordinates = [Number(x), Number(y), Number(z)];
175-
})
176-
return(coordinates);
171+
const metadata = pyramid[pyramid.length-1];
172+
const origin = metadata.TotalPixelMatrixOriginSequence[0];
173+
const xOffset = Number(origin.XOffsetInSlideCoordinateSystem);
174+
const yOffset = Number(origin.YOffsetInSlideCoordinateSystem);
175+
const pixelSpacing = _getPixelSpacing(metadata);
176+
coordinates = coordinates.map(point => {
177+
const x = Number((xOffset + (point[0] * pixelSpacing[0])).toFixed(4));
178+
const y = Number((yOffset - ((point[1] - 1) * pixelSpacing[1])).toFixed(4));
179+
const z = Number((0).toFixed(4));
180+
return [x, y, z];
181+
});
182+
if (transform) {
183+
return coordinates[0];
184+
}
185+
return coordinates;
177186
}
178187

179188
/*
180189
* Translate millimeters into pixel units of total pixel matrix of
181190
* slide coordinate system
182191
*/
183192
function _coordinateFormatScoord3d2Geometry(coordinates, pyramid) {
184-
if(coordinates.length === 3){
193+
let transform = false;
194+
if(!(coordinates[0] instanceof Array)) {
185195
coordinates = [coordinates];
196+
transform = true;
186197
}
187-
coordinates.map(coord =>{
198+
const metadata = pyramid[pyramid.length-1];
199+
const origin = metadata.TotalPixelMatrixOriginSequence[0];
200+
const xOffset = Number(origin.XOffsetInSlideCoordinateSystem);
201+
const yOffset = Number(origin.YOffsetInSlideCoordinateSystem);
202+
coordinates = coordinates.map(coord =>{
188203
const pixelSpacing = _getPixelSpacing(pyramid[pyramid.length-1]);
189-
const x = (coord[0] / pixelSpacing[0] - 1);
190-
const y = -(coord[1] /pixelSpacing[1] - 1);
204+
const x = (coord[0] / pixelSpacing[0] - 1) - xOffset;
205+
const y = -(coord[1] /pixelSpacing[1] - 1) - yOffset;
191206
const z = coord[2];
192-
coordinates = [x, y, z];
207+
return [x, y, z];
193208
});
194-
return(coordinates);
209+
if (transform) {
210+
return coordinates[0];
211+
}
212+
return coordinates;
195213
}
196214

197215
function _getROIFromFeature(feature, pyramid){

test/api.spec.js

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -13,77 +13,77 @@ describe('dicomMicroscopyViewer.api.VLWholeSlideMicroscopyImageViewer', ()=> {
1313
const properties = {};
1414
const ellipse = new dicomMicroscopyViewer.scoord3d.Ellipse({
1515
coordinates: [
16-
[8.0, 9.2, 1],
17-
[8.4, 9.2, 1],
18-
[8.2, 9.0, 1],
19-
[8.2, 9.4, 1]
16+
[8.0, 9.2, 0],
17+
[8.4, 9.2, 0],
18+
[8.2, 9.0, 0],
19+
[8.2, 9.4, 0]
2020
],
2121
frameOfReferenceUID: '1.2.3'
2222
});
2323
const point = new dicomMicroscopyViewer.scoord3d.Point({
24-
coordinates: [9.0467, 8.7631, 1],
24+
coordinates: [9.0467, 8.7631, 0],
2525
frameOfReferenceUID: '1.2.3'
2626
});
2727
const box = new dicomMicroscopyViewer.scoord3d.Polyline({
2828
coordinates: [
29-
[8.8824, 8.8684, 1],
30-
[9.2255, 9.9634, 1],
31-
[10.3205, 9.6203, 1],
32-
[9.9774, 8.5253, 1],
33-
[8.8824, 8.8684, 1]
29+
[8.8824, 8.8684, 0],
30+
[9.2255, 9.9634, 0],
31+
[10.3205, 9.6203, 0],
32+
[9.9774, 8.5253, 0],
33+
[8.8824, 8.8684, 0]
3434
],
3535
frameOfReferenceUID: '1.2.3'
3636
})
3737
const polygon = new dicomMicroscopyViewer.scoord3d.Polyline({
3838
coordinates: [
39-
[7.8326, 8.4428, 1],
40-
[7.1919, 7.9169, 1],
41-
[8.7772, 7.2831, 1],
42-
[7.8326, 8.4428, 1]
39+
[7.8326, 8.4428, 0],
40+
[7.1919, 7.9169, 0],
41+
[8.7772, 7.2831, 0],
42+
[7.8326, 8.4428, 0]
4343
],
4444
frameOfReferenceUID: '1.2.3'
4545
})
4646
const freehandPolygon = new dicomMicroscopyViewer.scoord3d.Polyline({
4747
coordinates: [
48-
[6.9340, 7.0669, 1],
49-
[6.9340, 7.0669, 1],
50-
[6.9189, 7.0216, 1],
51-
[6.9114, 6.9973, 1],
52-
[6.9114, 6.9797, 1],
53-
[6.9139, 6.9621, 1],
54-
[6.9216, 6.9470, 1],
55-
[6.9292, 6.9344, 1],
56-
[6.9419, 6.9294, 1],
57-
[6.9496, 6.9269, 1],
58-
[6.9597, 6.9243, 1],
59-
[6.9674, 6.9243, 1],
60-
[6.9674, 6.9243, 1],
61-
[6.9340, 7.0669, 1]
48+
[6.9340, 7.0669, 0],
49+
[6.9340, 7.0669, 0],
50+
[6.9189, 7.0216, 0],
51+
[6.9114, 6.9973, 0],
52+
[6.9114, 6.9797, 0],
53+
[6.9139, 6.9621, 0],
54+
[6.9216, 6.9470, 0],
55+
[6.9292, 6.9344, 0],
56+
[6.9419, 6.9294, 0],
57+
[6.9496, 6.9269, 0],
58+
[6.9597, 6.9243, 0],
59+
[6.9674, 6.9243, 0],
60+
[6.9674, 6.9243, 0],
61+
[6.9340, 7.0669, 0]
6262
],
6363
frameOfReferenceUID: '1.2.3'
6464
})
6565
const line = new dicomMicroscopyViewer.scoord3d.Polyline({
6666
coordinates: [
67-
[7.0442, 7.5295, 1],
68-
[7.6725, 7.0580, 1]
67+
[7.0442, 7.5295, 0],
68+
[7.6725, 7.0580, 0]
6969
],
7070
frameOfReferenceUID: '1.2.3'
7171
})
7272
const freeHandLine = new dicomMicroscopyViewer.scoord3d.Polyline({
7373
coordinates: [
74-
[6.6769, 9.1169, 1],
75-
[6.6769, 9.1169, 1],
76-
[6.6668, 9.1119, 1],
77-
[6.6567, 9.1043, 1],
78-
[6.6366, 9.0817, 1],
79-
[6.6182, 9.0423, 1],
80-
[6.6182, 9.0322, 1],
81-
[6.6182, 9.0197, 1],
82-
[6.6233, 9.0096, 1],
83-
[6.6258, 9.0020, 1],
84-
[6.6284, 8.9995, 1],
85-
[6.6334, 8.9945, 1],
86-
[6.6360, 8.9945, 1]
74+
[6.6769, 9.1169, 0],
75+
[6.6769, 9.1169, 0],
76+
[6.6668, 9.1119, 0],
77+
[6.6567, 9.1043, 0],
78+
[6.6366, 9.0817, 0],
79+
[6.6182, 9.0423, 0],
80+
[6.6182, 9.0322, 0],
81+
[6.6182, 9.0197, 0],
82+
[6.6233, 9.0096, 0],
83+
[6.6258, 9.0020, 0],
84+
[6.6284, 8.9995, 0],
85+
[6.6334, 8.9945, 0],
86+
[6.6360, 8.9945, 0]
8787
],
8888
frameOfReferenceUID: '1.2.3'
8989
})

0 commit comments

Comments
 (0)