@loaders.gl/geotiff 3.1.3 → 4.0.0-alpha.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundle.js +2 -24
- package/dist/bundle.js.map +1 -0
- package/dist/index.js +3 -10
- package/dist/index.js.map +1 -0
- package/dist/lib/load-geotiff.js +31 -56
- package/dist/lib/load-geotiff.js.map +1 -0
- package/dist/lib/ome/load-ome-tiff.js +50 -45
- package/dist/lib/ome/load-ome-tiff.js.map +1 -0
- package/dist/lib/ome/ome-indexers.js +112 -104
- package/dist/lib/ome/ome-indexers.js.map +1 -0
- package/dist/lib/ome/ome-utils.js +69 -59
- package/dist/lib/ome/ome-utils.js.map +1 -0
- package/dist/lib/ome/omexml.js +60 -60
- package/dist/lib/ome/omexml.js.map +1 -0
- package/dist/lib/ome/utils.js +18 -27
- package/dist/lib/ome/utils.js.map +1 -0
- package/dist/lib/tiff-pixel-source.js +106 -59
- package/dist/lib/tiff-pixel-source.js.map +1 -0
- package/dist/lib/utils/Pool.js +72 -78
- package/dist/lib/utils/Pool.js.map +1 -0
- package/dist/{es5/lib → lib}/utils/decoder.worker.ts.disabled +0 -0
- package/dist/lib/utils/proxies.js +56 -79
- package/dist/lib/utils/proxies.js.map +1 -0
- package/dist/lib/utils/tiff-utils.js +24 -40
- package/dist/lib/utils/tiff-utils.js.map +1 -0
- package/dist/types.js +2 -2
- package/dist/{es5/types.js.map → types.js.map} +0 -0
- package/dist/typings/geotiff.js +2 -1
- package/dist/{es5/typings → typings}/geotiff.js.map +0 -0
- package/package.json +4 -4
- package/dist/es5/bundle.js +0 -13
- package/dist/es5/bundle.js.map +0 -1
- package/dist/es5/index.js +0 -24
- package/dist/es5/index.js.map +0 -1
- package/dist/es5/lib/load-geotiff.js +0 -100
- package/dist/es5/lib/load-geotiff.js.map +0 -1
- package/dist/es5/lib/ome/load-ome-tiff.js +0 -85
- package/dist/es5/lib/ome/load-ome-tiff.js.map +0 -1
- package/dist/es5/lib/ome/ome-indexers.js +0 -167
- package/dist/es5/lib/ome/ome-indexers.js.map +0 -1
- package/dist/es5/lib/ome/ome-utils.js +0 -87
- package/dist/es5/lib/ome/ome-utils.js.map +0 -1
- package/dist/es5/lib/ome/omexml.js +0 -82
- package/dist/es5/lib/ome/omexml.js.map +0 -1
- package/dist/es5/lib/ome/utils.js +0 -32
- package/dist/es5/lib/ome/utils.js.map +0 -1
- package/dist/es5/lib/tiff-pixel-source.js +0 -202
- package/dist/es5/lib/tiff-pixel-source.js.map +0 -1
- package/dist/es5/lib/utils/Pool.js +0 -173
- package/dist/es5/lib/utils/Pool.js.map +0 -1
- package/dist/es5/lib/utils/proxies.js +0 -82
- package/dist/es5/lib/utils/proxies.js.map +0 -1
- package/dist/es5/lib/utils/tiff-utils.js +0 -53
- package/dist/es5/lib/utils/tiff-utils.js.map +0 -1
- package/dist/es5/types.js +0 -2
- package/dist/es5/typings/geotiff.js +0 -2
- package/dist/esm/bundle.js +0 -4
- package/dist/esm/bundle.js.map +0 -1
- package/dist/esm/index.js +0 -3
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/lib/load-geotiff.js +0 -32
- package/dist/esm/lib/load-geotiff.js.map +0 -1
- package/dist/esm/lib/ome/load-ome-tiff.js +0 -51
- package/dist/esm/lib/ome/load-ome-tiff.js.map +0 -1
- package/dist/esm/lib/ome/ome-indexers.js +0 -116
- package/dist/esm/lib/ome/ome-indexers.js.map +0 -1
- package/dist/esm/lib/ome/ome-utils.js +0 -73
- package/dist/esm/lib/ome/ome-utils.js.map +0 -1
- package/dist/esm/lib/ome/omexml.js +0 -66
- package/dist/esm/lib/ome/omexml.js.map +0 -1
- package/dist/esm/lib/ome/utils.js +0 -21
- package/dist/esm/lib/ome/utils.js.map +0 -1
- package/dist/esm/lib/tiff-pixel-source.js +0 -111
- package/dist/esm/lib/tiff-pixel-source.js.map +0 -1
- package/dist/esm/lib/utils/Pool.js +0 -77
- package/dist/esm/lib/utils/Pool.js.map +0 -1
- package/dist/esm/lib/utils/decoder.worker.ts.disabled +0 -21
- package/dist/esm/lib/utils/proxies.js +0 -63
- package/dist/esm/lib/utils/proxies.js.map +0 -1
- package/dist/esm/lib/utils/tiff-utils.js +0 -28
- package/dist/esm/lib/utils/tiff-utils.js.map +0 -1
- package/dist/esm/types.js +0 -2
- package/dist/esm/types.js.map +0 -1
- package/dist/esm/typings/geotiff.js +0 -2
- package/dist/esm/typings/geotiff.js.map +0 -1
package/dist/bundle.js
CHANGED
|
@@ -1,26 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
-
}) : (function(o, m, k, k2) {
|
|
6
|
-
if (k2 === undefined) k2 = k;
|
|
7
|
-
o[k2] = m[k];
|
|
8
|
-
}));
|
|
9
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
-
}) : function(o, v) {
|
|
12
|
-
o["default"] = v;
|
|
13
|
-
});
|
|
14
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
-
if (mod && mod.__esModule) return mod;
|
|
16
|
-
var result = {};
|
|
17
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
-
__setModuleDefault(result, mod);
|
|
19
|
-
return result;
|
|
20
|
-
};
|
|
21
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
-
const moduleExports = __importStar(require("./index"));
|
|
23
|
-
// @ts-ignore
|
|
1
|
+
import * as moduleExports from './index';
|
|
24
2
|
globalThis.loaders = globalThis.loaders || {};
|
|
25
|
-
// @ts-ignore
|
|
26
3
|
module.exports = Object.assign(globalThis.loaders, moduleExports);
|
|
4
|
+
//# sourceMappingURL=bundle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/bundle.ts"],"names":["moduleExports","globalThis","loaders","module","exports","Object","assign"],"mappings":"AAAA,OAAO,KAAKA,aAAZ,MAA+B,SAA/B;AAEAC,UAAU,CAACC,OAAX,GAAqBD,UAAU,CAACC,OAAX,IAAsB,EAA3C;AAEAC,MAAM,CAACC,OAAP,GAAiBC,MAAM,CAACC,MAAP,CAAcL,UAAU,CAACC,OAAzB,EAAkCF,aAAlC,CAAjB","sourcesContent":["import * as moduleExports from './index';\n// @ts-ignore\nglobalThis.loaders = globalThis.loaders || {};\n// @ts-ignore\nmodule.exports = Object.assign(globalThis.loaders, moduleExports);\n"],"file":"bundle.js"}
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.TiffPixelSource = exports.loadGeoTiff = void 0;
|
|
7
|
-
var load_geotiff_1 = require("./lib/load-geotiff");
|
|
8
|
-
Object.defineProperty(exports, "loadGeoTiff", { enumerable: true, get: function () { return load_geotiff_1.loadGeoTiff; } });
|
|
9
|
-
var tiff_pixel_source_1 = require("./lib/tiff-pixel-source");
|
|
10
|
-
Object.defineProperty(exports, "TiffPixelSource", { enumerable: true, get: function () { return __importDefault(tiff_pixel_source_1).default; } });
|
|
1
|
+
export { loadGeoTiff } from './lib/load-geotiff';
|
|
2
|
+
export { default as TiffPixelSource } from './lib/tiff-pixel-source';
|
|
3
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"names":["loadGeoTiff","default","TiffPixelSource"],"mappings":"AAAA,SAAQA,WAAR,QAA0B,oBAA1B;AACA,SAAQC,OAAO,IAAIC,eAAnB,QAAyC,yBAAzC","sourcesContent":["export {loadGeoTiff} from './lib/load-geotiff';\nexport {default as TiffPixelSource} from './lib/tiff-pixel-source';\n"],"file":"index.js"}
|
package/dist/lib/load-geotiff.js
CHANGED
|
@@ -1,57 +1,32 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
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
|
-
// if (pool) {
|
|
32
|
-
/*
|
|
33
|
-
* Creates a worker pool to decode tiff tiles. Wraps tiff
|
|
34
|
-
* in a Proxy that injects 'pool' into `tiff.readRasters`.
|
|
35
|
-
*/
|
|
36
|
-
// tiff = createPoolProxy(tiff, new Pool());
|
|
37
|
-
// }
|
|
38
|
-
if (offsets) {
|
|
39
|
-
/*
|
|
40
|
-
* Performance enhancement. If offsets are provided, we
|
|
41
|
-
* create a proxy that intercepts calls to `tiff.getImage`
|
|
42
|
-
* and injects the pre-computed offsets.
|
|
43
|
-
*/
|
|
44
|
-
tiff = (0, proxies_1.createOffsetsProxy)(tiff, offsets);
|
|
45
|
-
}
|
|
46
|
-
/*
|
|
47
|
-
* Inspect tiff source for our performance enhancing proxies.
|
|
48
|
-
* Prints warnings to console if `offsets` or `pool` are missing.
|
|
49
|
-
*/
|
|
50
|
-
(0, proxies_1.checkProxies)(tiff);
|
|
51
|
-
const firstImage = await tiff.getImage(0);
|
|
52
|
-
if ((0, load_ome_tiff_1.isOmeTiff)(firstImage)) {
|
|
53
|
-
return (0, load_ome_tiff_1.loadOmeTiff)(tiff, firstImage);
|
|
54
|
-
}
|
|
55
|
-
throw new Error('GeoTIFF not recognized.');
|
|
1
|
+
import { fromUrl, fromBlob, GeoTIFF } from 'geotiff';
|
|
2
|
+
import { createOffsetsProxy, checkProxies } from './utils/proxies';
|
|
3
|
+
import { loadOmeTiff, isOmeTiff } from './ome/load-ome-tiff';
|
|
4
|
+
export async function loadGeoTiff(source, opts = {}) {
|
|
5
|
+
const {
|
|
6
|
+
headers,
|
|
7
|
+
offsets
|
|
8
|
+
} = opts;
|
|
9
|
+
let tiff;
|
|
10
|
+
|
|
11
|
+
if (source instanceof GeoTIFF) {
|
|
12
|
+
tiff = source;
|
|
13
|
+
} else if (typeof source === 'string') {
|
|
14
|
+
tiff = await fromUrl(source, headers);
|
|
15
|
+
} else {
|
|
16
|
+
tiff = await fromBlob(source);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (offsets) {
|
|
20
|
+
tiff = createOffsetsProxy(tiff, offsets);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
checkProxies(tiff);
|
|
24
|
+
const firstImage = await tiff.getImage(0);
|
|
25
|
+
|
|
26
|
+
if (isOmeTiff(firstImage)) {
|
|
27
|
+
return loadOmeTiff(tiff, firstImage);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
throw new Error('GeoTIFF not recognized.');
|
|
56
31
|
}
|
|
57
|
-
|
|
32
|
+
//# sourceMappingURL=load-geotiff.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/lib/load-geotiff.ts"],"names":["fromUrl","fromBlob","GeoTIFF","createOffsetsProxy","checkProxies","loadOmeTiff","isOmeTiff","loadGeoTiff","source","opts","headers","offsets","tiff","firstImage","getImage","Error"],"mappings":"AAAA,SAAQA,OAAR,EAAiBC,QAAjB,EAA2BC,OAA3B,QAAyC,SAAzC;AAEA,SAEEC,kBAFF,EAGEC,YAHF,QAIO,iBAJP;AAOA,SAAQC,WAAR,EAAqBC,SAArB,QAAqC,qBAArC;AA4BA,OAAO,eAAeC,WAAf,CACLC,MADK,EAELC,IAAoB,GAAG,EAFlB,EAGiB;AACtB,QAAM;AAACC,IAAAA,OAAD;AAAUC,IAAAA;AAAV,MAAqBF,IAA3B;AAGA,MAAIG,IAAJ;;AACA,MAAIJ,MAAM,YAAYN,OAAtB,EAA+B;AAC7BU,IAAAA,IAAI,GAAGJ,MAAP;AACD,GAFD,MAEO,IAAI,OAAOA,MAAP,KAAkB,QAAtB,EAAgC;AACrCI,IAAAA,IAAI,GAAG,MAAMZ,OAAO,CAACQ,MAAD,EAASE,OAAT,CAApB;AACD,GAFM,MAEA;AACLE,IAAAA,IAAI,GAAG,MAAMX,QAAQ,CAACO,MAAD,CAArB;AACD;;AAUD,MAAIG,OAAJ,EAAa;AAMXC,IAAAA,IAAI,GAAGT,kBAAkB,CAACS,IAAD,EAAOD,OAAP,CAAzB;AACD;;AAMDP,EAAAA,YAAY,CAACQ,IAAD,CAAZ;AAEA,QAAMC,UAAU,GAAG,MAAMD,IAAI,CAACE,QAAL,CAAc,CAAd,CAAzB;;AAEA,MAAIR,SAAS,CAACO,UAAD,CAAb,EAA2B;AACzB,WAAOR,WAAW,CAACO,IAAD,EAAOC,UAAP,CAAlB;AACD;;AAED,QAAM,IAAIE,KAAJ,CAAU,yBAAV,CAAN;AACD","sourcesContent":["import {fromUrl, fromBlob, GeoTIFF} from 'geotiff';\n\nimport {\n // createPoolProxy,\n createOffsetsProxy,\n checkProxies\n} from './utils/proxies';\n// import Pool from './lib/Pool';\n\nimport {loadOmeTiff, isOmeTiff} from './ome/load-ome-tiff';\nimport type TiffPixelSource from './tiff-pixel-source';\n\n/** Options for initializing a tiff pixel source. */\ninterface GeoTIFFOptions {\n /** Headers passed to each underlying request. */\n headers?: Record<string, unknown>;\n /** Performance enhancment to index the remote tiff source using pre-computed byte-offsets. Generated via https://github.com/ilan-gold/generate-tiff-offsets */\n offsets?: number[];\n /** Indicates whether a multi-threaded pool of image decoders should be used to decode tiles. */\n pool?: boolean;\n}\n\ninterface GeoTIFFData {\n data: TiffPixelSource<string[]>[];\n metadata: Record<string, unknown>;\n}\n\n/**\n * Opens an OME-TIFF via URL and returns data source and associated metadata for first image.\n *\n * @param source url string, File/Blob object, or GeoTIFF object\n * @param opts options for initializing a tiff pixel source.\n * - `opts.headers` are passed to each underlying fetch request.\n * - `opts.offsets` are a performance enhancment to index the remote tiff source using pre-computed byte-offsets.\n * - `opts.pool` indicates whether a multi-threaded pool of image decoders should be used to decode tiles (default = true).\n * @return data source and associated OME-Zarr metadata.\n */\nexport async function loadGeoTiff(\n source: string | Blob | GeoTIFF,\n opts: GeoTIFFOptions = {}\n): Promise<GeoTIFFData> {\n const {headers, offsets} = opts;\n\n // Create tiff source\n let tiff: GeoTIFF;\n if (source instanceof GeoTIFF) {\n tiff = source;\n } else if (typeof source === 'string') {\n tiff = await fromUrl(source, headers);\n } else {\n tiff = await fromBlob(source);\n }\n\n // if (pool) {\n /*\n * Creates a worker pool to decode tiff tiles. Wraps tiff\n * in a Proxy that injects 'pool' into `tiff.readRasters`.\n */\n // tiff = createPoolProxy(tiff, new Pool());\n // }\n\n if (offsets) {\n /*\n * Performance enhancement. If offsets are provided, we\n * create a proxy that intercepts calls to `tiff.getImage`\n * and injects the pre-computed offsets.\n */\n tiff = createOffsetsProxy(tiff, offsets);\n }\n\n /*\n * Inspect tiff source for our performance enhancing proxies.\n * Prints warnings to console if `offsets` or `pool` are missing.\n */\n checkProxies(tiff);\n\n const firstImage = await tiff.getImage(0);\n\n if (isOmeTiff(firstImage)) {\n return loadOmeTiff(tiff, firstImage);\n }\n\n throw new Error('GeoTIFF not recognized.');\n}\n"],"file":"load-geotiff.js"}
|
|
@@ -1,46 +1,51 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const
|
|
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
|
-
return
|
|
1
|
+
import TiffPixelSource from '../tiff-pixel-source';
|
|
2
|
+
import { getOmeLegacyIndexer, getOmeSubIFDIndexer } from './ome-indexers';
|
|
3
|
+
import { getOmePixelSourceMeta } from './ome-utils';
|
|
4
|
+
import { fromString } from './omexml';
|
|
5
|
+
export const isOmeTiff = img => img.fileDirectory.ImageDescription.includes('<OME');
|
|
6
|
+
export async function loadOmeTiff(tiff, firstImage) {
|
|
7
|
+
const {
|
|
8
|
+
ImageDescription,
|
|
9
|
+
SubIFDs,
|
|
10
|
+
PhotometricInterpretation: photometricInterpretation
|
|
11
|
+
} = firstImage.fileDirectory;
|
|
12
|
+
const omexml = fromString(ImageDescription);
|
|
13
|
+
let levels;
|
|
14
|
+
let pyramidIndexer;
|
|
15
|
+
|
|
16
|
+
if (SubIFDs) {
|
|
17
|
+
levels = SubIFDs.length + 1;
|
|
18
|
+
pyramidIndexer = getOmeSubIFDIndexer(tiff, omexml);
|
|
19
|
+
} else {
|
|
20
|
+
levels = omexml.length;
|
|
21
|
+
pyramidIndexer = getOmeLegacyIndexer(tiff, omexml);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const imgMeta = omexml[0];
|
|
25
|
+
const {
|
|
26
|
+
labels,
|
|
27
|
+
getShape,
|
|
28
|
+
physicalSizes,
|
|
29
|
+
dtype
|
|
30
|
+
} = getOmePixelSourceMeta(imgMeta);
|
|
31
|
+
const tileSize = firstImage.getTileWidth();
|
|
32
|
+
const meta = {
|
|
33
|
+
photometricInterpretation,
|
|
34
|
+
physicalSizes
|
|
35
|
+
};
|
|
36
|
+
const data = Array.from({
|
|
37
|
+
length: levels
|
|
38
|
+
}).map((_, resolution) => {
|
|
39
|
+
const shape = getShape(resolution);
|
|
40
|
+
|
|
41
|
+
const indexer = sel => pyramidIndexer(sel, resolution);
|
|
42
|
+
|
|
43
|
+
const source = new TiffPixelSource(indexer, dtype, tileSize, shape, labels, meta);
|
|
44
|
+
return source;
|
|
45
|
+
});
|
|
46
|
+
return {
|
|
47
|
+
data,
|
|
48
|
+
metadata: imgMeta
|
|
49
|
+
};
|
|
45
50
|
}
|
|
46
|
-
|
|
51
|
+
//# sourceMappingURL=load-ome-tiff.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/ome/load-ome-tiff.ts"],"names":["TiffPixelSource","getOmeLegacyIndexer","getOmeSubIFDIndexer","getOmePixelSourceMeta","fromString","isOmeTiff","img","fileDirectory","ImageDescription","includes","loadOmeTiff","tiff","firstImage","SubIFDs","PhotometricInterpretation","photometricInterpretation","omexml","levels","pyramidIndexer","length","imgMeta","labels","getShape","physicalSizes","dtype","tileSize","getTileWidth","meta","data","Array","from","map","_","resolution","shape","indexer","sel","source","metadata"],"mappings":"AAEA,OAAOA,eAAP,MAA4B,sBAA5B;AACA,SAAQC,mBAAR,EAA6BC,mBAA7B,QAAuE,gBAAvE;AACA,SAAQC,qBAAR,QAAoC,aAApC;AACA,SAAQC,UAAR,QAAyB,UAAzB;AAGA,OAAO,MAAMC,SAAS,GAAIC,GAAD,IAAuBA,GAAG,CAACC,aAAJ,CAAkBC,gBAAlB,CAAmCC,QAAnC,CAA4C,MAA5C,CAAzC;AAEP,OAAO,eAAeC,WAAf,CAA2BC,IAA3B,EAA0CC,UAA1C,EAAoE;AAEzE,QAAM;AACJJ,IAAAA,gBADI;AAEJK,IAAAA,OAFI;AAGJC,IAAAA,yBAAyB,EAAEC;AAHvB,MAIFH,UAAU,CAACL,aAJf;AAKA,QAAMS,MAAM,GAAGZ,UAAU,CAACI,gBAAD,CAAzB;AAMA,MAAIS,MAAJ;AACA,MAAIC,cAAJ;;AAEA,MAAIL,OAAJ,EAAa;AAEXI,IAAAA,MAAM,GAAGJ,OAAO,CAACM,MAAR,GAAiB,CAA1B;AACAD,IAAAA,cAAc,GAAGhB,mBAAmB,CAACS,IAAD,EAAOK,MAAP,CAApC;AACD,GAJD,MAIO;AAELC,IAAAA,MAAM,GAAGD,MAAM,CAACG,MAAhB;AACAD,IAAAA,cAAc,GAAGjB,mBAAmB,CAACU,IAAD,EAAOK,MAAP,CAApC;AACD;;AAGD,QAAMI,OAAO,GAAGJ,MAAM,CAAC,CAAD,CAAtB;AACA,QAAM;AAACK,IAAAA,MAAD;AAASC,IAAAA,QAAT;AAAmBC,IAAAA,aAAnB;AAAkCC,IAAAA;AAAlC,MAA2CrB,qBAAqB,CAACiB,OAAD,CAAtE;AACA,QAAMK,QAAQ,GAAGb,UAAU,CAACc,YAAX,EAAjB;AACA,QAAMC,IAAI,GAAG;AAACZ,IAAAA,yBAAD;AAA4BQ,IAAAA;AAA5B,GAAb;AAEA,QAAMK,IAAI,GAAGC,KAAK,CAACC,IAAN,CAAW;AAACX,IAAAA,MAAM,EAAEF;AAAT,GAAX,EAA6Bc,GAA7B,CAAiC,CAACC,CAAD,EAAIC,UAAJ,KAAmB;AAC/D,UAAMC,KAAK,GAAGZ,QAAQ,CAACW,UAAD,CAAtB;;AACA,UAAME,OAAO,GAAIC,GAAD,IAA2BlB,cAAc,CAACkB,GAAD,EAAMH,UAAN,CAAzD;;AACA,UAAMI,MAAM,GAAG,IAAIrC,eAAJ,CAAoBmC,OAApB,EAA6BX,KAA7B,EAAoCC,QAApC,EAA8CS,KAA9C,EAAqDb,MAArD,EAA6DM,IAA7D,CAAf;AACA,WAAOU,MAAP;AACD,GALY,CAAb;AAOA,SAAO;AAACT,IAAAA,IAAD;AAAOU,IAAAA,QAAQ,EAAElB;AAAjB,GAAP;AACD","sourcesContent":["import type {GeoTIFF, GeoTIFFImage} from 'geotiff';\n\nimport TiffPixelSource from '../tiff-pixel-source';\nimport {getOmeLegacyIndexer, getOmeSubIFDIndexer, OmeTiffIndexer} from './ome-indexers';\nimport {getOmePixelSourceMeta} from './ome-utils';\nimport {fromString} from './omexml';\nimport type {OmeTiffSelection} from './ome-indexers';\n\nexport const isOmeTiff = (img: GeoTIFFImage) => img.fileDirectory.ImageDescription.includes('<OME');\n\nexport async function loadOmeTiff(tiff: GeoTIFF, firstImage: GeoTIFFImage) {\n // Get first image from tiff and inspect OME-XML metadata\n const {\n ImageDescription,\n SubIFDs,\n PhotometricInterpretation: photometricInterpretation\n } = firstImage.fileDirectory;\n const omexml = fromString(ImageDescription);\n\n /*\n * Image pyramids are stored differently between versions of Bioformats.\n * Thus we need a different indexer depending on which format we have.\n */\n let levels: number;\n let pyramidIndexer: OmeTiffIndexer;\n\n if (SubIFDs) {\n // Image is >= Bioformats 6.0 and resolutions are stored using SubIFDs.\n levels = SubIFDs.length + 1;\n pyramidIndexer = getOmeSubIFDIndexer(tiff, omexml);\n } else {\n // Image is legacy format; resolutions are stored as separate images.\n levels = omexml.length;\n pyramidIndexer = getOmeLegacyIndexer(tiff, omexml);\n }\n\n // TODO: The OmeTIFF loader only works for the _first_ image in the metadata.\n const imgMeta = omexml[0];\n const {labels, getShape, physicalSizes, dtype} = getOmePixelSourceMeta(imgMeta);\n const tileSize = firstImage.getTileWidth();\n const meta = {photometricInterpretation, physicalSizes};\n\n const data = Array.from({length: levels}).map((_, resolution) => {\n const shape = getShape(resolution);\n const indexer = (sel: OmeTiffSelection) => pyramidIndexer(sel, resolution);\n const source = new TiffPixelSource(indexer, dtype, tileSize, shape, labels, meta);\n return source;\n });\n\n return {data, metadata: imgMeta};\n}\n"],"file":"load-ome-tiff.js"}
|
|
@@ -1,108 +1,116 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
* TODO: We currently only support indexing the first image in the OME-TIFF with
|
|
15
|
-
* our indexers. There can be multiple images in an OME-TIFF, so supporting these
|
|
16
|
-
* images will require extending these indexers or creating new methods.
|
|
17
|
-
*/
|
|
18
|
-
/*
|
|
19
|
-
* Returns an indexer for legacy Bioformats images. This assumes that
|
|
20
|
-
* downsampled resolutions are stored sequentially in the OME-TIFF.
|
|
21
|
-
*/
|
|
22
|
-
function getOmeLegacyIndexer(tiff, rootMeta) {
|
|
23
|
-
const imgMeta = rootMeta[0];
|
|
24
|
-
const { SizeT, SizeC, SizeZ } = imgMeta.Pixels;
|
|
25
|
-
const ifdIndexer = getOmeIFDIndexer(imgMeta);
|
|
26
|
-
return (sel, pyramidLevel) => {
|
|
27
|
-
// Get IFD index at base pyramid level
|
|
28
|
-
const index = ifdIndexer(sel);
|
|
29
|
-
// Get index of first image at pyramidal level
|
|
30
|
-
const pyramidIndex = pyramidLevel * SizeZ * SizeT * SizeC;
|
|
31
|
-
// Return image at IFD index for pyramidal level
|
|
32
|
-
return tiff.getImage(index + pyramidIndex);
|
|
33
|
-
};
|
|
1
|
+
export function getOmeLegacyIndexer(tiff, rootMeta) {
|
|
2
|
+
const imgMeta = rootMeta[0];
|
|
3
|
+
const {
|
|
4
|
+
SizeT,
|
|
5
|
+
SizeC,
|
|
6
|
+
SizeZ
|
|
7
|
+
} = imgMeta.Pixels;
|
|
8
|
+
const ifdIndexer = getOmeIFDIndexer(imgMeta);
|
|
9
|
+
return (sel, pyramidLevel) => {
|
|
10
|
+
const index = ifdIndexer(sel);
|
|
11
|
+
const pyramidIndex = pyramidLevel * SizeZ * SizeT * SizeC;
|
|
12
|
+
return tiff.getImage(index + pyramidIndex);
|
|
13
|
+
};
|
|
34
14
|
}
|
|
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
|
-
// Get IFD for the selection at the pyramidal level
|
|
66
|
-
const key = `${sel.t}-${sel.c}-${sel.z}-${pyramidLevel}`;
|
|
67
|
-
if (!ifdCache.has(key)) {
|
|
68
|
-
// Only create a new request if we don't have the key.
|
|
69
|
-
const subIfdOffset = SubIFDs[pyramidLevel - 1];
|
|
70
|
-
ifdCache.set(key, tiff.parseFileDirectoryAt(subIfdOffset));
|
|
71
|
-
}
|
|
72
|
-
const ifd = (await ifdCache.get(key));
|
|
73
|
-
// Create a new image object manually from IFD
|
|
74
|
-
// https://github.com/geotiffjs/geotiff.js/blob/8ef472f41b51d18074aece2300b6a8ad91a21ae1/src/geotiff.js#L447-L453
|
|
75
|
-
return new baseImage.constructor(ifd.fileDirectory, ifd.geoKeyDirectory, tiff.dataView, tiff.littleEndian, tiff.cache, tiff.source);
|
|
76
|
-
};
|
|
15
|
+
export function getOmeSubIFDIndexer(tiff, rootMeta) {
|
|
16
|
+
const imgMeta = rootMeta[0];
|
|
17
|
+
const ifdIndexer = getOmeIFDIndexer(imgMeta);
|
|
18
|
+
const ifdCache = new Map();
|
|
19
|
+
return async (sel, pyramidLevel) => {
|
|
20
|
+
const index = ifdIndexer(sel);
|
|
21
|
+
const baseImage = await tiff.getImage(index);
|
|
22
|
+
|
|
23
|
+
if (pyramidLevel === 0) {
|
|
24
|
+
return baseImage;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const {
|
|
28
|
+
SubIFDs
|
|
29
|
+
} = baseImage.fileDirectory;
|
|
30
|
+
|
|
31
|
+
if (!SubIFDs) {
|
|
32
|
+
throw Error('Indexing Error: OME-TIFF is missing SubIFDs.');
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const key = "".concat(sel.t, "-").concat(sel.c, "-").concat(sel.z, "-").concat(pyramidLevel);
|
|
36
|
+
|
|
37
|
+
if (!ifdCache.has(key)) {
|
|
38
|
+
const subIfdOffset = SubIFDs[pyramidLevel - 1];
|
|
39
|
+
ifdCache.set(key, tiff.parseFileDirectoryAt(subIfdOffset));
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const ifd = await ifdCache.get(key);
|
|
43
|
+
return new baseImage.constructor(ifd.fileDirectory, ifd.geoKeyDirectory, tiff.dataView, tiff.littleEndian, tiff.cache, tiff.source);
|
|
44
|
+
};
|
|
77
45
|
}
|
|
78
|
-
|
|
79
|
-
/*
|
|
80
|
-
* Returns a function that computes the image index based on the dimension
|
|
81
|
-
* order and dimension sizes.
|
|
82
|
-
*/
|
|
46
|
+
|
|
83
47
|
function getOmeIFDIndexer(imgMeta) {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
48
|
+
const {
|
|
49
|
+
SizeC,
|
|
50
|
+
SizeZ,
|
|
51
|
+
SizeT,
|
|
52
|
+
DimensionOrder
|
|
53
|
+
} = imgMeta.Pixels;
|
|
54
|
+
|
|
55
|
+
switch (DimensionOrder) {
|
|
56
|
+
case 'XYZCT':
|
|
57
|
+
{
|
|
58
|
+
return ({
|
|
59
|
+
t,
|
|
60
|
+
c,
|
|
61
|
+
z
|
|
62
|
+
}) => t * SizeZ * SizeC + c * SizeZ + z;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
case 'XYZTC':
|
|
66
|
+
{
|
|
67
|
+
return ({
|
|
68
|
+
t,
|
|
69
|
+
c,
|
|
70
|
+
z
|
|
71
|
+
}) => c * SizeZ * SizeT + t * SizeZ + z;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
case 'XYCTZ':
|
|
75
|
+
{
|
|
76
|
+
return ({
|
|
77
|
+
t,
|
|
78
|
+
c,
|
|
79
|
+
z
|
|
80
|
+
}) => z * SizeC * SizeT + t * SizeC + c;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
case 'XYCZT':
|
|
84
|
+
{
|
|
85
|
+
return ({
|
|
86
|
+
t,
|
|
87
|
+
c,
|
|
88
|
+
z
|
|
89
|
+
}) => t * SizeC * SizeZ + z * SizeC + c;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
case 'XYTCZ':
|
|
93
|
+
{
|
|
94
|
+
return ({
|
|
95
|
+
t,
|
|
96
|
+
c,
|
|
97
|
+
z
|
|
98
|
+
}) => z * SizeT * SizeC + c * SizeT + t;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
case 'XYTZC':
|
|
102
|
+
{
|
|
103
|
+
return ({
|
|
104
|
+
t,
|
|
105
|
+
c,
|
|
106
|
+
z
|
|
107
|
+
}) => c * SizeT * SizeZ + z * SizeT + t;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
default:
|
|
111
|
+
{
|
|
112
|
+
throw new Error("Invalid OME-XML DimensionOrder, got ".concat(DimensionOrder, "."));
|
|
113
|
+
}
|
|
114
|
+
}
|
|
108
115
|
}
|
|
116
|
+
//# sourceMappingURL=ome-indexers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/ome/ome-indexers.ts"],"names":["getOmeLegacyIndexer","tiff","rootMeta","imgMeta","SizeT","SizeC","SizeZ","Pixels","ifdIndexer","getOmeIFDIndexer","sel","pyramidLevel","index","pyramidIndex","getImage","getOmeSubIFDIndexer","ifdCache","Map","baseImage","SubIFDs","fileDirectory","Error","key","t","c","z","has","subIfdOffset","set","parseFileDirectoryAt","ifd","get","constructor","geoKeyDirectory","dataView","littleEndian","cache","source","DimensionOrder"],"mappings":"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","sourcesContent":["import type {GeoTIFFImage, GeoTIFF, ImageFileDirectory} from 'geotiff';\nimport type {OMEXML} from '../ome/omexml';\n\nexport type OmeTiffSelection = {t: number; c: number; z: number};\nexport type OmeTiffIndexer = (sel: OmeTiffSelection, z: number) => Promise<GeoTIFFImage>;\n\n/*\n * An \"indexer\" for a GeoTIFF-based source is a function that takes a\n * \"selection\" (e.g. { z, t, c }) and returns a Promise for the GeoTIFFImage\n * object corresponding to that selection.\n *\n * For OME-TIFF images, the \"selection\" object is the same regardless of\n * the format version. However, modern version of Bioformats have a different\n * memory layout for pyramidal resolutions. Thus, we have two different \"indexers\"\n * depending on which format version is detected.\n *\n * TODO: We currently only support indexing the first image in the OME-TIFF with\n * our indexers. There can be multiple images in an OME-TIFF, so supporting these\n * images will require extending these indexers or creating new methods.\n */\n\n/*\n * Returns an indexer for legacy Bioformats images. This assumes that\n * downsampled resolutions are stored sequentially in the OME-TIFF.\n */\nexport function getOmeLegacyIndexer(tiff: GeoTIFF, rootMeta: OMEXML): OmeTiffIndexer {\n const imgMeta = rootMeta[0];\n const {SizeT, SizeC, SizeZ} = imgMeta.Pixels;\n const ifdIndexer = getOmeIFDIndexer(imgMeta);\n\n return (sel: OmeTiffSelection, pyramidLevel: number) => {\n // Get IFD index at base pyramid level\n const index = ifdIndexer(sel);\n // Get index of first image at pyramidal level\n const pyramidIndex = pyramidLevel * SizeZ * SizeT * SizeC;\n // Return image at IFD index for pyramidal level\n return tiff.getImage(index + pyramidIndex);\n };\n}\n\n/*\n * Returns an indexer for modern Bioforamts images that store multiscale\n * resolutions using SubIFDs.\n *\n * The ifdIndexer returns the 'index' to the base resolution for a\n * particular 'selection'. The SubIFDs to the downsampled resolutions\n * of the 'selection' are stored within the `baseImage.fileDirectory`.\n * We use the SubIFDs to get the IFD for the corresponding sub-resolution.\n *\n * NOTE: This function create a custom IFD cache rather than mutating\n * `GeoTIFF.ifdRequests` with a random offset. The IFDs are cached in\n * an ES6 Map that maps a string key that identifies the selection uniquely\n * to the corresponding IFD.\n */\nexport function getOmeSubIFDIndexer(tiff: GeoTIFF, rootMeta: OMEXML): OmeTiffIndexer {\n const imgMeta = rootMeta[0];\n const ifdIndexer = getOmeIFDIndexer(imgMeta);\n const ifdCache: Map<string, Promise<ImageFileDirectory>> = new Map();\n\n return async (sel: OmeTiffSelection, pyramidLevel: number) => {\n const index = ifdIndexer(sel);\n const baseImage = await tiff.getImage(index);\n\n // It's the highest resolution, no need to look up SubIFDs.\n if (pyramidLevel === 0) {\n return baseImage;\n }\n\n const {SubIFDs} = baseImage.fileDirectory;\n if (!SubIFDs) {\n throw Error('Indexing Error: OME-TIFF is missing SubIFDs.');\n }\n\n // Get IFD for the selection at the pyramidal level\n const key = `${sel.t}-${sel.c}-${sel.z}-${pyramidLevel}`;\n if (!ifdCache.has(key)) {\n // Only create a new request if we don't have the key.\n const subIfdOffset = SubIFDs[pyramidLevel - 1];\n ifdCache.set(key, tiff.parseFileDirectoryAt(subIfdOffset));\n }\n const ifd = (await ifdCache.get(key)) as ImageFileDirectory;\n\n // Create a new image object manually from IFD\n // https://github.com/geotiffjs/geotiff.js/blob/8ef472f41b51d18074aece2300b6a8ad91a21ae1/src/geotiff.js#L447-L453\n return new (baseImage.constructor as any)(\n ifd.fileDirectory,\n ifd.geoKeyDirectory,\n tiff.dataView,\n tiff.littleEndian,\n tiff.cache,\n tiff.source\n ) as GeoTIFFImage;\n };\n}\n\n/*\n * Returns a function that computes the image index based on the dimension\n * order and dimension sizes.\n */\nfunction getOmeIFDIndexer(imgMeta: OMEXML[0]): (sel: OmeTiffSelection) => number {\n const {SizeC, SizeZ, SizeT, DimensionOrder} = imgMeta.Pixels;\n switch (DimensionOrder) {\n case 'XYZCT': {\n return ({t, c, z}) => t * SizeZ * SizeC + c * SizeZ + z;\n }\n case 'XYZTC': {\n return ({t, c, z}) => c * SizeZ * SizeT + t * SizeZ + z;\n }\n case 'XYCTZ': {\n return ({t, c, z}) => z * SizeC * SizeT + t * SizeC + c;\n }\n case 'XYCZT': {\n return ({t, c, z}) => t * SizeC * SizeZ + z * SizeC + c;\n }\n case 'XYTCZ': {\n return ({t, c, z}) => z * SizeT * SizeC + c * SizeT + t;\n }\n case 'XYTZC': {\n return ({t, c, z}) => c * SizeT * SizeZ + z * SizeT + t;\n }\n default: {\n throw new Error(`Invalid OME-XML DimensionOrder, got ${DimensionOrder}.`);\n }\n }\n}\n"],"file":"ome-indexers.js"}
|
|
@@ -1,63 +1,73 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
int8: 'Int8',
|
|
12
|
-
int16: 'Int16',
|
|
13
|
-
int32: 'Int32'
|
|
1
|
+
import { getDims, getLabels } from './utils';
|
|
2
|
+
export const DTYPE_LOOKUP = {
|
|
3
|
+
uint8: 'Uint8',
|
|
4
|
+
uint16: 'Uint16',
|
|
5
|
+
uint32: 'Uint32',
|
|
6
|
+
float: 'Float32',
|
|
7
|
+
double: 'Float64',
|
|
8
|
+
int8: 'Int8',
|
|
9
|
+
int16: 'Int16',
|
|
10
|
+
int32: 'Int32'
|
|
14
11
|
};
|
|
15
|
-
function getOmePixelSourceMeta({
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
12
|
+
export function getOmePixelSourceMeta({
|
|
13
|
+
Pixels
|
|
14
|
+
}) {
|
|
15
|
+
const labels = getLabels(Pixels.DimensionOrder);
|
|
16
|
+
const dims = getDims(labels);
|
|
17
|
+
const shape = Array(labels.length).fill(0);
|
|
18
|
+
shape[dims('t')] = Pixels.SizeT;
|
|
19
|
+
shape[dims('c')] = Pixels.SizeC;
|
|
20
|
+
shape[dims('z')] = Pixels.SizeZ;
|
|
21
|
+
|
|
22
|
+
if (Pixels.Interleaved) {
|
|
23
|
+
labels.push('_c');
|
|
24
|
+
shape.push(3);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const getShape = level => {
|
|
28
|
+
const s = [...shape];
|
|
29
|
+
s[dims('x')] = Pixels.SizeX >> level;
|
|
30
|
+
s[dims('y')] = Pixels.SizeY >> level;
|
|
31
|
+
return s;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
if (!(Pixels.Type in DTYPE_LOOKUP)) {
|
|
35
|
+
throw Error("Pixel type ".concat(Pixels.Type, " not supported."));
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const dtype = DTYPE_LOOKUP[Pixels.Type];
|
|
39
|
+
|
|
40
|
+
if (Pixels.PhysicalSizeX && Pixels.PhysicalSizeY) {
|
|
41
|
+
const physicalSizes = {
|
|
42
|
+
x: {
|
|
43
|
+
size: Pixels.PhysicalSizeX,
|
|
44
|
+
unit: Pixels.PhysicalSizeXUnit
|
|
45
|
+
},
|
|
46
|
+
y: {
|
|
47
|
+
size: Pixels.PhysicalSizeY,
|
|
48
|
+
unit: Pixels.PhysicalSizeYUnit
|
|
49
|
+
}
|
|
37
50
|
};
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
x: {
|
|
45
|
-
size: Pixels.PhysicalSizeX,
|
|
46
|
-
unit: Pixels.PhysicalSizeXUnit
|
|
47
|
-
},
|
|
48
|
-
y: {
|
|
49
|
-
size: Pixels.PhysicalSizeY,
|
|
50
|
-
unit: Pixels.PhysicalSizeYUnit
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
if (Pixels.PhysicalSizeZ) {
|
|
54
|
-
physicalSizes.z = {
|
|
55
|
-
size: Pixels.PhysicalSizeZ,
|
|
56
|
-
unit: Pixels.PhysicalSizeZUnit
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
return { labels, getShape, physicalSizes, dtype };
|
|
51
|
+
|
|
52
|
+
if (Pixels.PhysicalSizeZ) {
|
|
53
|
+
physicalSizes.z = {
|
|
54
|
+
size: Pixels.PhysicalSizeZ,
|
|
55
|
+
unit: Pixels.PhysicalSizeZUnit
|
|
56
|
+
};
|
|
60
57
|
}
|
|
61
|
-
|
|
58
|
+
|
|
59
|
+
return {
|
|
60
|
+
labels,
|
|
61
|
+
getShape,
|
|
62
|
+
physicalSizes,
|
|
63
|
+
dtype
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return {
|
|
68
|
+
labels,
|
|
69
|
+
getShape,
|
|
70
|
+
dtype
|
|
71
|
+
};
|
|
62
72
|
}
|
|
63
|
-
|
|
73
|
+
//# sourceMappingURL=ome-utils.js.map
|