Git Product home page Git Product logo

Comments (5)

kaspermarstal avatar kaspermarstal commented on July 18, 2024

I suggest not fiddling with internal pixeltypes and instead do one of two things.

  1. Go into the SimpleElastixBuildDirectory/elastix-build and set the USE_ALL_PXELTYPES CMake variable to ON and recompile the project. You may have to start the compilation from the SimpleElastixBuildDirectory/SimpleITK-build directory for the linker to pickup the updated libraries.
  2. Cast the images to a float pixel type using the CastImageFilter:
    CastImageFilter caster = new CastImageFilter();
    caster.setOutputPixelType( sitkFloat32 );
    Image castImage = caster.execute( image );

Let me know how it goes!

from simpleelastix.

mongoose54 avatar mongoose54 commented on July 18, 2024

@kaspermarstal Your second solution seems to work. Only for float32. Any other encoding seems to fail. Here is my code in case someone wants to use it:

`public void simpleelastixtest() {

    CastImageFilter caster = new CastImageFilter();
    caster.setOutputPixelType(PixelIDValueEnum.sitkFloat32);

    org.apache.logging.log4j.Logger log = MSLog4J2.getLogger();

    // Instantiate SimpleElastix
    org.itk.simple.SimpleElastix elastix = new org.itk.simple.SimpleElastix();

    // Read input
    org.itk.simple.ImageFileReader reader1 = new org.itk.simple.ImageFileReader();

    reader1.setFileName("brain1.png");
    Image castImage1 = caster.execute(reader1.execute());
    elastix.setFixedImage(castImage1);
    log.info(castImage1.getHeight());

    org.itk.simple.ImageFileReader reader2 = new org.itk.simple.ImageFileReader();
    reader2.setFileName("brain1.png");
    Image castImage2 = caster.execute(reader2.execute());
    elastix.setMovingImage(castImage2);
    log.info(castImage2.getHeight());

    elastix.setParameterMap(elastix.getDefaultParameterMap("rigid"));
    elastix.logToConsoleOn();


    // Perform registration
    elastix.execute();

    // Write result image
    ImageFileWriter writer = new org.itk.simple.ImageFileWriter();
    writer.setFileName("test.png");
    writer.execute(elastix.getResultImage());

    elastix.prettyPrint(elastix.getTransformParameterMap());

}`

However the example doesn't save the output image. Or more accurately Elastix is missing the output path . Is there a way to set the output path for Elastix? Here is the output of the console. "Brain1.png" is this image.

from simpleelastix.

kaspermarstal avatar kaspermarstal commented on July 18, 2024

Looks like there is an error in the example. The call to execute on the writer should be writer.execute(elastix.getResultImage(), "path/to/folder"). Does this help?

The output path controls the directory of the log file. You can set the directory using `LogToFolder("path/to/folder").

from simpleelastix.

mongoose54 avatar mongoose54 commented on July 18, 2024

@kaspermarstal Thanks for the suggestion. LogToFolder () helps with not producing errors. Now the logs are stored. However even with this the result image is written into the local path "test.png" with 0 size. I am attaching the new code:

`public void simpleelastixtest() {

CastImageFilter caster = new CastImageFilter();
caster.setOutputPixelType(PixelIDValueEnum.sitkFloat32);

org.apache.logging.log4j.Logger log = MSLog4J2.getLogger();

// Instantiate SimpleElastix
org.itk.simple.SimpleElastix elastix = new org.itk.simple.SimpleElastix();

// Read input
org.itk.simple.ImageFileReader reader1 = new org.itk.simple.ImageFileReader();

reader1.setFileName("brain1.png");
Image castImage1 = caster.execute(reader1.execute());
elastix.setFixedImage(castImage1);
log.info(castImage1.getHeight());

org.itk.simple.ImageFileReader reader2 = new org.itk.simple.ImageFileReader();
reader2.setFileName("brain1.png");
Image castImage2 = caster.execute(reader2.execute());
elastix.setMovingImage(castImage2);
log.info(castImage2.getHeight());

elastix.setParameterMap(elastix.getDefaultParameterMap("rigid"));
elastix.logToConsoleOn();
elastix.logToFolder("\\elastixtestlogs\\");

// Perform registration
elastix.execute();

// Write result image
ImageFileWriter writer = new org.itk.simple.ImageFileWriter();
writer.execute(elastix.getResultImage(),"test.png",false);

}`

Running elastix.getResultImage().getHeight() gives me the dimension of the image. So I guess the image is produced.

from simpleelastix.

mongoose54 avatar mongoose54 commented on July 18, 2024

OK so I just figured it out why it didn't save the image. ImageFileWriter can export only to .nii file formats.

from simpleelastix.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.