Image binarization using otsu's method on HTML ImageData in c++, compiled to WASM for the web.
See In action: Web Demo
- note: Demo loads the .wasm file without the glue code.
- Requires Emscripten.
$ em++ img_processing.cpp -s ALLOW_MEMORY_GROWTH=1 -s STANDALONE_WASM -s EXPORTED_FUNCTIONS="['_otsuBinarize', '_malloc', '_free']" -Os -o img_processing.wasmNote: when loading wasm with WebAssembly.instantiateStreaming on a local test server
- The server must be configured to serve the .wasm file with the correct MIME type by sending the Content-Type: application/wasm header
- Example: configured python http.server script:
import http.server, socketserver
PORT = 8000
Handler = http.server.SimpleHTTPRequestHandler
Handler.extensions_map['.wasm'] = 'application/wasm'
with socketserver.TCPServer(("", PORT), Handler) as httpd:
print("serving at port", PORT)
httpd.serve_forever()- Otsu thresholding — image binarization by HBY coding academic
- otsu's method Wikipedia
- Loading WebAssembly modules efficiently