Skip to content

Commit

Permalink
feat(compare-images): add typescript binding output
Browse files Browse the repository at this point in the history
  • Loading branch information
thewtex committed Aug 21, 2023
1 parent 01d4e3e commit adbc0c6
Show file tree
Hide file tree
Showing 30 changed files with 1,047 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ packages/compress-stringify/typescript/demo-app
packages/dicom/wasi-build/
packages/dicom/typescript/package-lock.json
packages/dicom/python/itkwasm-dicom-emscripten/test/test_itkwasm_dicom.py
packages/compare-images/emscripten-build/
packages/compare-images/wasi-build/

node_modules
.DS_Store
Expand Down
Empty file.
5 changes: 5 additions & 0 deletions packages/compare-images/typescript/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules
.DS_Store
test
cypress
demo-app
145 changes: 145 additions & 0 deletions packages/compare-images/typescript/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
# @itk-wasm/compare-images

[![npm version](https://badge.fury.io/js/@itk-wasm%2Fcompare-images.svg)](https://www.npmjs.com/package/@itk-wasm/compare-images)

> Read files and images related to compare-images file format.
## Installation

```sh
npm install @itk-wasm/compare-images
```

## Usage

### Browser interface

Import:

```js
import {
compareDoubleImages,
setPipelinesBaseUrl,
getPipelinesBaseUrl,
setPipelineWorkerUrl,
getPipelineWorkerUrl,
} from "@itk-wasm/compare-images"
```

#### compareDoubleImages

*Compare double pixel type images with a tolerance for regression testing.*

```ts
async function compareDoubleImages(
webWorker: null | Worker,
testImage: Image,
options: CompareDoubleImagesOptions = { baselineImages: [] as Image[], }
) : Promise<CompareDoubleImagesResult>
```

| Parameter | Type | Description |
| :---------: | :-----: | :------------------- |
| `testImage` | *Image* | The input test image |

**`CompareDoubleImagesOptions` interface:**

| Property | Type | Description |
| :-----------------------: | :-------: | :--------------------------------------------------------------------------------------------------------------- |
| `baselineImages` | *Image[]* | Baseline images compare against |
| `differenceThreshold` | *number* | Intensity difference for pixels to be considered different. |
| `radiusTolerance` | *number* | Radius of the neighborhood around a pixel to search for similar intensity values. |
| `numberOfPixelsTolerance` | *number* | Number of pixels that can be different before the test fails. |
| `ignoreBoundaryPixels` | *boolean* | Ignore boundary pixels. Useful when resampling may have introduced difference pixel values along the image edge. |

**`CompareDoubleImagesResult` interface:**

| Property | Type | Description |
| :----------------------: | :------: | :-------------------------------------------------------------------------------- |
| **webWorker** | *Worker* | WebWorker used for computation |
| `metrics` | *Object* | Metrics for the baseline with the fewest number of pixels outside the tolerances. |
| `differenceImage` | *Image* | Absolute difference image |
| `differenceUchar2dImage` | *Image* | Unsigned char, 2D difference image for rendering |

#### setPipelinesBaseUrl

*Set base URL for WebAssembly assets when vendored.*

```ts
function setPipelinesBaseUrl(
baseUrl: string | URL
) : void
```

#### getPipelinesBaseUrl

*Get base URL for WebAssembly assets when vendored.*

```ts
function getPipelinesBaseUrl() : string | URL
```

#### setPipelineWorkerUrl

*Set base URL for the itk-wasm pipeline worker script when vendored.*

```ts
function setPipelineWorkerUrl(
baseUrl: string | URL
) : void
```

#### getPipelineWorkerUrl

*Get base URL for the itk-wasm pipeline worker script when vendored.*

```ts
function getPipelineWorkerUrl() : string | URL
```

### Node interface

Import:

```js
import {
compareDoubleImagesNode,
setPipelinesBaseUrl,
getPipelinesBaseUrl,
setPipelineWorkerUrl,
getPipelineWorkerUrl,
} from "@itk-wasm/compare-images"
```

#### compareDoubleImagesNode

*Compare double pixel type images with a tolerance for regression testing.*

```ts
async function compareDoubleImagesNode(
testImage: Image,
options: CompareDoubleImagesOptions = { baselineImages: [] as Image[], }
) : Promise<CompareDoubleImagesNodeResult>
```

| Parameter | Type | Description |
| :---------: | :-----: | :------------------- |
| `testImage` | *Image* | The input test image |

**`CompareDoubleImagesNodeOptions` interface:**

| Property | Type | Description |
| :-----------------------: | :-------: | :--------------------------------------------------------------------------------------------------------------- |
| `baselineImages` | *Image[]* | Baseline images compare against |
| `differenceThreshold` | *number* | Intensity difference for pixels to be considered different. |
| `radiusTolerance` | *number* | Radius of the neighborhood around a pixel to search for similar intensity values. |
| `numberOfPixelsTolerance` | *number* | Number of pixels that can be different before the test fails. |
| `ignoreBoundaryPixels` | *boolean* | Ignore boundary pixels. Useful when resampling may have introduced difference pixel values along the image edge. |

**`CompareDoubleImagesNodeResult` interface:**

| Property | Type | Description |
| :----------------------: | :------: | :-------------------------------------------------------------------------------- |
| `metrics` | *Object* | Metrics for the baseline with the fewest number of pixels outside the tolerances. |
| `differenceImage` | *Image* | Absolute difference image |
| `differenceUchar2dImage` | *Image* | Unsigned char, 2D difference image for rendering |
51 changes: 51 additions & 0 deletions packages/compare-images/typescript/build/rollup.browser.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { nodeResolve } from '@rollup/plugin-node-resolve'
import copy from 'rollup-plugin-copy'
import typescript from '@rollup/plugin-typescript'
import commonjs from '@rollup/plugin-commonjs'
import nodePolyfills from 'rollup-plugin-polyfill-node'
import ignore from 'rollup-plugin-ignore'
import terser from '@rollup/plugin-terser'
import packageJson from '../package.json' assert { type: 'json' }
import json from '@rollup/plugin-json'
import path from 'path'

const itkConfig = './src/itkConfig.js'
const bundleName = path.basename(packageJson.name)

export default {
input: './src/index.ts',
output: [
{
file: `./dist/bundles/${bundleName}.js`,
format: 'es',
sourcemap: true,
// plugins: [terser(),],
},
],
plugins: [
copy({
targets: [
{ src: 'node_modules/itk-wasm/dist/web-workers/bundles/pipeline.worker.js', dest: 'dist/web-workers/' },
],
hook: 'writeBundle'
}),
ignore(['crypto']),
nodeResolve({
preferBuiltins: false,
browser: true,
}),
commonjs({
transformMixedEsModules: true
}),
nodePolyfills(),
typescript(),
json(),
],
resolve: {
// where itk-wasm code has 'import ../itkConfig.js` point to the path of itkConfig
alias: {
'../itkConfig.js': itkConfig,
'../../itkConfig.js': itkConfig
}
}
}
32 changes: 32 additions & 0 deletions packages/compare-images/typescript/build/rollup.node.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { nodeResolve } from '@rollup/plugin-node-resolve'
import typescript from '@rollup/plugin-typescript'
import commonjs from '@rollup/plugin-commonjs'
import json from '@rollup/plugin-json'
import terser from '@rollup/plugin-terser'
import packageJson from '../package.json' assert { type: 'json' }
import path from 'path'

const bundleName = path.basename(packageJson.name)

export default {
input: './src/index-node.ts',
output: [
{
file: `./dist/bundles/${bundleName}-node.js`,
format: 'es',
sourcemap: true,
// plugins: [terser(),],
},
],
plugins: [
commonjs({
transformMixedEsModules: true
}),
nodeResolve({
preferBuiltins: true,
browser: false,
}),
typescript(),
json(),
],
}
20 changes: 20 additions & 0 deletions packages/compare-images/typescript/build/vite.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { defineConfig } from 'vite'
import { viteStaticCopy } from 'vite-plugin-static-copy'
import path from 'path'

export default defineConfig({
root: path.join('test', 'browser', 'demo-app'),
build: {
outDir: '../../../demo-app',
emptyOutDir: true,
},
plugins: [
// put lazy loaded JavaScript and Wasm bundles in dist directory
viteStaticCopy({
targets: [
{ src: '../../../dist/pipelines/*', dest: 'pipelines' },
{ src: '../../../dist/web-workers/*', dest: 'web-workers' },
],
})
],
})

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Binary file not shown.
43 changes: 43 additions & 0 deletions packages/compare-images/typescript/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>@itk-wasm/compare-images</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="description" content="Read files and images related to compare-images file format.">
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0">
<link rel="stylesheet" media="(prefers-color-scheme: dark)" href="https://cdn.jsdelivr.net/npm/docsify-themeable@0/dist/css/theme-simple-dark.css">
<link rel="stylesheet" media="(prefers-color-scheme: light)" href="https://cdn.jsdelivr.net/npm/docsify-themeable@0/dist/css/theme-simple.css">
<style>
:root {
--base-font-size: 16px;
--theme-color : lightblue;
--code-theme-text : #afcf7f;
--code-font-weight : 750;
--code-inline-background: hsl(var(--mono-hue), var(--mono-saturation), 35%);
--mono-hue : 213;
--mono-saturation : 0%;
}
</style>
</head>
<body>
<div id="app">Loading...</div>
<script>
window.$docsify = {
logo: 'test/browser/logo.svg',
name: '@itk-wasm/compare-images',
repo: ''
}
</script>
<!-- Docsify v4 -->
<script src="https://cdn.jsdelivr.net/npm/docsify@4"></script>
<script src="https://cdn.jsdelivr.net/npm/docsify-copy-code/dist/docsify-copy-code.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/prismjs@1/components/prism-typescript.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/prismjs@1/components/prism-c.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/prismjs@1/components/prism-cpp.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/prismjs@1/components/prism-python.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/docsify-themeable@0/dist/js/docsify-themeable.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/docsify@4/lib/plugins/search.js"></script>
<script src="https://cdn.jsdelivr.net/npm/docsify@4/lib/plugins/zoom-image.min.js"></script>
</body>
</html>
60 changes: 60 additions & 0 deletions packages/compare-images/typescript/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{
"name": "@itk-wasm/compare-images",
"version": "1.0.0",
"description": "Read files and images related to compare-images file format.",
"type": "module",
"module": "./dist/bundles/compare-images.js",
"types": "./dist/src/index.d.ts",
"exports": {
".": {
"browser": "./dist/bundles/compare-images.js",
"node": "./dist/bundles/compare-images.node.js",
"default": "./dist/bundles/compare-images.js"
}
},
"scripts": {
"start": "npm run copyShoelaceAssets && vite -c build/vite.config.js",
"test": "echo \"Error: no test specified\" && exit 1",
"build": "npm run build:tsc && npm run build:node && npm run build:browser && npm run build:demo",
"build:node": "rollup -c ./build/rollup.node.config.js",
"build:browser": "rollup -c ./build/rollup.browser.config.js",
"build:tsc": "tsc --pretty",
"copyShoelaceAssets": "shx mkdir -p test/browser/demo-app/public && shx cp -r node_modules/@shoelace-style/shoelace/dist/assets test/browser/demo-app/public/",
"build:demo": "npm run copyShoelaceAssets && vite -c build/vite.config.js build"
},
"keywords": [
"itk",
"wasm",
"webassembly",
"wasi"
],
"author": "",
"license": "Apache-2.0",
"dependencies": {
"itk-wasm": "^1.0.0-b.119"
},
"devDependencies": {
"@rollup/plugin-commonjs": "^24.0.0",
"@rollup/plugin-json": "^6.0.0",
"@rollup/plugin-node-resolve": "^15.1.0",
"@rollup/plugin-terser": "^0.4.0",
"@rollup/plugin-typescript": "^11.1.1",
"@shoelace-style/shoelace": "^2.5.2",
"@types/node": "^20.2.5",
"debug": "^4.3.4",
"rollup": "^3.9.0",
"rollup-plugin-copy": "^3.4.0",
"rollup-plugin-ignore": "^1.0.10",
"rollup-plugin-polyfill-node": "^0.12.0",
"shx": "^0.3.4",
"supports-color": "^9.3.1",
"tslib": "^2.5.2",
"typescript": "^5.0.4",
"vite": "^4.3.3",
"vite-plugin-static-copy": "^0.14.0"
},
"repository": {
"type": "git",
"url": "https://github.com/InsightSoftwareConsortium/itk-wasm"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Generated file. To retain edits, remove this comment.

import { Image } from 'itk-wasm'

interface CompareDoubleImagesNodeResult {
/** Metrics for the baseline with the fewest number of pixels outside the tolerances. */
metrics: Object

/** Absolute difference image */
differenceImage: Image

/** Unsigned char, 2D difference image for rendering */
differenceUchar2dImage: Image

}

export default CompareDoubleImagesNodeResult
Loading

0 comments on commit adbc0c6

Please sign in to comment.