@@ -5,42 +5,75 @@ import setupDicomForm from './dicomForm'
55import parseDicomFiles from './parseDicomFiles'
66
77const 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 = ""
930
1031 // Get files
1132 const dataTransfer = event.dataTransfer
1233 const files = event.target.files || dataTransfer.files
1334
1435 // Parse DICOM metadata
36+ let start = startChrono("Parsing + organising all files using javascript")
1537 const { patients, failures } = await parseDicomFiles(files, true)
38+ const parseTime = endChrono(start)
1639
17- // Select DICOM serie
18- outputTextArea.textContent = "Please select serie..."
40+ // Select DICOM series
1941 setupDicomForm(patients, async (serie) => {
20- console.time('customRead:')
42+ // Read image data with javascript code
43+ start = startChrono("Loading image data using javascript")
2144 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'
2648
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" )
2951 const files = Object.values(serie.images).map((image) => image.file)
3052 const { image, webWorker } = await readImageDICOMFileSeries(null, files)
3153 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 = (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)
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: ${image1.data[i]} !== ${image.data[i]}`
72+ outputTextArea.textContent += ` ${msg}\n`
73+ throw Error(msg)
4074 }
41- return value
4275 }
43- outputTextArea.textContent = JSON.stringify(image, replacer, 4)
76+ outputTextArea.textContent += ' they match ✓'
4477 })
4578})
4679
0 commit comments