itk-wasm icon indicating copy to clipboard operation
itk-wasm copied to clipboard

ITKMorphologicalContourInterpolation

Open thomas-beznik opened this issue 5 years ago • 5 comments

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

thomas-beznik avatar Apr 17 '20 16:04 thomas-beznik

Hello Thomas,

Yes, we will create an example.

Thanks, Matt

thewtex avatar Apr 17 '20 22:04 thewtex

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!

thomas-beznik avatar Apr 27 '20 09:04 thomas-beznik

Yes, @finetjul has used it in an application, but I do not know if has been made open source, yet.

thewtex avatar Apr 27 '20 19:04 thewtex

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.

finetjul avatar Apr 28 '20 07:04 finetjul

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.

thewtex avatar Apr 29 '20 13:04 thewtex