itk-wasm
itk-wasm copied to clipboard
ITKMorphologicalContourInterpolation
Hello everyone,
I would like to use "ITKMorphologicalContourInterpolation" from ITK inside of the browser. Is it possible? I have followed the steps to install itk-js, but I can't find this class and I don't see what I should do... Any help would be greatly appreciated!
Best, Thomas
Hello Thomas,
Yes, we will create an example.
Thanks, Matt
Hello,
Thank you for your answer!
Do you confirm that it is indeed possible to use this class using itk-js? Could you also give me a lead on how this could be done? I need this feature quite urgently and might need to go another direction if things don't evolve here, but I would really like to use this class.
Thank you for the help!
Yes, @finetjul has used it in an application, but I do not know if has been made open source, yet.
Sure, here is what we do:
#include <iostream>
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
#include "itkMorphologicalContourInterpolator.h"
int main(int argc, char** argv) {
if(argc != 3)
{
std::cout << "Usage: " << argv[0] << " <input> <output>" << std::endl;
return EXIT_FAILURE;
}
const char * inputImageFile = argv[1];
const char * outputImageFile = argv[2];
using PixelType = unsigned short;
constexpr unsigned int Dimension = 3;
using ImageType = itk::Image<PixelType, Dimension>;
using ReaderType = itk::ImageFileReader<ImageType>;
auto reader = ReaderType::New();
reader->SetFileName(argv[1]);
using InterpolatorType = itk::MorphologicalContourInterpolator<ImageType>;
auto interpolator = InterpolatorType::New();
interpolator->SetInput(reader->GetOutput());
// This filter fails with the default emscripten trap mode.
// https://github.com/emscripten-core/emscripten/blob/906e14e4173e00b47ed931f993c837eb7c6f649a/site/source/docs/compiling/WebAssembly.rst#trap-mode
using WriterType = itk::ImageFileWriter<ImageType>;
auto writer = WriterType::New();
writer->SetInput(interpolator->GetOutput());
writer->SetFileName(argv[2]);
try{
writer->Update();
}catch(itk::ExceptionObject & err){
std::cerr << err << std::endl;
}
return EXIT_SUCCESS;
}
There are examples on itk.js to build with emscripten.
You then add your WASM to webpack and use runPipelineBrowser to execute the program within JS.
Sure, here is what we do:
@finetjul thanks!
// This filter fails with the default emscripten trap mode. https://github.com/emscripten-core/emscripten/blob/906e14e4173e00b47ed931f993c837eb7c6f649a/site/source/docs/compiling/WebAssembly.rst#trap-mode
Note -- we are fixing this by default with the next version of itk.js by adding the flag -s BINARYEN_TRAP_MODE=clamp.