Hello,
I try to adapt BinShrink example to write the ShrinkImage on the hard drive (using writeImageLocalFile).
If I just load the image and write it, I don t have any problem.
If I load the image, runPipelineNode with hello.cxx (the code from the sample) and then try to write the outputs on the disk. I have nothing written.... is there a bug or am I doing something wrong ?
Thanks a lot
Here are the sources used
index.js
const path = require('path')
const runPipelineNode = require('itk/runPipelineNode.js')
const readImageLocalFile = require('itk/readImageLocalFile.js')
const writeImageLocalFile = require('itk/writeImageLocalFile.js')
const IOTypes = require('itk/IOTypes.js')
const pipelinePath = path.resolve(__dirname, 'web-build', 'hello' )
const testInputFilePath = path.resolve(__dirname, 'cthead1.png')
const testOutputFilePath = path.resolve(__dirname, 'cthead1Shrink.png')
/* * /
// Working piece of code
readImageLocalFile(testInputFilePath)
.then(function (image) {
const useCompression = false
return writeImageLocalFile(useCompression, image, testOutputFilePath)
})
/* */
// Piece of code not with bug
readImageLocalFile(testInputFilePath)
.then(function (image) {
const args = ['cthead1.png.json', 'cthead1Shrink.png.json', '4']
const desiredOutputs = [
{ path: args[1], type: IOTypes.Image }
]
const inputs = [
{ path: args[0], type: IOTypes.Image, data: image }
]
return runPipelineNode(pipelinePath, args, desiredOutputs, inputs)
}).then(function ({stdout, stderr, outputs}) {
const useCompression = false
return writeImageLocalFile(useCompression, outputs[0].data, testOutputFilePath)
}).then(function () {
console.log("DEBUG - Script runned - Output written on disk")
})
/* */
hello.cxx
#include
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
#include "itkBinShrinkImageFilter.h"
int main( int argc, char *argv[] ) {
// Test from website
if( argc < 4 )
{
std::cerr << "Usage: " << argv[0] << " " << std::endl;
return EXIT_FAILURE;
}
std::cout << "Inside js coming from cxx" << std::endl;
const char * inputImageFile = argv[1];
const char * outputImageFile = argv[2];
unsigned int shrinkFactor = atoi( argv[3] );
using PixelType = unsigned char;
constexpr unsigned int Dimension = 2;
using ImageType = itk::Image< PixelType, Dimension >;
using ReaderType = itk::ImageFileReader< ImageType >;
auto reader = ReaderType::New();
reader->SetFileName( inputImageFile );
using ShrinkFilterType = itk::BinShrinkImageFilter< ImageType, ImageType >;
auto shrinker = ShrinkFilterType::New();
shrinker->SetInput( reader->GetOutput() );
shrinker->SetShrinkFactors( shrinkFactor );
using WriterType = itk::ImageFileWriter< ImageType >;
auto writer = WriterType::New();
writer->SetInput( shrinker->GetOutput() );
writer->SetFileName( outputImageFile );
try
{
writer->Update();
}
catch( itk::ExceptionObject & error )
{
std::cerr << "Error: " << error << std::endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
CMakeLists.txt
cmake_minimum_required(VERSION 3.10)
project(HelloWorld)
FIND_PACKAGE ( ITK )
IF ( ITK_FOUND )
INCLUDE( ${ITK_USE_FILE} )
ELSE (ITK_FOUND)
MESSAGE (FATAL ERROR
"itk not found. Il est ou?")
ENDIF( ITK_FOUND )
set(io_components ITKImageIO)
if(EMSCRIPTEN)
set(io_components BridgeJavaScript)
endif()
find_package(ITK REQUIRED
COMPONENTS ${io_components}
ITKImageGrid
)
include(${ITK_USE_FILE})
if(EMSCRIPTEN)
include(ITKBridgeJavaScript)
web_add_executable(hello hello.cxx)
web_target_link_libraries(hello ${ITK_LIBRARIES})
else()
add_executable(hello hello.cxx)
target_link_libraries(hello ${ITK_LIBRARIES})
endif()