@@ -3,14 +3,15 @@ import {
33 InterfaceTypes ,
44 PipelineOutput ,
55 PipelineInput ,
6- runPipelineNode
7- } from ' itk-wasm'
6+ runPipelineNode ,
7+ } from " itk-wasm" ;
88
9- import CompareDoubleImagesOptions from ' ./compare-double-images-options.js'
10- import CompareDoubleImagesNodeResult from ' ./compare-double-images-node-result.js'
11- import CompareImagesMetric from ' ./compare-images-metric.js'
9+ import CompareDoubleImagesOptions from " ./compare-double-images-options.js" ;
10+ import CompareDoubleImagesNodeResult from " ./compare-double-images-node-result.js" ;
11+ import CompareImagesMetric from " ./compare-images-metric.js" ;
1212
13- import path from 'path'
13+ import path from "path" ;
14+ import { fileURLToPath } from "url" ;
1415
1516/**
1617 * Compare double pixel type images with a tolerance for regression testing.
@@ -22,86 +23,88 @@ import path from 'path'
2223 */
2324async function compareDoubleImagesNode (
2425 testImage : Image ,
25- options : CompareDoubleImagesOptions = { baselineImages : [ ] as Image [ ] , }
26- ) : Promise < CompareDoubleImagesNodeResult > {
27-
26+ options : CompareDoubleImagesOptions = { baselineImages : [ ] as Image [ ] }
27+ ) : Promise < CompareDoubleImagesNodeResult > {
2828 const desiredOutputs : Array < PipelineOutput > = [
2929 { type : InterfaceTypes . JsonCompatible } ,
3030 { type : InterfaceTypes . Image } ,
3131 { type : InterfaceTypes . Image } ,
32- ]
32+ ] ;
3333
3434 const inputs : Array < PipelineInput > = [
3535 { type : InterfaceTypes . Image , data : testImage } ,
36- ]
36+ ] ;
3737
38- const args = [ ]
38+ const args = [ ] ;
3939 // Inputs
40- const testImageName = '0'
41- args . push ( testImageName as string )
40+ const testImageName = "0" ;
41+ args . push ( testImageName as string ) ;
4242
4343 // Outputs
44- const metricsName = '0'
45- args . push ( metricsName )
44+ const metricsName = "0" ;
45+ args . push ( metricsName ) ;
4646
47- const differenceImageName = '1'
48- args . push ( differenceImageName )
47+ const differenceImageName = "1" ;
48+ args . push ( differenceImageName ) ;
4949
50- const differenceUchar2dImageName = '2'
51- args . push ( differenceUchar2dImageName )
50+ const differenceUchar2dImageName = "2" ;
51+ args . push ( differenceUchar2dImageName ) ;
5252
5353 // Options
54- args . push ( ' --memory-io' )
54+ args . push ( " --memory-io" ) ;
5555 if ( typeof options . baselineImages !== "undefined" ) {
56- if ( options . baselineImages . length < 1 ) {
57- throw new Error ( '"baseline-images" option must have a length > 1' )
56+ if ( options . baselineImages . length < 1 ) {
57+ throw new Error ( '"baseline-images" option must have a length > 1' ) ;
5858 }
59- args . push ( ' --baseline-images' )
59+ args . push ( " --baseline-images" ) ;
6060
6161 options . baselineImages . forEach ( ( value ) => {
62- const inputCountString = inputs . length . toString ( )
63- inputs . push ( { type : InterfaceTypes . Image , data : value as Image } )
64- args . push ( inputCountString )
65-
66- } )
62+ const inputCountString = inputs . length . toString ( ) ;
63+ inputs . push ( { type : InterfaceTypes . Image , data : value as Image } ) ;
64+ args . push ( inputCountString ) ;
65+ } ) ;
6766 }
6867 if ( typeof options . differenceThreshold !== "undefined" ) {
69- args . push ( '--difference-threshold' , options . differenceThreshold . toString ( ) )
70-
68+ args . push ( "--difference-threshold" , options . differenceThreshold . toString ( ) ) ;
7169 }
7270 if ( typeof options . radiusTolerance !== "undefined" ) {
73- args . push ( '--radius-tolerance' , options . radiusTolerance . toString ( ) )
74-
71+ args . push ( "--radius-tolerance" , options . radiusTolerance . toString ( ) ) ;
7572 }
7673 if ( typeof options . spatialTolerance !== "undefined" ) {
77- args . push ( '--spatial-tolerance' , options . spatialTolerance . toString ( ) )
78-
74+ args . push ( "--spatial-tolerance" , options . spatialTolerance . toString ( ) ) ;
7975 }
8076 if ( typeof options . numberOfPixelsTolerance !== "undefined" ) {
81- args . push ( '--number-of-pixels-tolerance' , options . numberOfPixelsTolerance . toString ( ) )
82-
77+ args . push (
78+ "--number-of-pixels-tolerance" ,
79+ options . numberOfPixelsTolerance . toString ( )
80+ ) ;
8381 }
8482 if ( typeof options . ignoreBoundaryPixels !== "undefined" ) {
85- options . ignoreBoundaryPixels && args . push ( ' --ignore-boundary-pixels' )
83+ options . ignoreBoundaryPixels && args . push ( " --ignore-boundary-pixels" ) ;
8684 }
8785
88- const pipelinePath = path . join ( path . dirname ( import . meta. url . substring ( 7 ) ) , 'pipelines' , 'compare-double-images' )
89-
90- const {
91- returnValue,
92- stderr,
93- outputs
94- } = await runPipelineNode ( pipelinePath , args , desiredOutputs , inputs )
86+ const pipelinePath = path . join (
87+ path . dirname ( fileURLToPath ( import . meta. url ) ) ,
88+ "pipelines" ,
89+ "compare-double-images"
90+ ) ;
91+
92+ const { returnValue, stderr, outputs } = await runPipelineNode (
93+ pipelinePath ,
94+ args ,
95+ desiredOutputs ,
96+ inputs
97+ ) ;
9598 if ( returnValue !== 0 ) {
96- throw new Error ( stderr )
99+ throw new Error ( stderr ) ;
97100 }
98101
99102 const result = {
100103 metrics : outputs [ 0 ] . data as unknown as CompareImagesMetric ,
101104 differenceImage : outputs [ 1 ] . data as Image ,
102105 differenceUchar2dImage : outputs [ 2 ] . data as Image ,
103- }
104- return result
106+ } ;
107+ return result ;
105108}
106109
107- export default compareDoubleImagesNode
110+ export default compareDoubleImagesNode ;
0 commit comments