-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(compare-images): add typescript binding output
- Loading branch information
Showing
30 changed files
with
1,047 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
node_modules | ||
.DS_Store | ||
test | ||
cypress | ||
demo-app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
51
packages/compare-images/typescript/build/rollup.browser.config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
32
packages/compare-images/typescript/build/rollup.node.config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(), | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' }, | ||
], | ||
}) | ||
], | ||
}) |
16 changes: 16 additions & 0 deletions
16
packages/compare-images/typescript/dist/pipelines/compare-double-images.js
Large diffs are not rendered by default.
Oops, something went wrong.
21 changes: 21 additions & 0 deletions
21
packages/compare-images/typescript/dist/pipelines/compare-double-images.umd.js
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file added
BIN
+926 KB
packages/compare-images/typescript/dist/pipelines/compare-double-images.wasm
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
packages/compare-images/typescript/src/compare-double-images-node-result.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.