@fideus-labs/ngff-zarr 0.2.4 → 0.2.6
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/README.md +268 -76
- package/esm/browser-mod.js +1 -0
- package/esm/browser-mod.js.map +1 -0
- package/esm/io/from_ngff_zarr.d.ts.map +1 -1
- package/esm/io/from_ngff_zarr.js +23 -7
- package/esm/io/from_ngff_zarr.js.map +1 -0
- package/esm/io/hcs.js +1 -0
- package/esm/io/hcs.js.map +1 -0
- package/esm/io/itk_image_to_ngff_image.js +1 -0
- package/esm/io/itk_image_to_ngff_image.js.map +1 -0
- package/esm/io/ngff_image_to_itk_image.js +1 -0
- package/esm/io/ngff_image_to_itk_image.js.map +1 -0
- package/esm/io/to_ngff_image.js +1 -0
- package/esm/io/to_ngff_image.js.map +1 -0
- package/esm/io/to_ngff_zarr.d.ts.map +1 -1
- package/esm/io/to_ngff_zarr.js +35 -26
- package/esm/io/to_ngff_zarr.js.map +1 -0
- package/esm/methods/itkwasm-browser.js +1 -0
- package/esm/methods/itkwasm-browser.js.map +1 -0
- package/esm/methods/itkwasm-node.js +1 -0
- package/esm/methods/itkwasm-node.js.map +1 -0
- package/esm/methods/itkwasm-shared.js +1 -0
- package/esm/methods/itkwasm-shared.js.map +1 -0
- package/esm/methods/itkwasm.d.ts +14 -0
- package/esm/methods/itkwasm.d.ts.map +1 -0
- package/esm/methods/itkwasm.js +18 -0
- package/esm/methods/itkwasm.js.map +1 -0
- package/esm/mod.js +1 -0
- package/esm/mod.js.map +1 -0
- package/esm/process/to_multiscales-browser.js +1 -0
- package/esm/process/to_multiscales-browser.js.map +1 -0
- package/esm/process/to_multiscales-node.js +1 -0
- package/esm/process/to_multiscales-node.js.map +1 -0
- package/esm/process/to_multiscales-shared.js +1 -0
- package/esm/process/to_multiscales-shared.js.map +1 -0
- package/esm/schemas/coordinate_systems.js +1 -0
- package/esm/schemas/coordinate_systems.js.map +1 -0
- package/esm/schemas/index.js +1 -0
- package/esm/schemas/index.js.map +1 -0
- package/esm/schemas/methods.js +1 -0
- package/esm/schemas/methods.js.map +1 -0
- package/esm/schemas/multiscales.js +1 -0
- package/esm/schemas/multiscales.js.map +1 -0
- package/esm/schemas/ngff_image.js +1 -0
- package/esm/schemas/ngff_image.js.map +1 -0
- package/esm/schemas/ome_zarr.js +1 -0
- package/esm/schemas/ome_zarr.js.map +1 -0
- package/esm/schemas/rfc4.js +1 -0
- package/esm/schemas/rfc4.js.map +1 -0
- package/esm/schemas/units.js +1 -0
- package/esm/schemas/units.js.map +1 -0
- package/esm/schemas/zarr_metadata.js +1 -0
- package/esm/schemas/zarr_metadata.js.map +1 -0
- package/esm/types/array_interface.js +1 -0
- package/esm/types/array_interface.js.map +1 -0
- package/esm/types/hcs.js +1 -0
- package/esm/types/hcs.js.map +1 -0
- package/esm/types/methods.js +1 -0
- package/esm/types/methods.js.map +1 -0
- package/esm/types/multiscales.js +1 -0
- package/esm/types/multiscales.js.map +1 -0
- package/esm/types/ngff_image.js +1 -0
- package/esm/types/ngff_image.js.map +1 -0
- package/esm/types/rfc4.js +1 -0
- package/esm/types/rfc4.js.map +1 -0
- package/esm/types/units.js +1 -0
- package/esm/types/units.js.map +1 -0
- package/esm/types/zarr_metadata.js +1 -0
- package/esm/types/zarr_metadata.js.map +1 -0
- package/esm/utils/create_queue.js +1 -0
- package/esm/utils/create_queue.js.map +1 -0
- package/esm/utils/factory.js +1 -0
- package/esm/utils/factory.js.map +1 -0
- package/esm/utils/method_metadata.js +1 -0
- package/esm/utils/method_metadata.js.map +1 -0
- package/esm/utils/validation.js +1 -0
- package/esm/utils/validation.js.map +1 -0
- package/package.json +23 -34
- package/esm/_dnt.shims.d.ts +0 -2
- package/esm/_dnt.shims.d.ts.map +0 -1
- package/esm/_dnt.shims.js +0 -57
- package/esm/package.json +0 -3
- package/script/_dnt.shims.d.ts +0 -2
- package/script/_dnt.shims.d.ts.map +0 -1
- package/script/_dnt.shims.js +0 -60
- package/script/browser-mod.d.ts +0 -16
- package/script/browser-mod.d.ts.map +0 -1
- package/script/browser-mod.js +0 -51
- package/script/io/from_ngff_zarr.d.ts +0 -10
- package/script/io/from_ngff_zarr.d.ts.map +0 -1
- package/script/io/from_ngff_zarr.js +0 -234
- package/script/io/hcs.d.ts +0 -18
- package/script/io/hcs.d.ts.map +0 -1
- package/script/io/hcs.js +0 -55
- package/script/io/itk_image_to_ngff_image.d.ts +0 -30
- package/script/io/itk_image_to_ngff_image.d.ts.map +0 -1
- package/script/io/itk_image_to_ngff_image.js +0 -153
- package/script/io/ngff_image_to_itk_image.d.ts +0 -30
- package/script/io/ngff_image_to_itk_image.d.ts.map +0 -1
- package/script/io/ngff_image_to_itk_image.js +0 -244
- package/script/io/to_ngff_image.d.ts +0 -17
- package/script/io/to_ngff_image.d.ts.map +0 -1
- package/script/io/to_ngff_image.js +0 -162
- package/script/io/to_ngff_zarr.d.ts +0 -10
- package/script/io/to_ngff_zarr.d.ts.map +0 -1
- package/script/io/to_ngff_zarr.js +0 -346
- package/script/methods/itkwasm-browser.d.ts +0 -6
- package/script/methods/itkwasm-browser.d.ts.map +0 -1
- package/script/methods/itkwasm-browser.js +0 -488
- package/script/methods/itkwasm-node.d.ts +0 -6
- package/script/methods/itkwasm-node.d.ts.map +0 -1
- package/script/methods/itkwasm-node.js +0 -493
- package/script/methods/itkwasm-shared.d.ts +0 -68
- package/script/methods/itkwasm-shared.d.ts.map +0 -1
- package/script/methods/itkwasm-shared.js +0 -524
- package/script/mod.d.ts +0 -24
- package/script/mod.d.ts.map +0 -1
- package/script/mod.js +0 -50
- package/script/package.json +0 -3
- package/script/process/to_multiscales-browser.d.ts +0 -17
- package/script/process/to_multiscales-browser.d.ts.map +0 -1
- package/script/process/to_multiscales-browser.js +0 -17
- package/script/process/to_multiscales-node.d.ts +0 -18
- package/script/process/to_multiscales-node.d.ts.map +0 -1
- package/script/process/to_multiscales-node.js +0 -21
- package/script/process/to_multiscales-shared.d.ts +0 -28
- package/script/process/to_multiscales-shared.d.ts.map +0 -1
- package/script/process/to_multiscales-shared.js +0 -66
- package/script/schemas/coordinate_systems.d.ts +0 -251
- package/script/schemas/coordinate_systems.d.ts.map +0 -1
- package/script/schemas/coordinate_systems.js +0 -142
- package/script/schemas/index.d.ts +0 -9
- package/script/schemas/index.d.ts.map +0 -1
- package/script/schemas/index.js +0 -101
- package/script/schemas/methods.d.ts +0 -3
- package/script/schemas/methods.d.ts.map +0 -1
- package/script/schemas/methods.js +0 -11
- package/script/schemas/multiscales.d.ts +0 -4
- package/script/schemas/multiscales.d.ts.map +0 -1
- package/script/schemas/multiscales.js +0 -24
- package/script/schemas/ngff_image.d.ts +0 -20
- package/script/schemas/ngff_image.d.ts.map +0 -1
- package/script/schemas/ngff_image.js +0 -24
- package/script/schemas/ome_zarr.d.ts +0 -617
- package/script/schemas/ome_zarr.d.ts.map +0 -1
- package/script/schemas/ome_zarr.js +0 -211
- package/script/schemas/rfc4.d.ts +0 -334
- package/script/schemas/rfc4.d.ts.map +0 -1
- package/script/schemas/rfc4.js +0 -132
- package/script/schemas/units.d.ts +0 -78
- package/script/schemas/units.d.ts.map +0 -1
- package/script/schemas/units.js +0 -70
- package/script/schemas/zarr_metadata.d.ts +0 -55
- package/script/schemas/zarr_metadata.d.ts.map +0 -1
- package/script/schemas/zarr_metadata.js +0 -71
- package/script/types/array_interface.d.ts +0 -7
- package/script/types/array_interface.d.ts.map +0 -1
- package/script/types/array_interface.js +0 -2
- package/script/types/hcs.d.ts +0 -70
- package/script/types/hcs.d.ts.map +0 -1
- package/script/types/hcs.js +0 -233
- package/script/types/methods.d.ts +0 -7
- package/script/types/methods.d.ts.map +0 -1
- package/script/types/methods.js +0 -12
- package/script/types/multiscales.d.ts +0 -21
- package/script/types/multiscales.d.ts.map +0 -1
- package/script/types/multiscales.js +0 -38
- package/script/types/ngff_image.d.ts +0 -27
- package/script/types/ngff_image.d.ts.map +0 -1
- package/script/types/ngff_image.js +0 -48
- package/script/types/rfc4.d.ts +0 -94
- package/script/types/rfc4.d.ts.map +0 -1
- package/script/types/rfc4.js +0 -143
- package/script/types/units.d.ts +0 -12
- package/script/types/units.d.ts.map +0 -1
- package/script/types/units.js +0 -66
- package/script/types/zarr_metadata.d.ts +0 -58
- package/script/types/zarr_metadata.d.ts.map +0 -1
- package/script/types/zarr_metadata.js +0 -20
- package/script/utils/create_queue.d.ts +0 -6
- package/script/utils/create_queue.d.ts.map +0 -1
- package/script/utils/create_queue.js +0 -17
- package/script/utils/factory.d.ts +0 -13
- package/script/utils/factory.d.ts.map +0 -1
- package/script/utils/factory.js +0 -108
- package/script/utils/method_metadata.d.ts +0 -10
- package/script/utils/method_metadata.d.ts.map +0 -1
- package/script/utils/method_metadata.js +0 -40
- package/script/utils/validation.d.ts +0 -6
- package/script/utils/validation.d.ts.map +0 -1
- package/script/utils/validation.js +0 -78
- /package/{LICENSE → LICENSE.txt} +0 -0
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Convert ITK-Wasm Image to NgffImage
|
|
3
|
-
*/
|
|
4
|
-
import type { Image } from "itk-wasm";
|
|
5
|
-
import { NgffImage } from "../types/ngff_image.js";
|
|
6
|
-
export interface ItkImageToNgffImageOptions {
|
|
7
|
-
/**
|
|
8
|
-
* Whether to add anatomical orientation metadata based on ITK LPS coordinate system
|
|
9
|
-
* @default true
|
|
10
|
-
*/
|
|
11
|
-
addAnatomicalOrientation?: boolean;
|
|
12
|
-
/**
|
|
13
|
-
* Path prefix for the zarr array (e.g., "scale0/", "scale1/")
|
|
14
|
-
* @default "image"
|
|
15
|
-
*/
|
|
16
|
-
path?: string;
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Convert an ITK-Wasm Image to an NgffImage, preserving spatial metadata.
|
|
20
|
-
*
|
|
21
|
-
* This function converts ITK-Wasm Image objects to NgffImage format while
|
|
22
|
-
* preserving spatial information like spacing, origin, and optionally
|
|
23
|
-
* anatomical orientation based on the ITK LPS coordinate system.
|
|
24
|
-
*
|
|
25
|
-
* @param itkImage - The ITK-Wasm Image to convert
|
|
26
|
-
* @param options - Conversion options
|
|
27
|
-
* @returns Promise resolving to NgffImage
|
|
28
|
-
*/
|
|
29
|
-
export declare function itkImageToNgffImage(itkImage: Image, options?: ItkImageToNgffImageOptions): Promise<NgffImage>;
|
|
30
|
-
//# sourceMappingURL=itk_image_to_ngff_image.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"itk_image_to_ngff_image.d.ts","sourceRoot":"","sources":["../../src/io/itk_image_to_ngff_image.ts"],"names":[],"mappings":"AAEA;;GAEG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAEtC,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAOnD,MAAM,WAAW,0BAA0B;IACzC;;;OAGG;IACH,wBAAwB,CAAC,EAAE,OAAO,CAAC;IAEnC;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,mBAAmB,CACvC,QAAQ,EAAE,KAAK,EACf,OAAO,GAAE,0BAA+B,GACvC,OAAO,CAAC,SAAS,CAAC,CAmHpB"}
|
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// SPDX-FileCopyrightText: Copyright (c) Fideus Labs LLC
|
|
3
|
-
// SPDX-License-Identifier: MIT
|
|
4
|
-
/**
|
|
5
|
-
* Convert ITK-Wasm Image to NgffImage
|
|
6
|
-
*/
|
|
7
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
8
|
-
if (k2 === undefined) k2 = k;
|
|
9
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
10
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
11
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
12
|
-
}
|
|
13
|
-
Object.defineProperty(o, k2, desc);
|
|
14
|
-
}) : (function(o, m, k, k2) {
|
|
15
|
-
if (k2 === undefined) k2 = k;
|
|
16
|
-
o[k2] = m[k];
|
|
17
|
-
}));
|
|
18
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
19
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
20
|
-
}) : function(o, v) {
|
|
21
|
-
o["default"] = v;
|
|
22
|
-
});
|
|
23
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
24
|
-
if (mod && mod.__esModule) return mod;
|
|
25
|
-
var result = {};
|
|
26
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
27
|
-
__setModuleDefault(result, mod);
|
|
28
|
-
return result;
|
|
29
|
-
};
|
|
30
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
31
|
-
exports.itkImageToNgffImage = itkImageToNgffImage;
|
|
32
|
-
const zarr = __importStar(require("zarrita"));
|
|
33
|
-
const ngff_image_js_1 = require("../types/ngff_image.js");
|
|
34
|
-
const rfc4_js_1 = require("../types/rfc4.js");
|
|
35
|
-
// Import the get_strides function from zarrita utilities
|
|
36
|
-
const zarrita_1 = require("zarrita");
|
|
37
|
-
/**
|
|
38
|
-
* Convert an ITK-Wasm Image to an NgffImage, preserving spatial metadata.
|
|
39
|
-
*
|
|
40
|
-
* This function converts ITK-Wasm Image objects to NgffImage format while
|
|
41
|
-
* preserving spatial information like spacing, origin, and optionally
|
|
42
|
-
* anatomical orientation based on the ITK LPS coordinate system.
|
|
43
|
-
*
|
|
44
|
-
* @param itkImage - The ITK-Wasm Image to convert
|
|
45
|
-
* @param options - Conversion options
|
|
46
|
-
* @returns Promise resolving to NgffImage
|
|
47
|
-
*/
|
|
48
|
-
async function itkImageToNgffImage(itkImage, options = {}) {
|
|
49
|
-
const { addAnatomicalOrientation = true, path = "image" } = options;
|
|
50
|
-
// Extract image properties from ITK-Wasm Image
|
|
51
|
-
const _data = itkImage.data;
|
|
52
|
-
// ITK stores size in physical space order [x, y, z], but the data buffer is in
|
|
53
|
-
// C-order (row-major) which means [z, y, x] indexing. Reverse to match data layout.
|
|
54
|
-
const shape = [...itkImage.size].reverse();
|
|
55
|
-
const spacing = itkImage.spacing;
|
|
56
|
-
const origin = itkImage.origin;
|
|
57
|
-
const ndim = shape.length;
|
|
58
|
-
// Determine dimension names based on shape and image type
|
|
59
|
-
// This logic matches the Python implementation
|
|
60
|
-
let dims;
|
|
61
|
-
// Check if this is a vector image (multi-component)
|
|
62
|
-
const imageType = itkImage.imageType;
|
|
63
|
-
const isVector = imageType.components > 1;
|
|
64
|
-
if (ndim === 3 && isVector) {
|
|
65
|
-
// 2D RGB/vector image: 2D spatial + components
|
|
66
|
-
dims = ["y", "x", "c"];
|
|
67
|
-
}
|
|
68
|
-
else if (ndim < 4) {
|
|
69
|
-
// Scalar images up to 3D: take the last ndim spatial dimensions
|
|
70
|
-
dims = ["z", "y", "x"].slice(-ndim);
|
|
71
|
-
}
|
|
72
|
-
else if (ndim < 5) {
|
|
73
|
-
// 3D RGB/vector or 4D scalar
|
|
74
|
-
if (isVector) {
|
|
75
|
-
dims = ["z", "y", "x", "c"];
|
|
76
|
-
}
|
|
77
|
-
else {
|
|
78
|
-
dims = ["t", "z", "y", "x"];
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
else if (ndim < 6) {
|
|
82
|
-
// 4D RGB/vector
|
|
83
|
-
dims = ["t", "z", "y", "x", "c"];
|
|
84
|
-
}
|
|
85
|
-
else {
|
|
86
|
-
throw new Error(`Unsupported number of dimensions: ${ndim}`);
|
|
87
|
-
}
|
|
88
|
-
// Identify spatial dimensions
|
|
89
|
-
const allSpatialDims = new Set(["x", "y", "z"]);
|
|
90
|
-
const spatialDims = dims.filter((dim) => allSpatialDims.has(dim));
|
|
91
|
-
// Create scale mapping from spacing
|
|
92
|
-
// ITK stores spacing/origin in physical space order (x, y, z),
|
|
93
|
-
// but we need to map them to array order (z, y, x).
|
|
94
|
-
// Reverse the arrays to convert from physical to array order, matching Python implementation.
|
|
95
|
-
const scale = {};
|
|
96
|
-
const reversedSpacing = spacing.slice().reverse();
|
|
97
|
-
spatialDims.forEach((dim, idx) => {
|
|
98
|
-
scale[dim] = reversedSpacing[idx];
|
|
99
|
-
});
|
|
100
|
-
// Create translation mapping from origin
|
|
101
|
-
const translation = {};
|
|
102
|
-
const reversedOrigin = origin.slice().reverse();
|
|
103
|
-
spatialDims.forEach((dim, idx) => {
|
|
104
|
-
translation[dim] = reversedOrigin[idx];
|
|
105
|
-
});
|
|
106
|
-
// Create Zarr array from ITK-Wasm data
|
|
107
|
-
const store = new Map();
|
|
108
|
-
const root = zarr.root(store);
|
|
109
|
-
// Determine appropriate chunk size
|
|
110
|
-
const chunkShape = shape.map((s) => Math.min(s, 256));
|
|
111
|
-
const zarrArray = await zarr.create(root.resolve(path), {
|
|
112
|
-
shape: shape,
|
|
113
|
-
chunk_shape: chunkShape,
|
|
114
|
-
data_type: imageType.componentType,
|
|
115
|
-
fill_value: 0,
|
|
116
|
-
});
|
|
117
|
-
// Write the ITK-Wasm data to the zarr array
|
|
118
|
-
// We use zarrita's set function to write the entire data efficiently
|
|
119
|
-
// Create a selection that covers the entire array (null means "all" for each dimension)
|
|
120
|
-
const selection = new Array(ndim).fill(null);
|
|
121
|
-
// Create a chunk object with the ITK-Wasm data in zarrita format
|
|
122
|
-
// ITK-Wasm stores data in column-major order with size [x, y, z],
|
|
123
|
-
// which has the same memory layout as C-order (row-major) with shape [z, y, x].
|
|
124
|
-
// We reversed the shape above, and now use C-order strides for that reversed shape.
|
|
125
|
-
const dataChunk = {
|
|
126
|
-
data: itkImage.data,
|
|
127
|
-
shape: shape,
|
|
128
|
-
stride: (0, zarrita_1._zarrita_internal_get_strides)(shape, "C"), // C-order strides for the reversed shape
|
|
129
|
-
};
|
|
130
|
-
// Write all data to the zarr array using zarrita's set function
|
|
131
|
-
// This handles chunking and encoding automatically
|
|
132
|
-
await zarr.set(zarrArray, selection, dataChunk); // Add anatomical orientation if requested
|
|
133
|
-
let axesOrientations;
|
|
134
|
-
if (addAnatomicalOrientation) {
|
|
135
|
-
axesOrientations = {};
|
|
136
|
-
for (const dim of spatialDims) {
|
|
137
|
-
const orientation = (0, rfc4_js_1.itkLpsToAnatomicalOrientation)(dim);
|
|
138
|
-
if (orientation !== undefined) {
|
|
139
|
-
axesOrientations[dim] = orientation;
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
return new ngff_image_js_1.NgffImage({
|
|
144
|
-
data: zarrArray,
|
|
145
|
-
dims,
|
|
146
|
-
scale,
|
|
147
|
-
translation,
|
|
148
|
-
name: "image",
|
|
149
|
-
axesUnits: undefined,
|
|
150
|
-
axesOrientations,
|
|
151
|
-
computedCallbacks: undefined,
|
|
152
|
-
});
|
|
153
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Convert NgffImage to ITK-Wasm Image
|
|
3
|
-
*/
|
|
4
|
-
import type { Image } from "itk-wasm";
|
|
5
|
-
import { NgffImage } from "../types/ngff_image.js";
|
|
6
|
-
export interface NgffImageToItkImageOptions {
|
|
7
|
-
/**
|
|
8
|
-
* Extract a specific time index from a time-series image
|
|
9
|
-
* If specified and 't' dimension exists, extracts the slice at this time index
|
|
10
|
-
*/
|
|
11
|
-
tIndex?: number;
|
|
12
|
-
/**
|
|
13
|
-
* Extract a specific channel index from a multi-channel image
|
|
14
|
-
* If specified and 'c' dimension exists, extracts the slice at this channel index
|
|
15
|
-
*/
|
|
16
|
-
cIndex?: number;
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Convert an NgffImage to an ITK-Wasm Image, preserving spatial metadata.
|
|
20
|
-
*
|
|
21
|
-
* This function converts NgffImage objects to ITK-Wasm Image format while
|
|
22
|
-
* preserving spatial information like spacing, origin, and direction matrix.
|
|
23
|
-
* Optionally extracts specific time or channel slices.
|
|
24
|
-
*
|
|
25
|
-
* @param ngffImage - The NgffImage to convert
|
|
26
|
-
* @param options - Conversion options
|
|
27
|
-
* @returns Promise resolving to ITK-Wasm Image
|
|
28
|
-
*/
|
|
29
|
-
export declare function ngffImageToItkImage(ngffImage: NgffImage, options?: NgffImageToItkImageOptions): Promise<Image>;
|
|
30
|
-
//# sourceMappingURL=ngff_image_to_itk_image.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ngff_image_to_itk_image.d.ts","sourceRoot":"","sources":["../../src/io/ngff_image_to_itk_image.ts"],"names":[],"mappings":"AAEA;;GAEG;AAEH,OAAO,KAAK,EAEV,KAAK,EAKN,MAAM,UAAU,CAAC;AAElB,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAEnD,MAAM,WAAW,0BAA0B;IACzC;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAsED;;;;;;;;;;GAUG;AACH,wBAAsB,mBAAmB,CACvC,SAAS,EAAE,SAAS,EACpB,OAAO,GAAE,0BAA+B,GACvC,OAAO,CAAC,KAAK,CAAC,CAmMhB"}
|
|
@@ -1,244 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// SPDX-FileCopyrightText: Copyright (c) Fideus Labs LLC
|
|
3
|
-
// SPDX-License-Identifier: MIT
|
|
4
|
-
/**
|
|
5
|
-
* Convert NgffImage to ITK-Wasm Image
|
|
6
|
-
*/
|
|
7
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
8
|
-
if (k2 === undefined) k2 = k;
|
|
9
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
10
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
11
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
12
|
-
}
|
|
13
|
-
Object.defineProperty(o, k2, desc);
|
|
14
|
-
}) : (function(o, m, k, k2) {
|
|
15
|
-
if (k2 === undefined) k2 = k;
|
|
16
|
-
o[k2] = m[k];
|
|
17
|
-
}));
|
|
18
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
19
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
20
|
-
}) : function(o, v) {
|
|
21
|
-
o["default"] = v;
|
|
22
|
-
});
|
|
23
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
24
|
-
if (mod && mod.__esModule) return mod;
|
|
25
|
-
var result = {};
|
|
26
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
27
|
-
__setModuleDefault(result, mod);
|
|
28
|
-
return result;
|
|
29
|
-
};
|
|
30
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
31
|
-
exports.ngffImageToItkImage = ngffImageToItkImage;
|
|
32
|
-
const zarr = __importStar(require("zarrita"));
|
|
33
|
-
const ngff_image_js_1 = require("../types/ngff_image.js");
|
|
34
|
-
/**
|
|
35
|
-
* Convert the data type from zarr DataType to ITK-Wasm component type
|
|
36
|
-
*/
|
|
37
|
-
function dataTypeToComponentType(dataType) {
|
|
38
|
-
switch (dataType) {
|
|
39
|
-
case "uint8":
|
|
40
|
-
return "uint8";
|
|
41
|
-
case "int8":
|
|
42
|
-
return "int8";
|
|
43
|
-
case "uint16":
|
|
44
|
-
return "uint16";
|
|
45
|
-
case "int16":
|
|
46
|
-
return "int16";
|
|
47
|
-
case "uint32":
|
|
48
|
-
return "uint32";
|
|
49
|
-
case "int32":
|
|
50
|
-
return "int32";
|
|
51
|
-
case "uint64":
|
|
52
|
-
return "uint64";
|
|
53
|
-
case "int64":
|
|
54
|
-
return "int64";
|
|
55
|
-
case "float32":
|
|
56
|
-
return "float32";
|
|
57
|
-
case "float64":
|
|
58
|
-
return "float64";
|
|
59
|
-
default:
|
|
60
|
-
throw new Error(`Unsupported data type: ${dataType}`);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Move the channel dimension to the end (last position) if it exists
|
|
65
|
-
* This follows the ITK convention where vector/RGB components are the last dimension
|
|
66
|
-
*/
|
|
67
|
-
function moveChannelDimToLast(ngffImage) {
|
|
68
|
-
const dims = ngffImage.dims;
|
|
69
|
-
const cIndex = dims.indexOf("c");
|
|
70
|
-
if (cIndex === -1 || cIndex === dims.length - 1) {
|
|
71
|
-
// No channel dimension or already at the end
|
|
72
|
-
return ngffImage;
|
|
73
|
-
}
|
|
74
|
-
// Reorder dimensions to move 'c' to the end
|
|
75
|
-
const newDims = [...dims];
|
|
76
|
-
const cDim = newDims.splice(cIndex, 1)[0];
|
|
77
|
-
newDims.push(cDim);
|
|
78
|
-
// Note: We would need to transpose the zarr array data here
|
|
79
|
-
// For now, we'll assume the data is already in the correct order
|
|
80
|
-
// In a full implementation, you'd transpose the zarr array
|
|
81
|
-
return new ngff_image_js_1.NgffImage({
|
|
82
|
-
data: ngffImage.data, // TODO: transpose if needed
|
|
83
|
-
dims: newDims,
|
|
84
|
-
scale: ngffImage.scale,
|
|
85
|
-
translation: ngffImage.translation,
|
|
86
|
-
name: ngffImage.name,
|
|
87
|
-
axesUnits: ngffImage.axesUnits,
|
|
88
|
-
axesOrientations: ngffImage.axesOrientations,
|
|
89
|
-
computedCallbacks: ngffImage.computedCallbacks,
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* Convert an NgffImage to an ITK-Wasm Image, preserving spatial metadata.
|
|
94
|
-
*
|
|
95
|
-
* This function converts NgffImage objects to ITK-Wasm Image format while
|
|
96
|
-
* preserving spatial information like spacing, origin, and direction matrix.
|
|
97
|
-
* Optionally extracts specific time or channel slices.
|
|
98
|
-
*
|
|
99
|
-
* @param ngffImage - The NgffImage to convert
|
|
100
|
-
* @param options - Conversion options
|
|
101
|
-
* @returns Promise resolving to ITK-Wasm Image
|
|
102
|
-
*/
|
|
103
|
-
async function ngffImageToItkImage(ngffImage, options = {}) {
|
|
104
|
-
const { tIndex, cIndex } = options;
|
|
105
|
-
let workingImage = ngffImage;
|
|
106
|
-
// Extract time slice if requested
|
|
107
|
-
if (tIndex !== undefined && workingImage.dims.includes("t")) {
|
|
108
|
-
const tDimIndex = workingImage.dims.indexOf("t");
|
|
109
|
-
const newDims = workingImage.dims.filter((dim) => dim !== "t");
|
|
110
|
-
const newScale = Object.fromEntries(Object.entries(workingImage.scale).filter(([dim]) => dim !== "t"));
|
|
111
|
-
const newTranslation = Object.fromEntries(Object.entries(workingImage.translation).filter(([dim]) => dim !== "t"));
|
|
112
|
-
// Extract the time slice from zarr array
|
|
113
|
-
const selection = new Array(workingImage.data.shape.length).fill(null);
|
|
114
|
-
selection[tDimIndex] = tIndex;
|
|
115
|
-
const sliceData = await zarr.get(workingImage.data, selection);
|
|
116
|
-
// Create new zarr array with reduced dimensions
|
|
117
|
-
const store = new Map();
|
|
118
|
-
const root = zarr.root(store);
|
|
119
|
-
const newShape = workingImage.data.shape.filter((_, i) => i !== tDimIndex);
|
|
120
|
-
const chunkShape = newShape.map((s) => Math.min(s, 256));
|
|
121
|
-
const newArray = await zarr.create(root.resolve("slice"), {
|
|
122
|
-
shape: newShape,
|
|
123
|
-
chunk_shape: chunkShape,
|
|
124
|
-
data_type: workingImage.data.dtype,
|
|
125
|
-
fill_value: 0,
|
|
126
|
-
});
|
|
127
|
-
// Write the slice data
|
|
128
|
-
const fullSelection = new Array(newShape.length).fill(null);
|
|
129
|
-
await zarr.set(newArray, fullSelection, sliceData);
|
|
130
|
-
workingImage = new ngff_image_js_1.NgffImage({
|
|
131
|
-
data: newArray,
|
|
132
|
-
dims: newDims,
|
|
133
|
-
scale: newScale,
|
|
134
|
-
translation: newTranslation,
|
|
135
|
-
name: workingImage.name,
|
|
136
|
-
axesUnits: workingImage.axesUnits
|
|
137
|
-
? Object.fromEntries(Object.entries(workingImage.axesUnits).filter(([dim]) => dim !== "t"))
|
|
138
|
-
: undefined,
|
|
139
|
-
axesOrientations: workingImage.axesOrientations
|
|
140
|
-
? Object.fromEntries(Object.entries(workingImage.axesOrientations).filter(([dim]) => dim !== "t"))
|
|
141
|
-
: undefined,
|
|
142
|
-
computedCallbacks: workingImage.computedCallbacks,
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
// Extract channel slice if requested
|
|
146
|
-
if (cIndex !== undefined && workingImage.dims.includes("c")) {
|
|
147
|
-
const cDimIndex = workingImage.dims.indexOf("c");
|
|
148
|
-
const newDims = workingImage.dims.filter((dim) => dim !== "c");
|
|
149
|
-
const newScale = Object.fromEntries(Object.entries(workingImage.scale).filter(([dim]) => dim !== "c"));
|
|
150
|
-
const newTranslation = Object.fromEntries(Object.entries(workingImage.translation).filter(([dim]) => dim !== "c"));
|
|
151
|
-
// Extract the channel slice from zarr array
|
|
152
|
-
const selection = new Array(workingImage.data.shape.length).fill(null);
|
|
153
|
-
selection[cDimIndex] = cIndex;
|
|
154
|
-
const sliceData = await zarr.get(workingImage.data, selection);
|
|
155
|
-
// Create new zarr array with reduced dimensions
|
|
156
|
-
const store = new Map();
|
|
157
|
-
const root = zarr.root(store);
|
|
158
|
-
const newShape = workingImage.data.shape.filter((_, i) => i !== cDimIndex);
|
|
159
|
-
const chunkShape = newShape.map((s) => Math.min(s, 256));
|
|
160
|
-
const newArray = await zarr.create(root.resolve("slice"), {
|
|
161
|
-
shape: newShape,
|
|
162
|
-
chunk_shape: chunkShape,
|
|
163
|
-
data_type: workingImage.data.dtype,
|
|
164
|
-
fill_value: 0,
|
|
165
|
-
});
|
|
166
|
-
// Write the slice data
|
|
167
|
-
const fullSelection = new Array(newShape.length).fill(null);
|
|
168
|
-
await zarr.set(newArray, fullSelection, sliceData);
|
|
169
|
-
workingImage = new ngff_image_js_1.NgffImage({
|
|
170
|
-
data: newArray,
|
|
171
|
-
dims: newDims,
|
|
172
|
-
scale: newScale,
|
|
173
|
-
translation: newTranslation,
|
|
174
|
-
name: workingImage.name,
|
|
175
|
-
axesUnits: workingImage.axesUnits
|
|
176
|
-
? Object.fromEntries(Object.entries(workingImage.axesUnits).filter(([dim]) => dim !== "c"))
|
|
177
|
-
: undefined,
|
|
178
|
-
axesOrientations: workingImage.axesOrientations
|
|
179
|
-
? Object.fromEntries(Object.entries(workingImage.axesOrientations).filter(([dim]) => dim !== "c"))
|
|
180
|
-
: undefined,
|
|
181
|
-
computedCallbacks: workingImage.computedCallbacks,
|
|
182
|
-
});
|
|
183
|
-
}
|
|
184
|
-
// Move channel dimension to last position (ITK convention)
|
|
185
|
-
workingImage = moveChannelDimToLast(workingImage);
|
|
186
|
-
const dims = workingImage.dims;
|
|
187
|
-
const data = workingImage.data;
|
|
188
|
-
// Identify ITK spatial dimensions
|
|
189
|
-
const itkDimensionNames = new Set(["x", "y", "z", "t"]);
|
|
190
|
-
const itkDims = dims.filter((dim) => itkDimensionNames.has(dim));
|
|
191
|
-
// Sort ITK dimensions: spatial first (x, y, z), then time
|
|
192
|
-
const sortedItkDims = itkDims.sort((a, b) => {
|
|
193
|
-
const order = ["x", "y", "z", "t"];
|
|
194
|
-
return order.indexOf(a) - order.indexOf(b);
|
|
195
|
-
});
|
|
196
|
-
// Create ITK spacing, origin, and size arrays
|
|
197
|
-
// sortedItkDims is already in physical space order [x, y, z]
|
|
198
|
-
// Mapping from dims extracts the correct values from NGFF's array order [z, y, x]
|
|
199
|
-
const spacing = sortedItkDims.map((dim) => workingImage.scale[dim] || 1.0);
|
|
200
|
-
const origin = sortedItkDims.map((dim) => workingImage.translation[dim] || 0.0);
|
|
201
|
-
const size = sortedItkDims.map((dim) => data.shape[dims.indexOf(dim)]);
|
|
202
|
-
const dimension = sortedItkDims.length;
|
|
203
|
-
// Determine component type and pixel type
|
|
204
|
-
const componentType = dataTypeToComponentType(data.dtype);
|
|
205
|
-
let components = 1;
|
|
206
|
-
let pixelType = "Scalar";
|
|
207
|
-
if (dims.includes("c")) {
|
|
208
|
-
components = data.shape[dims.indexOf("c")];
|
|
209
|
-
if (components === 3 && componentType === "uint8") {
|
|
210
|
-
pixelType = "RGB";
|
|
211
|
-
}
|
|
212
|
-
else {
|
|
213
|
-
pixelType =
|
|
214
|
-
"VariableLengthVector";
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
// Create ImageType
|
|
218
|
-
const imageType = {
|
|
219
|
-
dimension,
|
|
220
|
-
componentType,
|
|
221
|
-
pixelType,
|
|
222
|
-
components,
|
|
223
|
-
};
|
|
224
|
-
// Read all data from zarr array
|
|
225
|
-
const selection = new Array(data.shape.length).fill(null);
|
|
226
|
-
const dataChunk = await zarr.get(data, selection);
|
|
227
|
-
// Create direction matrix (identity for now)
|
|
228
|
-
const direction = new Float64Array(dimension * dimension);
|
|
229
|
-
for (let i = 0; i < dimension; i++) {
|
|
230
|
-
direction[i * dimension + i] = 1.0;
|
|
231
|
-
}
|
|
232
|
-
// Create ITK-Wasm Image
|
|
233
|
-
const itkImage = {
|
|
234
|
-
imageType,
|
|
235
|
-
name: workingImage.name || "image",
|
|
236
|
-
origin,
|
|
237
|
-
spacing,
|
|
238
|
-
direction,
|
|
239
|
-
size,
|
|
240
|
-
metadata: new Map(),
|
|
241
|
-
data: dataChunk.data, // Cast to handle zarrita's data type
|
|
242
|
-
};
|
|
243
|
-
return itkImage;
|
|
244
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { NgffImage } from "../types/ngff_image.js";
|
|
2
|
-
export interface ToNgffImageOptions {
|
|
3
|
-
dims?: string[];
|
|
4
|
-
scale?: Record<string, number>;
|
|
5
|
-
translation?: Record<string, number>;
|
|
6
|
-
name?: string;
|
|
7
|
-
shape?: number[];
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* Convert array data to NgffImage
|
|
11
|
-
*
|
|
12
|
-
* @param data - Input data as typed array or regular array
|
|
13
|
-
* @param options - Configuration options for NgffImage creation
|
|
14
|
-
* @returns NgffImage instance
|
|
15
|
-
*/
|
|
16
|
-
export declare function toNgffImage(data: ArrayLike<number> | number[][] | number[][][], options?: ToNgffImageOptions): Promise<NgffImage>;
|
|
17
|
-
//# sourceMappingURL=to_ngff_image.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"to_ngff_image.d.ts","sourceRoot":"","sources":["../../src/io/to_ngff_image.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAGnD,MAAM,WAAW,kBAAkB;IACjC,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/B,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACrC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;CAClB;AAED;;;;;;GAMG;AACH,wBAAsB,WAAW,CAC/B,IAAI,EAAE,SAAS,CAAC,MAAM,CAAC,GAAG,MAAM,EAAE,EAAE,GAAG,MAAM,EAAE,EAAE,EAAE,EACnD,OAAO,GAAE,kBAAuB,GAC/B,OAAO,CAAC,SAAS,CAAC,CAqIpB"}
|
|
@@ -1,162 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.toNgffImage = toNgffImage;
|
|
27
|
-
const zarr = __importStar(require("zarrita"));
|
|
28
|
-
const ngff_image_js_1 = require("../types/ngff_image.js");
|
|
29
|
-
/**
|
|
30
|
-
* Convert array data to NgffImage
|
|
31
|
-
*
|
|
32
|
-
* @param data - Input data as typed array or regular array
|
|
33
|
-
* @param options - Configuration options for NgffImage creation
|
|
34
|
-
* @returns NgffImage instance
|
|
35
|
-
*/
|
|
36
|
-
async function toNgffImage(data, options = {}) {
|
|
37
|
-
const { dims = ["y", "x"], scale = {}, translation = {}, name = "image", shape: explicitShape, } = options;
|
|
38
|
-
// Determine data shape and create typed array
|
|
39
|
-
let typedData;
|
|
40
|
-
let shape;
|
|
41
|
-
if (Array.isArray(data)) {
|
|
42
|
-
// Handle multi-dimensional arrays
|
|
43
|
-
if (Array.isArray(data[0])) {
|
|
44
|
-
if (Array.isArray(data[0][0])) {
|
|
45
|
-
// 3D array
|
|
46
|
-
const d3 = data;
|
|
47
|
-
shape = [d3.length, d3[0].length, d3[0][0].length];
|
|
48
|
-
typedData = new Float32Array(shape[0] * shape[1] * shape[2]);
|
|
49
|
-
let idx = 0;
|
|
50
|
-
for (let i = 0; i < shape[0]; i++) {
|
|
51
|
-
for (let j = 0; j < shape[1]; j++) {
|
|
52
|
-
for (let k = 0; k < shape[2]; k++) {
|
|
53
|
-
typedData[idx++] = d3[i][j][k];
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
else {
|
|
59
|
-
// 2D array
|
|
60
|
-
const d2 = data;
|
|
61
|
-
shape = [d2.length, d2[0].length];
|
|
62
|
-
typedData = new Float32Array(shape[0] * shape[1]);
|
|
63
|
-
let idx = 0;
|
|
64
|
-
for (let i = 0; i < shape[0]; i++) {
|
|
65
|
-
for (let j = 0; j < shape[1]; j++) {
|
|
66
|
-
typedData[idx++] = d2[i][j];
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
else {
|
|
72
|
-
// 1D array
|
|
73
|
-
const d1 = data;
|
|
74
|
-
shape = [d1.length];
|
|
75
|
-
typedData = new Float32Array(d1);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
else {
|
|
79
|
-
// ArrayLike (already a typed array)
|
|
80
|
-
// Use explicit shape if provided, otherwise infer from data length and dims
|
|
81
|
-
if (explicitShape) {
|
|
82
|
-
shape = [...explicitShape];
|
|
83
|
-
}
|
|
84
|
-
else {
|
|
85
|
-
// Try to infer shape - this is a best guess
|
|
86
|
-
shape = [data.length];
|
|
87
|
-
}
|
|
88
|
-
// Preserve the original typed array type
|
|
89
|
-
if (data instanceof Uint8Array) {
|
|
90
|
-
typedData = data;
|
|
91
|
-
}
|
|
92
|
-
else if (data instanceof Uint16Array) {
|
|
93
|
-
typedData = data;
|
|
94
|
-
}
|
|
95
|
-
else {
|
|
96
|
-
typedData = new Float32Array(data);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
// Adjust shape to match dims length if not explicitly provided
|
|
100
|
-
if (!explicitShape) {
|
|
101
|
-
while (shape.length < dims.length) {
|
|
102
|
-
shape.unshift(1);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
if (shape.length !== dims.length) {
|
|
106
|
-
throw new Error(`Shape dimensionality (${shape.length}) must match dims length (${dims.length})`);
|
|
107
|
-
}
|
|
108
|
-
// Create in-memory zarr store and array
|
|
109
|
-
const store = new Map();
|
|
110
|
-
const root = zarr.root(store);
|
|
111
|
-
// Calculate appropriate chunk size
|
|
112
|
-
const chunkShape = shape.map((dim) => Math.min(dim, 256));
|
|
113
|
-
const zarrArray = await zarr.create(root.resolve("data"), {
|
|
114
|
-
shape,
|
|
115
|
-
chunk_shape: chunkShape,
|
|
116
|
-
data_type: "float32",
|
|
117
|
-
fill_value: 0,
|
|
118
|
-
});
|
|
119
|
-
// Write data to zarr array
|
|
120
|
-
await zarr.set(zarrArray, [], {
|
|
121
|
-
data: typedData,
|
|
122
|
-
shape,
|
|
123
|
-
stride: calculateStride(shape),
|
|
124
|
-
});
|
|
125
|
-
// Create scale and translation records with defaults
|
|
126
|
-
const fullScale = {};
|
|
127
|
-
const fullTranslation = {};
|
|
128
|
-
const spatialDims = new Set(["x", "y", "z"]);
|
|
129
|
-
for (const dim of dims) {
|
|
130
|
-
// Only set defaults for spatial dimensions
|
|
131
|
-
if (spatialDims.has(dim)) {
|
|
132
|
-
fullScale[dim] = scale[dim] ?? 1.0;
|
|
133
|
-
fullTranslation[dim] = translation[dim] ?? 0.0;
|
|
134
|
-
}
|
|
135
|
-
else {
|
|
136
|
-
// For non-spatial dimensions, only include if explicitly provided
|
|
137
|
-
if (scale[dim] !== undefined) {
|
|
138
|
-
fullScale[dim] = scale[dim];
|
|
139
|
-
}
|
|
140
|
-
if (translation[dim] !== undefined) {
|
|
141
|
-
fullTranslation[dim] = translation[dim];
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
return new ngff_image_js_1.NgffImage({
|
|
146
|
-
data: zarrArray,
|
|
147
|
-
dims,
|
|
148
|
-
scale: fullScale,
|
|
149
|
-
translation: fullTranslation,
|
|
150
|
-
name,
|
|
151
|
-
axesUnits: undefined,
|
|
152
|
-
computedCallbacks: undefined,
|
|
153
|
-
});
|
|
154
|
-
}
|
|
155
|
-
function calculateStride(shape) {
|
|
156
|
-
const stride = new Array(shape.length);
|
|
157
|
-
stride[shape.length - 1] = 1;
|
|
158
|
-
for (let i = shape.length - 2; i >= 0; i--) {
|
|
159
|
-
stride[i] = stride[i + 1] * shape[i + 1];
|
|
160
|
-
}
|
|
161
|
-
return stride;
|
|
162
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import * as zarr from "zarrita";
|
|
2
|
-
import type { Multiscales } from "../types/multiscales.js";
|
|
3
|
-
import type { MemoryStore } from "./from_ngff_zarr.js";
|
|
4
|
-
export interface ToNgffZarrOptions {
|
|
5
|
-
overwrite?: boolean;
|
|
6
|
-
version?: "0.4" | "0.5";
|
|
7
|
-
chunksPerShard?: number | number[] | Record<string, number>;
|
|
8
|
-
}
|
|
9
|
-
export declare function toNgffZarr(store: string | MemoryStore | zarr.FetchStore, multiscales: Multiscales, options?: ToNgffZarrOptions): Promise<void>;
|
|
10
|
-
//# sourceMappingURL=to_ngff_zarr.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"to_ngff_zarr.d.ts","sourceRoot":"","sources":["../../src/io/to_ngff_zarr.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,IAAI,MAAM,SAAS,CAAC;AAChC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAE3D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAGvD,MAAM,WAAW,iBAAiB;IAChC,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,OAAO,CAAC,EAAE,KAAK,GAAG,KAAK,CAAC;IACxB,cAAc,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC7D;AAED,wBAAsB,UAAU,CAC9B,KAAK,EAAE,MAAM,GAAG,WAAW,GAAG,IAAI,CAAC,UAAU,EAC7C,WAAW,EAAE,WAAW,EACxB,OAAO,GAAE,iBAAsB,GAC9B,OAAO,CAAC,IAAI,CAAC,CA0Ff"}
|