# watershed segmentation wasi

**URL:** https://discourse.itk.org/t/watershed-segmentation-wasi/5329
**Category:** Engineering
**Tags:** itk-wasm
**Created:** [September 9, 2022, 12:14pm UTC](https://discourse.itk.org/t/watershed-segmentation-wasi/5329 "2022-09-09T12:14:20Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![sag](https://discourse.itk.org/user_avatar/discourse.itk.org/sag/32/2041_2.png) [@sag](https://discourse.itk.org/u/sag)
#### Post date: [September 9, 2022, 12:14pm UTC](https://discourse.itk.org/t/watershed-segmentation-wasi/5329/1 "2022-09-09T12:14:20Z")

</div>

@matt.mccormick

Hi mat,

I fixed it. I know now why you did the following:  
`npx itk-wasm -b wasi-build run morphological.wasi.wasm -- -- VisibleWomanEyeSlice.png WatershedSegmentation1Output1.png`  
we dont need any options like --inputFileName, we just pass –

here is the result of segmentation:

original image

![VisibleWomanEyeSlice](https://discourse.itk.org/uploads/default/original/2X/f/fff4be59342428b1741d976a7848d54d3060f616.png)

Watershed image

![WatershedSegmentation1Output1](https://discourse.itk.org/uploads/default/original/2X/b/b9634e6630ff410b10462caf85f362635420a4ea.png)

Thank you  
@sag

---

<div class="post-metadata">

### Author: ![matt.mccormick](https://discourse.itk.org/user_avatar/discourse.itk.org/matt.mccormick/32/7_2.png) [@matt.mccormick](https://discourse.itk.org/u/matt.mccormick)
#### Post date: [October 17, 2022, 7:54pm UTC](https://discourse.itk.org/t/watershed-segmentation-wasi/5329/2 "2022-10-17T19:54:53Z")

</div>

Hi @sag ,

Well done! 🎇 👁 🌈

> npx itk-wasm -b wasi-build run morphological.wasi.wasm – – VisibleWomanEyeSlice.png WatershedSegmentation1Output1.png

There are two programs running:

1. The WASI WebAssembly interpreter
2. Your WebAssembly module

The double dash `--` serves the purpose here (and it is also command in other command line programs) to separate the options between the two. Before the double dash are the WASM interpreter arguments. After are the WASM module arguments.

---

<div class="post-metadata">

### Author: ![sag](https://discourse.itk.org/user_avatar/discourse.itk.org/sag/32/2041_2.png) [@sag](https://discourse.itk.org/u/sag)
#### Post date: [October 24, 2022, 5:54pm UTC](https://discourse.itk.org/t/watershed-segmentation-wasi/5329/3 "2022-10-24T17:54:25Z")

</div>

Hi @matt.mccormick  
Thank you for theory behind WASI I understand the subject better now.

one thing to point out is that i can not figure out and get it to work for running watershed segmentation or ApplyColormapToAnImage in Node.js  
I need to pass input image file name or path and output image name or path to the WASM module and call that module via index.mjs javascript module. and it fails.However it perfectly works for WASI passing path for input/output file names.

I want to run ApplyColormapToAnImage example in node.js and i have run into problem. The following is the error i get:  
I followed the same code in InputsOutpus pipeline example except instead of passing images in c++ code i pass filenames, as WASI AND WASM module arguments. would that be the problem?

`npx node ./index.mjs ./cthead.png coloroed_node.png`

 ![watshed-node-](https://discourse.itk.org/uploads/default/original/2X/b/b472ee7ae245360362159f6a27cfee098182220f.png)

the resulting error apears in the screen shot.  
`index.mjs react code is similar to InputsOutputs pipeline example`  
following is the `index.mjs`

 ![watshed-node2](https://discourse.itk.org/uploads/default/original/2X/4/4db7e6c4e85a538f872be5833027671ca5cf3ce6.png)

1. I firstly import some function for the pipeline to execute the WASM module.
2. I build my args array passing WASM module argument which are two png image file name `cthead1.png` which is input image and `colored_node.png` is the output image file names.
3. I find the path to the `ApplyColormapToAnImage.wasm module` and run it using runPipelineNode function.
4. write the resulting image to `outputImage`.

`ApplyColormapToAnImage.cxx file`

 ![Apply-code1](https://discourse.itk.org/uploads/default/original/2X/0/0163c25f8ce50677521f6e5c539aa8f9a10230f2.png)

`ApplyColormapToAnImage.cxx --- second part of code`

 ![Apply-code2](https://discourse.itk.org/uploads/default/original/2X/0/0f4eaa2ad3902e93d49acc878aa91dc4d7f799b3.png)

what am i doing wrong here? It seems i dont understand pipeline mechanism properly. am passing my WASM module arguments properly via args in index.mjs, do i need to place doubel dash `--` before my command line arguments which i did and it did not remove the error? pleas help me understand how node.js runs the WASM module via index.mjs module. do `args` parameter in index.mjs correctly passing my file names to the `ApplyColormapToAnImage.wasm` corretly? what is going on here?  
mat i already appreciate your help

BR  
@sag

---

<div class="post-metadata">

### Author: ![matt.mccormick](https://discourse.itk.org/user_avatar/discourse.itk.org/matt.mccormick/32/7_2.png) [@matt.mccormick](https://discourse.itk.org/u/matt.mccormick)
#### Post date: [July 27, 2023, 9:07pm UTC](https://discourse.itk.org/t/watershed-segmentation-wasi/5329/4 "2023-07-27T21:07:28Z")

</div>

Hi,

A late note here in case it is helpful to someone, the error message about the `itk-wasm` package not being found is related to how Node.js finds dependencies. Typically for node.js projects, a “package” is created for a script, defined with a `package.json` file, that defines an entry module, e.g. `index.mjs`, and dependencies. Then the dependencies are installed and available in a local _node\_modules/_ directory.
