-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathindex.html
91 lines (77 loc) · 2.93 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Niimath WASM Demo</title>
</head>
<body>
<h1>Niimath WASM Demo</h1>
<input type="file" id="fileInput">
<button id="processButton" disabled>Process Image</button>
<p id="status">Please select a NIfTI image file to process.</p>
<a id="downloadLink" style="display: none;">Download Processed Image</a>
<script type="module">
import { Niimath } from './dist/index.js';
const niimath = new Niimath();
const fileInput = document.getElementById('fileInput');
const processButton = document.getElementById('processButton');
const status = document.getElementById('status');
const downloadLink = document.getElementById('downloadLink');
let selectedFile = null;
fileInput.addEventListener('change', async (event) => {
selectedFile = event.target.files[0];
if (selectedFile) {
processButton.disabled = false;
status.textContent = `Selected file: ${selectedFile.name}`;
} else {
processButton.disabled = true;
status.textContent = 'Please select a NIfTI image file to process.';
}
});
processButton.addEventListener('click', async () => {
if (!selectedFile) return;
status.textContent = 'Processing...';
processButton.disabled = true;
try {
console.log('Initializing niimath wasm...');
await niimath.init();
console.log('niimath wasm initialized.');
const t0 = performance.now();
// test the -mesh command and mesh output
// const outName = 'out.mz3';
// const outFile = await niimath.image(selectedFile)
// .mesh({
// i: 'm', // 'm' for medium
// b: 1, // fill bubbles
// v: 0 // not verbose
// })
// .run(outName)
// const t1 = performance.now();
// console.log("niimath wasm took " + (t1 - t0) + " milliseconds.")
// test with a volume output
const outName = 'out.nii.gz';
niimath.setOutputDataType('input')
const outFile = await niimath.image(selectedFile)
.sobel()
.run(outName)
console.log(niimath.outputDataType)
const t1 = performance.now();
console.log("niimath wasm took " + (t1 - t0) + " milliseconds.")
// Create a download link for the processed file
const url = URL.createObjectURL(outFile);
downloadLink.href = url;
downloadLink.download = outName;
downloadLink.style.display = 'block';
downloadLink.textContent = 'Download Processed Image';
status.textContent = 'Processing complete!';
} catch (error) {
console.error('Processing failed:', error);
status.textContent = 'Processing failed. Please check the console for details.';
} finally {
processButton.disabled = false;
}
});
</script>
</body>
</html>