Skip to content

Commit

Permalink
Merge pull request #1306 from thewtex/io-metadata
Browse files Browse the repository at this point in the history
io metadata
  • Loading branch information
thewtex authored Jan 22, 2025
2 parents 0d9df74 + e0d7b11 commit 268c3bd
Show file tree
Hide file tree
Showing 35 changed files with 3,142 additions and 3,115 deletions.
44 changes: 44 additions & 0 deletions include/itkMetaDataDictionaryCBOR.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*=========================================================================
*
* Copyright NumFOCUS
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0.txt
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*=========================================================================*/
#ifndef itkMetaDataDictionaryCBOR_h
#define itkMetaDataDictionaryCBOR_h

#include "itkMetaDataDictionary.h"
#include "itkDefaultConvertPixelTraits.h"
#include "itkMetaDataObject.h"
#include "itkArray.h"
#include "itkMatrix.h"

#include <string>
#include <vector>
#include <tuple>

#include "WebAssemblyInterfaceExport.h"

#include "cbor.h"

namespace itk
{

WebAssemblyInterface_EXPORT void metaDataDictionaryToCBOR(const itk::MetaDataDictionary & dictionary, cbor_item_t * metadataCbor);

WebAssemblyInterface_EXPORT void cborToMetaDataDictionary(const cbor_item_t * metadataCbor, itk::MetaDataDictionary & dictionary);

} // end namespace itk

#endif
4 changes: 2 additions & 2 deletions include/itkWasmImageIO.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ namespace itk
*
* \brief Read and write an itk::Image in a web-friendly format.
*
* This format is intended to facilitate data exchange in itk-wasm.
* It reads and writes an itk-wasm Image object in a CBOR file on the
* This format is intended to facilitate data exchange in ITK-Wasm.
* It reads and writes an ITK-Wasm Image object in a CBOR file on the
* filesystem with JSON files and binary files for TypedArrays.
*
* The file extensions used are .iwi and .iwi.cbor.
Expand Down
3 changes: 3 additions & 0 deletions itk_wasm_env.bash
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ export ITK_WASM_DICOM_TEST_DATA_URLS=${ITK_WASM_DICOM_TEST_DATA_URLS:-$(cat pack
export ITK_WASM_DOWNSAMPLE_TEST_DATA_HASH=${ITK_WASM_DOWNSAMPLE_TEST_DATA_HASH:-$(cat packages/downsample/package.json | jq -e -r '."itk-wasm"."test-data-hash"')}
export ITK_WASM_DOWNSAMPLE_TEST_DATA_URLS=${ITK_WASM_DOWNSAMPLE_TEST_DATA_URLS:-$(cat packages/downsample/package.json | jq -e -r '."itk-wasm"."test-data-urls" | join(" ")')}

export ITK_WASM_IMAGE_IO_TEST_DATA_HASH=${ITK_WASM_IMAGE_IO_TEST_DATA_HASH:-$(cat packages/mesh-io/package.json | jq -e -r '."itk-wasm"."test-data-hash"')}
export ITK_WASM_IMAGE_IO_TEST_DATA_URLS=${ITK_WASM_IMAGE_IO_TEST_DATA_URLS:-$(cat packages/mesh-io/package.json | jq -e -r '."itk-wasm"."test-data-urls" | join(" ")')}

export ITK_WASM_MESH_IO_TEST_DATA_HASH=${ITK_WASM_MESH_IO_TEST_DATA_HASH:-$(cat packages/mesh-io/package.json | jq -e -r '."itk-wasm"."test-data-hash"')}
export ITK_WASM_MESH_IO_TEST_DATA_URLS=${ITK_WASM_MESH_IO_TEST_DATA_URLS:-$(cat packages/mesh-io/package.json | jq -e -r '."itk-wasm"."test-data-urls" | join(" ")')}

Expand Down
2 changes: 1 addition & 1 deletion packages/core/python/itkwasm/itkwasm/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""itkwasm: Python interface to itk-wasm WebAssembly modules."""

__version__ = "1.0b185"
__version__ = "1.0b186"

from .interface_types import InterfaceTypes
from .image import Image, ImageType, ImageRegion
Expand Down
11 changes: 11 additions & 0 deletions packages/core/python/itkwasm/itkwasm/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,13 +235,18 @@ def run(
data_ptr = ri.set_input_array(mv, index, 0)
dv = array_like_to_bytes(image.direction)
direction_ptr = ri.set_input_array(dv, index, 1)
metadata = []
if image.metadata:
for key, value in image.metadata.items():
metadata.append((key, value))
image_json = {
"imageType": asdict(image.imageType),
"name": image.name,
"origin": image.origin,
"spacing": image.spacing,
"direction": f"data:application/vnd.itk.address,0:{direction_ptr}",
"size": image.size,
"metadata": metadata,
"data": f"data:application/vnd.itk.address,0:{data_ptr}",
}
ri.set_input_json(image_json, index)
Expand Down Expand Up @@ -427,6 +432,12 @@ def run(
elif output.type == InterfaceTypes.Image:
image_json = ri.get_output_json(index)

if 'metadata' in image_json and isinstance(image_json['metadata'], list):
metadata = image_json['metadata']
image_json['metadata'] = {}
for key, value in metadata:
image_json['metadata'][key] = value

image = Image(**image_json)

data_ptr = ri.get_output_array_address(0, index, 0)
Expand Down
Loading

0 comments on commit 268c3bd

Please sign in to comment.