ITK 5.2, WASM, itk-wasm, itk-wasm/emscripten, build example common/add noise to Binary Image, yinyang

@matt.mccormick,

Hi everyone,

subject: extend HelloWorld web-build example so that i can build itk example common/add noise to Binary Image, yinyang.png using node. couple of questions please bear with me.

  1. itk-wasm is a webassembly of itk TOOLKIT, CORRECT? it also has emscripten toolchain (itkwasm/emscripten) docker image which is pulled from docker hub.correct?

  1. I always use (itk-wasm build) from command line in vscode at WSL2/UBUNTU terminal and it pulls down some images such as itkwasm/emscripten if it is not there otherwise it just compiles HelloWorld.cxx file into webassembly (HelloWorld.js, HelloWorld.wasm, HelloWorld.umd, etc inside web-build folder inside my node-js project using my CMakeLists.txt file). Is that a right comment to say HelloWorld.js is a webassembly translation of my HelloWorld.cxx and using npx node index.mjs it should run the HelloWorld.cxx program inside the webassembly or calling index.mjs javascript module program can call the HelloWorld.js translation of HelloWorld.cxx program.?
    following is my CMakeLists.txt file and pay attention no Emscripten exists in that.

  1. does this cmake file which is from building itk examples work ? i have provide include and lib folders which is the linux build of ITK! I also export the paths of the include and lib folders inside the .bashrc of wsl2/ubuntu which is my environment inside the vscode/node. I have also installed itk-wasm, itk-image-io, itk-mesh-io using npm package manager. I use node@v18.4.0 and npm@v8.12.1 — if the cmakelists.txt not suitable would you kindly recommend the best one possible for this simple itk example please. I dont even know how find_package could find ITK because i dont have any ITK.cmake or something like that to find the package? so i know somehow itkwasm/empscripten builds this c++ code with options and all that and transforms it to javascript.

  2. here is my HelloWorld.cxx file. as you can see it is the extension of HelloWorld and i have added the code related to sample itk/common/add noise to binary image. which adds noise to yinyang.png file. here is the first part of the c++ code.

and here is the second part of the c++ code.

the commented part is also included and i did not remove the comments. the whole code is included.
Q. is it valid to use this code with the provided cmake file and explanations above, and use [itk-wasm build] and the result of the build is HelloWorld.js webassembly module which is in web-build folder?

  1. I use the following index.mjs file to connect to the HelloWorld.js module to call c++ program from javascript, here is the index.mjs module

at the top only in javascript i read and write a yinyang.png file and that works fine, but when i call the HelloWorld.js module from javascript using node runPipelineNode command and pass file names, it crashes. I pass arguments [args] with three parameters (yinyang.png.json, yinyang_with_noise.png.json, percent of noise) i dont know the code because i borrowed it from internet. I understand what happens because i am learning some Javascript but the HelloWorld.js throws exception when it want to open png file yinyang. Help would be appreciated.

here is the output at wsl2/ubuntu terminal in vscode/nodejs:
part1:

part 2

  1. There is only one line of code itk::ReadImage(argv[1]) , argv[1] = “yinyang.png.json”. runPipelineNode(pipelinepath, args) is passing yinyang.png.json to c++ code. I dont think this is going to work. I also passed yinyang.png to the itk::ReadImage but that also crashes.
    Q. yinyang.png and yinyan_with_noise.png are both in the working directory of the project. is this the right way to pass the name of the files from javascript to the c++ code?

ANY HELP IS APPRECIATED
here is HelloWorld.js module:

part2 of HelloWorld.js

line 9 is where the exception is thrown in this module.

I could not possibly understand it , may matt maccormic can help me, please any one can help would be appreciated.

BR
@sag