Hi everyone,

I have hard time to extend ITK-WASM HelloWasm example to MedianFilterTest.cxx example. I managed to build it using itk-wasm build command in node.js terminal command line in VSCODE. MedianFilterTest.js/umd/wasm are created. Here is the code for index.mjs

`import path from “path”
import { IOTypes, readImageLocalFile, writeImageLocalFile, runPipelineNode, imageSharedBufferOrCopy } from “itk-wasm”
import { argv, argv0, stderr } from “process”

const testOutputFilePath = path.resolve(‘cthead1.png.out.json’);
const testInputFilePath = path.resolve(‘cthead1.png.json’);

console.log(“testInputFilePath”, testInputFilePath)
console.log(“testOutputFilePath”, testOutputFilePath)

console.log(“index.mjs: inside the module”);
console.log(“argv[0]”, process.argv[0]);
console.log(“argv[1]”, process.argv[1]);
console.log(“argv[2]”, process.argv[2]);
console.log(“argv[3]”, process.argv[3]);
console.log(“argv[4]”, process.argv[4]);

const ARGV1 = process.argv[1];
const ARGV2 = process.argv[2];
const ARGV3 = process.argv[3];
const ARGV4 = process.argv[4];

console.log(‘__dirname’, __dirname)

.then(function (image) {
const args = [‘cthead1.png.json’, ‘cthead1.png.out.json’, ‘4’] <-----
const pipelinepath = path.resolve(“web-build”, ‘MedianFilterTest3’) <-----
const desiredOutput = [{ path: args[1], IOTypes: IOTypes.Image }] <-------

    const inputs = [{ path: args[0], type: IOTypes.Image, data: image }]   <------
    console.log('Before runPipelineNode');
    return runPipelineNode(pipelinepath, args, desiredOutput, inputs)   <------
}).then(function ({ stdout, stderr, outputs }) {
    console.log('After runPipelineNode')
    const useCompression = false;
    return writeImageLocalFile(useCompression, outputs[0].data, testOutputFilePath)
}).then(function () {
    console.log('DEBUG script runned - output image is written to the local disk.')


`how to pass png image or mha or nrrd or dicom or etc. type images into wasm module MedianFilterTest.js/wasm/umd created in web-build folder?
in the above javascript code of index.mjs module i use runPipelineNode API to pass JSON type and i borrowed this from matt maccormick code in ITK-WASM examples. I created png.json file from .png file using online conversion tools. i could not find any itk tools to be able to do that so i am not sure my way is right?

Q. does anyone know how to create a json file out of cthead1.png?
Q2. how to pass image files into runPipelineNode API so transfer the files into wasm module MedianFilterTest.js/wasm/umd?
Q3. my ITK-WASM MedianFilterTest crashes in node.js VSCODE and i think there is a problem with javascript index.mjs.

following are some evidence of the crash in screen shots in addition is my development environment

CMakeLists.txt (586 Bytes)

cthead1.png.json (10.3 KB)

MedianFilterTest.cxx (2.0 KB)

package.json (1.9 KB)

package-lock.json (41.2 KB)

cthead1.png.json (10.3 KB)

I have more questions to discuss in ITK Forum about ITK-WASM MedianFilterTest example.
Thats in advance


I have similar problem. Can You tell me how did you manage to solve this?

Thanks and best regards,

Does this discussion help you? You could also look at other posts by @sag.

I still cannot solve this problem. This is what is happening:

  1. you compile your c++ code using Emscripten into javascript because that is the only way to run it in the node. you nodejs is a c++ code that embedds a v8 engine to run javascript that is why we use node.js as server to run javascript. javascript only runs inside v8 engine in chrome. therefore your WASM module has all c++ code compile into javascript.
  2. you need a .js or .mjs javascript to pass arguments into the WASM module and get it to do some ITK Pipeline c++ image segmentation, filtering, etc. and create some images and then you are set.
  3. runPipelineNode is the mechnism to do that, firstly prepares your inputs, outputs and then finds the pipeline path of WASM module which is inside the web-build folder in your node.js project.
  4. actually tried to follow the InputsOutps pipeline example prepared by @matt.mccormick and @dzenanz . the problem is that when i try to write the image back in a file it fails for WASI.WASM case. I did manage to fix this problem by passing the file names via pipeline, instead of actual itk::wasm::InputImage which is in the example InputsOutputs, therefore the WASI works because after the pipeline gets the file names of input file and output file the rest exactly the ITK C++ example either watershed example or ApplyColormapToAnImage and it writes the output file to the output. WASI worked.
  5. my problem started when i tried to run in node.js using index.mjs javascripöt to run the pipeline using runPipelineNode function. the point is that how to pass the arguments to the WASM module which javascript code using runPipelineNode, and i still cannot figure it out and it is time consuming. I read the runPipelineNode and still i cannot figure it out, what are my inputs and outputs, because i using filenames as string and the rest is running c++. may be javascript code in WASM module does not like it. this approach is different than the example in @matt.mccormick InputsOutputs example

if you could figure this out for node.js let me know because i place this question to @matt.mccormick and i have not receieved any answer yet.

if you solve this let me know because I dont know how to get the node.js to work which is important to me. I dont know how to run the wasi.wasm module inside a web browser either. but node.js seems something practical to run the ITK Pipeline inside a chrome web browser.