Comments (5)
I suggest not fiddling with internal pixeltypes and instead do one of two things.
- 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.
- 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.
@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.
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.
@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.
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)
- RuntimeError: Exception thrown in SimpleITK Elastix HOT 1
- AffineDTITransform does not return the CenterOfRotationPoint
- windows user :thank you very much
- Gradient based optimizer: how to control learning rate HOT 2
- Rigid transformation warping with "TransformixImageFilter"
- error of compiling on linux
- Fatal error LNK1181
- Error while installing SimpleElastix on Windows. HOT 1
- Shearing matrix composition in Affine DTI 3D Transform
- Failed to build on Win10 HOT 3
- affine registration outcome measurement
- A lot of console output even after turning it off HOT 1
- Registration with initial transform obtained using SimpleITK/etc. (.tfm file) HOT 1
- The ElastixImageFilter stuck when using iterative InitialTransformParameterFileName.
- Unable to create/compile/build SimpleElastix C++ dynamic or static library in 32bit or 64-bit.
- Trouble understanding basic usage
- Is there a way to save the transform to a .tfm file?
- AttributeError: module 'SimpleITK' has no attribute 'VesselnessMeasureImageFilter'
- Use only corresponding points based transformation
- SimpleElastix no longer maintained, use SimpleITK or ITKElastix!
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from simpleelastix.