@@ -33,47 +33,98 @@ 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
+ const images = Object . values ( serie . images ) ;
48
+ const seriesFiles = images . map ( ( image ) => image . file )
49
+
50
+ // Read image data with itk (preSorted = true)
51
+ start = startChrono ( `Parsing selected series ${ seriesFiles . length } files + loading image data using itk (preSorted=true)` )
52
+ const readItkSortedTrue = await readImageDICOMFileSeries ( seriesFiles , true )
53
+ const imageSortedTrue = readItkSortedTrue . image
54
+ const itkTimeSortedTrue = endChrono ( start )
55
+ // outputTextArea.textContent += JSON.stringify(imageSortedTrue, replacer, 4)
56
+ // outputTextArea.textContent += '\n'
57
+ console . log ( `ITK READ PRESORTED: ${ itkTimeSortedTrue } ` ) ;
58
+
59
+ // Read image data with itk (preSorted = false)
60
+ start = startChrono ( `Parsing selected series ${ seriesFiles . length } files + loading image data using itk (preSorted=false)` )
61
+ const readItkSortedFalse = await readImageDICOMFileSeries ( seriesFiles , false )
62
+ const imageSortedFalse = readItkSortedFalse . image
63
+ const itkTimeSortedFalse = endChrono ( start )
64
+ // outputTextArea.textContent += JSON.stringify(imageSortedFalse, replacer, 4)
65
+ // outputTextArea.textContent += '\n'
66
+ console . log ( `ITK SORT + READ: ${ itkTimeSortedFalse } ` ) ;
67
+
42
68
// Read image data with javascript code
43
69
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'
70
+ const imageDicomParser = serie . getImageData ( )
71
+ const dicomParserTime = endChrono ( start )
72
+ // outputTextArea.textContent += JSON.stringify(imageDicomParser, replacer, 4)
73
+ // outputTextArea.textContent += '\n'
74
+ console . log ( `DICOMPARSER READ: ${ dicomParserTime } ` ) ;
57
75
58
- // 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 )
76
+ // Images compare
77
+ function arraysMatch ( arr1 , arr2 ) {
78
+ if ( arr1 . length !== arr2 . length ) {
79
+ outputTextArea . textContent += `⚠️ Mismatch in length (${ arr1 . length } vs ${ arr2 . length } ) for `
80
+ return false ;
81
+ }
82
+ for ( let i = 0 ; i < arr1 . length ; i += 1 ) {
83
+ if ( arr1 [ i ] !== arr2 [ i ] ) {
84
+ outputTextArea . textContent += `⚠️ Values don't match (${ arr1 [ i ] } vs ${ arr2 [ i ] } ) at index ${ i } in `
85
+ return false ;
86
+ }
87
+ }
88
+ return true ;
68
89
}
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 )
90
+ function objectsMatch ( a , b ) {
91
+ const aProps = Object . getOwnPropertyNames ( a ) ;
92
+ const bProps = Object . getOwnPropertyNames ( b ) ;
93
+ if ( aProps . length !== bProps . length ) {
94
+ outputTextArea . textContent += `⚠️ Mismatch in number of properties (${ aProps . length } vs ${ aProps . length } )\n`
95
+ return false ;
74
96
}
97
+ let match = true ;
98
+ for ( let i = 0 ; i < aProps . length ; i += 1 ) {
99
+ const propName = aProps [ i ] ;
100
+ if ( a [ propName ] instanceof Array || ArrayBuffer . isView ( a [ propName ] ) ) {
101
+ if ( ! arraysMatch ( a [ propName ] , b [ propName ] ) ) {
102
+ outputTextArea . textContent += `"${ propName } "\n`
103
+ match = false ;
104
+ }
105
+ } else if ( a [ propName ] instanceof Object ) {
106
+ match = match && objectsMatch ( a [ propName ] , b [ propName ] )
107
+ } else if ( a [ propName ] !== b [ propName ] ) {
108
+ match = false ;
109
+ outputTextArea . textContent += `⚠️ Values don't match (${ a [ propName ] } vs ${ b [ propName ] } ) for "${ propName } "\n`
110
+ }
111
+ }
112
+ return match ;
113
+ }
114
+
115
+ outputTextArea . textContent += `-- Comparing image from js code and itk's webassembly dicom reader\n`
116
+ if ( objectsMatch ( imageDicomParser , imageSortedFalse ) ) {
117
+ outputTextArea . textContent += `✅ Perfect match\n`
118
+ } else {
119
+ outputTextArea . textContent += `❌ Mismatch\n`
75
120
}
76
- outputTextArea . textContent += ' they match ✓'
121
+
122
+ // Time compare
123
+ let ratio = ( itkTimeSortedTrue / ( parseTime + dicomParserTime ) ) . toFixed ( 2 )
124
+ outputTextArea . textContent += `⚡ javascript code was ~${ ratio } x faster than itk's webassembly dicom reader (preSorted=true)\n`
125
+ ratio = ( itkTimeSortedFalse / ( parseTime + dicomParserTime ) ) . toFixed ( 2 )
126
+ outputTextArea . textContent += `⚡ javascript code was ~${ ratio } x faster than itk's webassembly dicom reader (preSorted=false)\n`
127
+
77
128
} )
78
129
} )
79
130
0 commit comments