# how to build watershed segmentation using itk-wasm

**URL:** <https://discourse.itk.org/t/how-to-build-watershed-segmentation-using-itk-wasm/5894>\
**Category:** Engineering\
**Tags:** itk-wasm-empscripten\
**Created:** [April 24, 2023, 7:42pm UTC](https://discourse.itk.org/t/how-to-build-watershed-segmentation-using-itk-wasm/5894 "2023-04-24T19:42:25Z")\
**Posts on this page:** 2\
**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:** [April 24, 2023, 7:42pm UTC](https://discourse.itk.org/t/how-to-build-watershed-segmentation-using-itk-wasm/5894/1 "2023-04-24T19:42:25Z")

</div>

@matt.mccormick

Hi,

`I already appreciate your help matt.`

I have a big question about build watershed segmentation in itk-wasm/emscripten(JS). i did manage to get the wasi-build working and segmented several png images, but i did build for emscripten (JS) and ran it as like InputsOutputs example(which worked just fine) i get a crash with lots of javascript logged out on screen.

`Here is the screen shot:`

 ![emscripten-build-release1](https://discourse.itk.org/uploads/default/original/2X/c/c385bc470eb8dcfe1c5648a1dfc803ff80d7f6b4.png)

that is why i contacted you about `Debugging example` which took me couple of days to run it, yet not complete and i send you the report about it. I wanted to use debugging to step into c++ code (which compiled to JS).  
you responded use `bindgen` to generate typescript and run it in dev tools and step into the javascript and c++ code.  
`bindgen needs a @itk-wasm/watershed which i dont have it. I know how to pubish package but i dont know how to make one like you did in @itk-wasm/mean-squares-versor-registration package. i did look at that example and could not figure it out how to make similar one for watershed that can generate typescript folder`

i have following concerns:

1. created account on [npmjs.com](http://npmjs.com) `sohrab123` and i published regular and scoped packages, i could not `npm install @sohrab123/package?! `May be because i am the publisher of the package` but i could npm install package in another node.js program without @sohrab123/package`. I have published @sohrab123/itk-wasm-segmentation-watershed-morphological on npm site, hoping i could use it as bingen package, do you think you could install it in your node.js then tell me how to make it a bindgen package, is there a program automatically generates bindgen package?

2. I studied and built `mean-squares-versor-registration but wasi test failed?!` i checked the test folder and no registered image output found, obviously, program wasi failed the test. `i checked the typescript folder all the .ts files, package.json, and rest of the scripts but could not figure out how to write one similar to that so i can use it for build:bindgen:typescript? as @sohrab123/watershed similar to @itk-wasm/mean-square-versor-registration`

3. If i use the typescript folder in mean-squares-versor-registration generated by bindgen, would that work? if so what would i need to change in that folder? replace names of mean-squares-versor-registration with itk-wasm-segmentation-watershed-morphological ? what else would i need to change to make one bindgen package for my application i really need help about this.

4. do i need to change names, image file names, i probably need one input image rather than two fixed and moving images, what else should i change?

5. the mean-squares-versor-morphological is not working properly, what am i doing wrong? If you could see into it and tell me the problem: i did:  
I `git clone the mean-squares-versor-registration`, next \> `npm install` next \> `npm run build`  
a. cd typescript folder  
b. npm install  
c. npm run build  
d. npm run test:wasi \> test had error  
e. I stopped here to get advice from you

`here is the segmentation cxx file:`

[SegmWatShedMorph.cxx](https://discourse.itk.org/uploads/short-url/41DYrskgiOoehhsvX0JdfixTnIL.cxx) (15.6 KB)

`png watersheded image from wasi test:`

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

`I guess i am close to be able to run the watershed on web browser, debug it, and then with dev tools and step into c++, javascript, and go from there. I just need some directions and help.`

p.s.: if it is not trouble please npm install @sohrab123/itk-wasm-segmentation-watershed-morphological package, if you can can you modify the @itk-wasm/mean-squares-versor-registration and send it to me so i can use it for other applications?  
greatly appreciated matt.

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:** [April 24, 2023, 8:36pm UTC](https://discourse.itk.org/t/how-to-build-watershed-segmentation-using-itk-wasm/5894/2 "2023-04-24T20:36:27Z")

</div>

Hi @sag,

> Here is the screen shot:

Building with `-DCMAKE_BUILD_TYPE:STRING=Debug` may help. Also, build against the `*-debug` tagged _itkwasm/emscripten_ build image:

[https://hub.docker.com/r/itkwasm/emscripten/tags](https://hub.docker.com/r/itkwasm/emscripten/tags)

> [@sag](#):
>
> created account on [npmjs.com](http://npmjs.com) `sohrab123` and i published regular and scoped packages

I see the package here:

> **[itk-wasm-segmentation-watershed-morphological](https://www.npmjs.com/package/itk-wasm-segmentation-watershed-morphological)**
>
> An itk-wasm Segmentation WaterShed morphological example. Latest version: 1.0.0, last published: 9 months ago. Start using itk-wasm-segmentation-watershed-morphological in your project by running \`npm i itk-wasm-segmentation-watershed-morphological\`....

👏

As noted, it can be installed:

![image](https://discourse.itk.org/uploads/default/original/2X/1/161b2d4c99a2c018c25b7702e3bfe06cf7b0bffe.png)

```auto
npm i itk-wasm-segmentation-watershed-morphological

```

> how to make it a bindgen package, is there a program automatically generates bindgen package?

The `itk-wasm` CLI has a `bindgen` subcommand.

> I studied and built mean-squares-versor-registration but wasi test failed?!

It may help to examine how it is tested via CI:

> <https://github.com/InsightSoftwareConsortium/itk-wasm/blob/1ceb67b93c4942aea6a03afc16237992fe5d627e/.github/workflows/examples.yml#L250-L276>

> If i use the typescript folder in mean-squares-versor-registration generated by bindgen, would that work? if so what would i need to change in that folder?

It is recommended to use the package.json build script produced by bindgen that will convert TypeScript to JavaScript and bundle the JavaScript.
