Skip to content

Commit f730274

Browse files
committed
Use Pyodide 0.17.0 release instead and update README
1 parent f8751d4 commit f730274

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Please use VS Code and bulit-in TypeScript/Python formatter setting. Please inst
4444

4545
### Setup Pyodide
4646

47-
The current code alreasy uses local latest Pyodide dev version to speed up loading instead of CDN, just download it once. The zip file is https://github.com/grimmer0125/embedded-python-dicom-visualization-reactapp/releases/download/v0.1/pyodide.zip and you can just execute
47+
The current code uses local built Pyodide 0.17.0 version to speed up loading instead of CDN, just download it once. The zip file is https://github.com/grimmer0125/embedded-python-dicom-visualization-reactapp/releases/download/v0.2/pyodide.zip and you can just execute
4848

4949
`$ sh download_pyodide.sh`
5050

@@ -71,9 +71,9 @@ await micropip.install('pydicom')
7171
7272
```
7373

74-
#### Why use latest dev instead of 0.17.0a2 Pyodide
74+
#### Why use 0.17.0 Pyodide version
7575

76-
Since we need to use `getBuffer` method to eliminate memory allocation/copy, that method only exists in the latest dev. During flattening a 2d grey array to 1d RGBA array, we need to allocate 1d RGBA arrray, we have moved this operation into Python Pyoidie side, so we need to avoid extra memory allocation due to `new Uint8ClampedArray` in the previous JS code.
76+
Since we need to use `getBuffer` method which is added in `v0.17.0` to eliminate memory allocation/copy, that method only exists in the latest dev. During flattening a 2D grey array to 1D RGBA array, we need to allocate 1D RGBA arrray, we have moved this operation into Python Pyoidie side, so we need to avoid extra memory allocation due to `new Uint8ClampedArray` in the previous JS code.
7777

7878
### Install Python, Node.js and their dependencies for intel and Mac M1 (arm) machines
7979

@@ -160,8 +160,8 @@ Below non handled items are done in another project https://github.com/grimmer01
160160

161161
1. [Solved][performance] Using Python numpy in browser is slow, it takes `3~4s` for 1 512\*512 array operation. Using pure JavaScript takes less than 0.5s. Ref: https://github.com/pyodide/pyodide/issues/112 (the author said WebAssembly may takes `3~5x` slow). The solution might be
162162

163-
1. (can rollback to git commit: `219299f9adec489134206faf0cfab79d8345a7df`), using pydicom to parse DICOM files, sending pixel data to JS, then use JS to flatten 2d grey data to 1d RGBA canvas image data.~~
164-
2. [Use this way, solved] Or is there any quick way in numpy for flattening a 2d grey array to 1d RGBA array with normalization? Such as https://stackoverflow.com/questions/59219210/extend-a-greyscale-image-to-fit-a-rgb-image? Also image2d.min()/max() is fast. Need more study/profiling.
163+
1. (can rollback to git commit: `219299f9adec489134206faf0cfab79d8345a7df`), using pydicom to parse DICOM files, sending pixel data to JS, then use JS to flatten 2D grey data to 1D RGBA canvas image data.~~
164+
2. [Use this way, solved] Or is there any quick way in numpy for flattening a 2D grey array to 1D RGBA array with normalization? Such as https://stackoverflow.com/questions/59219210/extend-a-greyscale-image-to-fit-a-rgb-image? Also image2D.min()/max() is fast. Need more study/profiling.
165165

166166
Speed (using above sample file to test, file: `OT-MONO2-8-hip.dcm` on https://barre.dev/medical/samples/):
167167

download_pyodide.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22

33
BASEDIR=$(dirname "$0")
4-
curl -JL https://github.com/grimmer0125/embedded-python-dicom-visualization-reactapp/releases/download/v0.1/pyodide.zip > $BASEDIR/pyodide.zip
4+
curl -JL https://github.com/grimmer0125/embedded-python-dicom-visualization-reactapp/releases/download/v0.2/pyodide.zip > $BASEDIR/pyodide.zip
55
unzip $BASEDIR/pyodide.zip -d $BASEDIR/public
66
rm -r $BASEDIR//public/__MACOSX
77
rm $BASEDIR/pyodide.zip

public/python/dicom_parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ def flatten_grey_image2d_to_rgba_1d_image_array_non_numpy_way(image2d):
191191
def main(is_pyodide_context: bool):
192192
if is_pyodide_context:
193193
from my_js_module import buffer # pylint: disable=import-error
194-
ds = get_pydicom_dataset_from_js_buffer(buffer)
194+
ds = get_pydicom_dataset_from_js_buffer(buffer.to_py())
195195
else:
196196
# start to do some local Python stuff, e.g. testing
197197
ds = get_pydicom_dataset_from_local_file(

0 commit comments

Comments
 (0)