Hi @matt.mccormick ,
I really appreciate your response. I tried to build and run ITK-WASM in windows but I failed. I did though succeed to build and run it in WSL2/ubuntu20.04 backend docker enabled environment. I reconfirm your post that WSL2 works for ITK-WASM.
Mat can you please help me with the ITK-WASM building an example where i pass one image into the wasm module and get out the processed image out of the wasm module using runPipelineNode in node.js environment. I am refering to the example MedianFilterTest pipeline example or Add noise to Image example of ITK.
Q. Tried to build and run MedianFilterTest example pipeline (ITK Examples) using ITK-WASM webassembly toolkit to compile it into javascript. I know that everything is working,
Here is my index.mjs code: Browed from mat ITK-WASM examples
`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]);
console.log(“===========================================”);
const ARGV1 = process.argv[1];
const ARGV2 = process.argv[2];
const ARGV3 = process.argv[3];
const ARGV4 = process.argv[4];
console.log(‘__dirname’, __dirname)
readImageLocalFile(testInputFilePath)
.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.')
})
`
Following are the files and screen shots of the node.js application in vscode EDI:
-
CMakeLists.txt file
CMakeLists.txt (586 Bytes)
-
cthead1.png.json file
cthead1.png.json (10.3 KB)
-
list of docker images download from docker hub screen shot illustrates all the necessary webassembly tools to build and run itk-wasm webassembly modules
-
MedianFilterTest.cxx file
MedianFilterTest.cxx (2.0 KB)
-
After building the project MediaFilterTest3 under WSL2/ubuntu 20.0.4 , I launched it using this command line [npx node index.mjs cthead1.png.json cthead1_out.png.json 4}
i get a crash with huge amount of javascript text dumped on the screen. there are two screen shots below illustrating this because is too large to show. It seems that it is complaining about PNGImageIOReadImage.js file. I searched the node_modules->itk-image-io package. I saw the file and it has umd and wasm version of it there too and it checks out.
This is the second part of the screen shot illustrating the last line of dumped javascript code
Mat can you help me to understand what is happening.
It seems to me that runPipelineNode(…) with parameters is the cause of this. I dont understand the sequence of the events: I have borrowed the index.mjs code
from ITK-WASM examples provided by you. images are passed in and out of runPipelineNode
API as <image.png.json>. I used online service to convert <image.png> to <image.png.json> please check out provided json images, do you think the json images are right? I saw somewhere there is an api in vtk to convert png files to json files? not sure please guide me with that.
is this [npx node index.mjs cthead1.png.json cthead1_out.png.json 4]
the right way to call the webassembly module in node.js command line? i also pass args['cthead1.png.json', cthead1_out.png.json', '4']
inside index.mjs. Is this right way of running web assembly? when i dont include parameters in the command line i dont get them inside c++ code, so i figured this is correct. what is the sequence of events here. node calls index.mjs module and then entry point is c++ code which is compiled as web assembly in MedianFilterTest.wasm and then that calls MedianFilterTest.js ?
WHAT IS THE PROBLEM TO CRASH?
CAN YOU PRIVIDE ME WITH ALL THE JSON IMAGES AND index.mjs, and CMakeLists.txt, package.json, package-loc.json, so i know how to fix this?
IS IT BECAUSE I USE WSL2/UBUNTU20.04?
CAN YOU TEST THIS UNDER LINUX?
WHAT IS WRONG HERE PLEASE ASSIST ME WITH THIS IF IT IS NOT TOO MUCH TROUBLE.
THANKS
@sag