@@ -5,42 +5,75 @@ import setupDicomForm from './dicomForm'
5
5
import parseDicomFiles from './parseDicomFiles'
6
6
7
7
const outputFileInformation = curry ( async function outputFileInformation ( outputTextArea , event ) {
8
- outputTextArea . textContent = "Parsing..."
8
+
9
+ function replacer ( key , value ) {
10
+ if ( ! ! value && value . byteLength !== undefined ) {
11
+ return String ( value . slice ( 0 , 6 ) ) + '...'
12
+ }
13
+ return value
14
+ }
15
+
16
+ function startChrono ( message ) {
17
+ outputTextArea . textContent += `-- ${ message } ... `
18
+ return start = window . performance . now ( )
19
+ }
20
+
21
+ function endChrono ( start ) {
22
+ let end = window . performance . now ( )
23
+ let time = end - start
24
+ let timeStr = `${ time . toFixed ( 2 ) } ms`
25
+ outputTextArea . textContent += `${ timeStr } \n`
26
+ return time
27
+ }
28
+
29
+ outputTextArea . textContent = ""
9
30
10
31
// Get files
11
32
const dataTransfer = event . dataTransfer
12
33
const files = event . target . files || dataTransfer . files
13
34
14
35
// Parse DICOM metadata
36
+ let start = startChrono ( "Parsing + organising all files using javascript" )
15
37
const { patients, failures } = await parseDicomFiles ( files , true )
38
+ const parseTime = endChrono ( start )
16
39
17
- // Select DICOM serie
18
- outputTextArea . textContent = "Please select serie..."
40
+ // Select DICOM series
19
41
setupDicomForm ( patients , async ( serie ) => {
20
- console . time ( 'customRead:' )
42
+ // Read image data with javascript code
43
+ start = startChrono ( "Loading image data using javascript" )
21
44
const image1 = serie . getImageData ( )
22
- console . log ( image1 )
23
- console . warn ( image1 . data . length )
24
- console . timeEnd ( 'customRead:' )
25
- outputTextArea . textContent = "Loading..."
45
+ const loadTime = endChrono ( start )
46
+ outputTextArea . textContent += JSON . stringify ( image1 , replacer , 4 )
47
+ outputTextArea . textContent += '\n'
26
48
27
- // Read DICOM serie
28
- console . time ( 'itkRead:' )
49
+ // Read image data with itk
50
+ start = startChrono ( "Parsing selected series files + loading image data using itk" )
29
51
const files = Object . values ( serie . images ) . map ( ( image ) => image . file )
30
52
const { image, webWorker } = await readImageDICOMFileSeries ( null , files )
31
53
webWorker . terminate ( )
32
- console . log ( image )
33
- console . warn ( image . data . length )
34
- console . timeEnd ( 'itkRead:' )
35
-
36
- // Display
37
- function replacer ( key , value ) {
38
- if ( ! ! value && value . byteLength !== undefined ) {
39
- return String ( value . slice ( 0 , 6 ) ) + '...'
54
+ const itkTime = endChrono ( start )
55
+ outputTextArea . textContent += JSON . stringify ( image , replacer , 4 )
56
+ outputTextArea . textContent += '\n'
57
+
58
+ // Time compare
59
+ let ratio = Math . round ( itkTime / ( parseTime + loadTime ) )
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 )
68
+ }
69
+ for ( let i = 0 ; i < image . data . length ; i ++ ) {
70
+ if ( image1 . data [ i ] !== image . data [ i ] ) {
71
+ let msg = `Element ${ i } differs 𐄂`
72
+ outputTextArea . textContent += ` ${ msg } \n`
73
+ throw Error ( msg )
40
74
}
41
- return value
42
75
}
43
- outputTextArea . textContent = JSON . stringify ( image , replacer , 4 )
76
+ outputTextArea . textContent += ' they match ✓'
44
77
} )
45
78
} )
46
79
0 commit comments