@@ -33,47 +33,114 @@ const outputFileInformation = curry(async function outputFileInformation (output
33
33
const files = event . target . files || dataTransfer . files
34
34
35
35
// Parse DICOM metadata
36
- let start = startChrono ( " Parsing + organising all files using javascript" )
37
- const { patients, failures } = await parseDicomFiles ( files , true )
36
+ let start = startChrono ( ` Parsing + organising ${ files . length } files using javascript` )
37
+ const { patients, failures } = await parseDicomFiles ( files , false )
38
38
const parseTime = endChrono ( start )
39
+ console . log ( `PARSE: ${ parseTime } ` ) ;
39
40
40
41
// Select DICOM series
41
42
setupDicomForm ( patients , async ( serie ) => {
43
+ console . log ( serie . metaData . Modality )
44
+ console . log ( serie . metaData . SeriesDescription )
45
+ console . log ( serie . metaData . TransferSyntaxUID )
46
+
47
+ // Init web workers
48
+ const images = Object . values ( serie . images ) ;
49
+ start = startChrono ( "Loading one file with itk to init webworkerspool" )
50
+ const { } = await readImageDICOMFileSeries ( [ images [ 0 ] . file ] , true )
51
+ const itkTimeTrue = endChrono ( start )
52
+ console . log ( `ITK READ 1 + WEBWORKERS: ${ itkTimeTrue } ` ) ;
53
+
54
+
55
+ // Read image data with itk (sort = true)
56
+ const seriesFiles = images . map ( ( image ) => image . file )
57
+ start = startChrono ( `Parsing selected series ${ seriesFiles . length } files + loading image data using itk & sort=true` )
58
+ const readItkSortTrue = await readImageDICOMFileSeries ( seriesFiles , true )
59
+ const imageSortTrue = readItkSortTrue . image
60
+ const itkTimeSortTrue = endChrono ( start )
61
+ console . log ( `ITK READ + SORT: ${ itkTimeSortTrue } ` ) ;
62
+
63
+ // Read image data with itk (sort = false)
64
+ start = startChrono ( `Parsing selected series ${ seriesFiles . length } files + loading image data using itk & sort=false` )
65
+ const readItkSortFalse = await readImageDICOMFileSeries ( seriesFiles , true )
66
+ const imageSortFalse = readItkSortFalse . image
67
+ const itkTimeSortFalse = endChrono ( start )
68
+ console . log ( `ITK READ NO SORT: ${ itkTimeSortFalse } ` ) ;
69
+
42
70
// Read image data with javascript code
43
71
start = startChrono ( "Loading image data using javascript" )
44
- const image1 = serie . getImageData ( )
45
- const loadTime = endChrono ( start )
46
- outputTextArea . textContent += JSON . stringify ( image1 , replacer , 4 )
47
- outputTextArea . textContent += '\n'
48
-
49
- // Read image data with itk
50
- start = startChrono ( "Parsing selected series files + loading image data using itk" )
51
- const files = Object . values ( serie . images ) . map ( ( image ) => image . file )
52
- const { image, webWorker } = await readImageDICOMFileSeries ( null , files )
53
- webWorker . terminate ( )
54
- const itkTime = endChrono ( start )
55
- outputTextArea . textContent += JSON . stringify ( image , replacer , 4 )
56
- outputTextArea . textContent += '\n'
72
+ const imageDicomParser = serie . getImageData ( )
73
+ const dicomParserTime = endChrono ( start )
74
+ // outputTextArea.textContent += JSON.stringify(image1, replacer, 4)
75
+ // outputTextArea.textContent += '\n'
76
+ console . log ( `DICOM PARSER READ: ${ dicomParserTime } ` ) ;
57
77
58
78
// Time compare
59
- let ratio = ( itkTime / ( parseTime + loadTime ) ) . toFixed ( 2 )
60
- outputTextArea . textContent += `-- js code was about ${ ratio } x faster than itk's webassembly dicom reader\n`
61
-
62
- // Image compare
63
- outputTextArea . textContent += "-- Comparing pixel data..."
64
- if ( image1 . data . length !== image . data . length ) {
65
- let msg = 'Pixel data size differ 𐄂'
66
- outputTextArea . textContent += ` ${ msg } \n`
67
- throw Error ( msg )
79
+ let ratio = ( itkTimeSortTrue / ( parseTime + dicomParserTime ) ) . toFixed ( 2 )
80
+ outputTextArea . textContent += `-- js code was ~${ ratio } x faster than itk's webassembly dicom reader (sort=true)\n`
81
+ ratio = ( itkTimeSortFalse / ( parseTime + dicomParserTime ) ) . toFixed ( 2 )
82
+ outputTextArea . textContent += `-- js code was ~${ ratio } x faster than itk's webassembly dicom reader (sort=false)\n`
83
+
84
+ function arraysMatch ( arr1 , arr2 ) {
85
+ if ( arr1 . length !== arr2 . length ) {
86
+ outputTextArea . textContent += ` -- Mismatch in length (${ arr1 . length } vs ${ arr2 . length } ) for `
87
+ return false ;
88
+ }
89
+ for ( let i = 0 ; i < arr1 . length ; i += 1 ) {
90
+ if ( arr1 [ i ] !== arr2 [ i ] ) {
91
+ outputTextArea . textContent += ` -- At least one value doesn't match (${ arr1 [ i ] } vs ${ arr2 [ i ] } ) at index ${ i } in `
92
+ return false ;
93
+ }
94
+ }
95
+ return true ;
68
96
}
69
- for ( let i = 0 ; i < image . data . length ; i ++ ) {
70
- if ( image1 . data [ i ] !== image . data [ i ] ) {
71
- let msg = `Element ${ i } differs: ${ image1 . data [ i ] } !== ${ image . data [ i ] } `
72
- outputTextArea . textContent += ` ${ msg } \n`
73
- throw Error ( msg )
97
+ function objectsMatch ( a , b ) {
98
+ const aProps = Object . getOwnPropertyNames ( a ) ;
99
+ const bProps = Object . getOwnPropertyNames ( b ) ;
100
+ if ( aProps . length !== bProps . length ) {
101
+ outputTextArea . textContent += ` -- Mismatch in number of properties (${ aProps . length } vs ${ aProps . length } )\n`
102
+ return false ;
103
+ }
104
+ let match = true ;
105
+ for ( let i = 0 ; i < aProps . length ; i += 1 ) {
106
+ const propName = aProps [ i ] ;
107
+ if ( a [ propName ] instanceof Array ) {
108
+ if ( ! arraysMatch ( a [ propName ] , b [ propName ] ) ) {
109
+ outputTextArea . textContent += `"${ propName } "\n`
110
+ match = false ;
111
+ }
112
+ } else if ( a [ propName ] instanceof Object ) {
113
+ match = match && objectsMatch ( a [ propName ] , b [ propName ] )
114
+ } else if ( a [ propName ] !== b [ propName ] ) {
115
+ match = false ;
116
+ outputTextArea . textContent += ` -- Values don't match (${ a [ propName ] } vs ${ b [ propName ] } ) for "${ propName } "\n`
117
+ }
74
118
}
119
+ if ( match == true ) {
120
+ outputTextArea . textContent += ` -- Perfect match ✓`
121
+ }
122
+ return true ;
75
123
}
76
- outputTextArea . textContent += ' they match ✓'
124
+
125
+ outputTextArea . textContent += `-- comparing image from js code and itk's webassembly dicom reader (sort=false)\n`
126
+ objectsMatch ( imageDicomParser , imageSortFalse )
127
+ outputTextArea . textContent += `-- comparing image from js code and itk's webassembly dicom reader (sort=true)\n`
128
+ objectsMatch ( imageDicomParser , imageSortTrue )
129
+ // // Image compare
130
+ // outputTextArea.textContent += "-- Comparing pixel data..."
131
+ // if (image1.data.length !== image.data.length) {
132
+ // let msg = 'Pixel data size differ 𐄂'
133
+ // outputTextArea.textContent += ` ${msg}\n`
134
+ // throw Error(msg)
135
+ // }
136
+ // for (let i = 0; i < image.data.length; i++) {
137
+ // if (image1.data[i] !== image.data[i]) {
138
+ // let msg = `Element ${i} differs: ${image1.data[i]} !== ${image.data[i]}`
139
+ // outputTextArea.textContent += ` ${msg}\n`
140
+ // throw Error(msg)
141
+ // }
142
+ // }
143
+ // outputTextArea.textContent += ' they match ✓'
77
144
} )
78
145
} )
79
146
0 commit comments