├── .checksums
├── .github
├── build.sh
├── setup.sh
└── workflows
│ ├── build-main.yml
│ ├── build-pr.yml
│ └── build.yml
├── .gitignore
├── LICENSE.txt
├── README.md
├── docs
├── PlatybrowserTransforms.md
└── TransformParameters.0.txt
├── pom.xml
├── scripts
└── run_elastix.groovy
└── src
├── main
└── java
│ └── de
│ └── embl
│ └── cba
│ └── elastix
│ ├── commandline
│ ├── ElastixCaller.java
│ ├── ExecutableShellScriptCreator.java
│ ├── TransformixCaller.java
│ └── settings
│ │ ├── ElastixSettings.java
│ │ ├── Settings.java
│ │ └── TransformixSettings.java
│ ├── commands
│ ├── ElastixCommand.java
│ └── TransformixCommand.java
│ ├── logging
│ ├── IJLazySwingLogger.java
│ └── Logger.java
│ ├── utils
│ ├── BatchApplyAmiraTransformationsToBdvXml.java
│ ├── BdvImagePlusExport.java
│ ├── MonitorThreadPoolStatus.java
│ ├── TransformConversions.java
│ └── Utils.java
│ └── wrapper
│ ├── BdvManager.java
│ ├── StagingManager.java
│ ├── elastix
│ ├── ElastixWrapper.java
│ ├── ElastixWrapperSettings.java
│ └── parameters
│ │ ├── DefaultElastixParametersCreator.java
│ │ └── ElastixParameters.java
│ └── transformix
│ ├── TransformixWrapper.java
│ └── TransformixWrapperSettings.java
└── test
├── java
├── ExampleElastixAPI.java
├── ExampleTransformixAPI.java
├── TimElastixAPI.java
├── command
│ ├── RunElastixCommand.java
│ └── RunTransformixCommand.java
├── explore
│ ├── ExploreSimpleElastix.txt
│ └── ExploreTmpDir.java
├── tests
│ ├── TestElastix.java
│ ├── TestElastixAndTransformixCLEM.java
│ └── TestTransformix.java
└── users
│ ├── rachel
│ └── RachelParapodRegistration.java
│ └── sultan
│ ├── TransformXRayDataUsingAmiraEulerTransform.java
│ └── TransformXRayUsingAmiraEulerViaElastix.java
└── resources
├── 2d-movie--affine--crop.tif
├── 2d-movie--affine.mhd
├── 2d-movie--affine.raw
├── 2d-movie--affine.tif
├── Thomas--Platynereis.tif
├── TransformParameters.45degreeEllispoid.txt
├── ellipsoid-voxels100x100x100-voxelSizes200x200x200nm.tif
├── test-data
├── big-warp-landmarks.csv
├── big-warp-transformations.rtf
├── clem
│ ├── aligned-ch0.tif
│ ├── aligned-ch1.tif
│ ├── em.tif
│ ├── fluo_green.tif
│ ├── fluo_red_green.tif
│ └── tmp
│ │ ├── IterationInfo.0.R0.txt
│ │ ├── TransformParameters.0.txt
│ │ ├── elastix.log
│ │ ├── elastix_parameters.txt
│ │ ├── fixed.mhd
│ │ ├── fixed.raw
│ │ ├── moving.mhd
│ │ ├── moving.raw
│ │ ├── result.mhd
│ │ ├── result.raw
│ │ ├── run_elastix.sh
│ │ ├── run_transformix.sh
│ │ ├── transformed-ch0.tif
│ │ └── transformix.log
├── fluo01
│ ├── ellipsoid-at45degrees-dxyz200nm.tif
│ ├── ellipsoid-horizontal-dxyz200nm.tif
│ ├── tmp
│ │ ├── IterationInfo.0.R0.txt
│ │ ├── TransformParameters.0.txt
│ │ ├── elastix.log
│ │ ├── elastix_parameters.txt
│ │ ├── fixed.mhd
│ │ ├── fixed.raw
│ │ ├── moving.mhd
│ │ ├── moving.raw
│ │ ├── result.mhd
│ │ ├── result.raw
│ │ ├── run_elastix.sh
│ │ ├── run_transformix.sh
│ │ ├── transformed-ch0.tif
│ │ └── transformix.log
│ └── transformed-ellipsoid-ch0.tif
├── sbem-mask.ome.tif
├── sbem-segmented-neuropil.ome.tif
├── sbem.mhd
├── sbem.ome.tif
├── sbem.raw
├── xray-manually-similarity-aligned.ome.tif
├── xray-segmented-neuropil-manually-similarity-aligned.ome.tif
├── xray-segmented-neuropil.ome.tif
└── xray.ome.tif
└── tmp
├── sbem-blur.mhd
└── sbem-blur.raw
/.checksums:
--------------------------------------------------------------------------------
1 | 85a88b5c5c846346199f7f09fe08a6e3bab2c1ba:d256f960a2605c110ec65c225b6722b0b89c4b14:32288ba3c9fde51b1f916a276f83bf2af8b14bbb 20180220164232 :2f9b1e2b053aa00d7e554395683a2d756946679c
2 | 0b095557d3ee56d758783082d14a52fd6bdc7fca:24eb890a5ed5236c8707dc84dc2621d73914935b:8903ed32c27ae9a609a2cba4f5412f910b97c307 20180220164232 :b20899aaeb931a97ac86191c54d9699323522e38
3 | 1fd62669e49002364fd38640987c25ad5f4aff4e:9a54a00d48e3ba6a87799624a278c19195360c90:d620b89a7610f315ca13c32e58a4f1254fbb0425 20180220164232 :bed7d55540558854c1ef3360aadfcf27e4b08bd7
4 | 48a00526957a5effd2296679457624684d687827:456a92c7a5f528a7769039f61469a77540bc01fe:8c3344b80d372784297876e19079b4aa155dc3a7 20180220164232 :d5e85b0e9a58948840f44f96d477644dfe8e1f3f
5 | b200bc477f25acdf61c319e309fa69ce74a813e2:8304409dabc2e0a8215414bf1021cec6dfc7ffa3:809c1f629987102c6c8df05fc7b697bf1e1d6825 20180220164232 :e9107a0e29092280640d2c76a7ff2429d62bf96b
6 | d574d99c35a605033f664a080aad208ad770d435 20180803150930 README.md
7 | 2f9b1e2b053aa00d7e554395683a2d756946679c 20180220164232 lib/imglib-2.0.0-beta61.jar
8 | bed7d55540558854c1ef3360aadfcf27e4b08bd7 20180220164232 lib/imglib-algorithms-2.0.0-beta6.jar
9 | b20899aaeb931a97ac86191c54d9699323522e38 20180220164232 lib/imglib-ij-2.0.0-beta6.jar
10 | d5e85b0e9a58948840f44f96d477644dfe8e1f3f 20180220164232 lib/jhdf5-14.12.0.jar
11 | e9107a0e29092280640d2c76a7ff2429d62bf96b 20180220164232 lib/mpicbg-1.0.1.jar
12 |
--------------------------------------------------------------------------------
/.github/build.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | curl -fsLO https://raw.githubusercontent.com/scijava/scijava-scripts/main/ci-build.sh
3 | sh ci-build.sh
4 |
--------------------------------------------------------------------------------
/.github/setup.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | curl -fsLO https://raw.githubusercontent.com/scijava/scijava-scripts/main/ci-setup-github-actions.sh
3 | sh ci-setup-github-actions.sh
4 |
--------------------------------------------------------------------------------
/.github/workflows/build-main.yml:
--------------------------------------------------------------------------------
1 | name: build
2 |
3 | on:
4 | push:
5 | branches:
6 | - master
7 | tags:
8 | - "*-[0-9]+.*"
9 |
10 | jobs:
11 | build:
12 | runs-on: ubuntu-latest
13 |
14 | steps:
15 | - uses: actions/checkout@v2
16 | - name: Cache local Maven repository
17 | uses: actions/cache@v2
18 | env:
19 | cache-name: cache-m2
20 | with:
21 | path: ~/.m2/repository
22 | key: ${{ runner.os }}-build-${{ env.cache-name }}
23 | restore-keys: |
24 | ${{ runner.os }}-build-${{ env.cache-name }}-
25 | ${{ runner.os }}-build-
26 | ${{ runner.os }}-
27 | - name: Set up Java
28 | uses: actions/setup-java@v2
29 | with:
30 | java-version: '8'
31 | distribution: 'zulu'
32 | - name: Set up CI environment
33 | run: .github/setup.sh
34 | - name: Execute the build
35 | run: .github/build.sh
36 | env:
37 | GPG_KEY_NAME: ${{ secrets.GPG_KEY_NAME }}
38 | GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
39 | MAVEN_USER: ${{ secrets.MAVEN_USER }}
40 | MAVEN_PASS: ${{ secrets.MAVEN_PASS }}
41 | OSSRH_PASS: ${{ secrets.OSSRH_PASS }}
42 | SIGNING_ASC: ${{ secrets.SIGNING_ASC }}
43 |
--------------------------------------------------------------------------------
/.github/workflows/build-pr.yml:
--------------------------------------------------------------------------------
1 | name: build PR
2 |
3 | on:
4 | pull_request:
5 | branches:
6 | - master
7 |
8 | jobs:
9 | build:
10 | runs-on: ubuntu-latest
11 |
12 | steps:
13 | - uses: actions/checkout@v2
14 | - name: Cache local Maven repository
15 | uses: actions/cache@v2
16 | env:
17 | cache-name: cache-m2
18 | with:
19 | path: ~/.m2/repository
20 | key: ${{ runner.os }}-build-${{ env.cache-name }}
21 | restore-keys: |
22 | ${{ runner.os }}-build-${{ env.cache-name }}-
23 | ${{ runner.os }}-build-
24 | ${{ runner.os }}-
25 | - name: Set up Java
26 | uses: actions/setup-java@v2
27 | with:
28 | java-version: '8'
29 | distribution: 'zulu'
30 | - name: Set up CI environment
31 | run: .github/setup.sh
32 | - name: Execute the build
33 | run: .github/build.sh
34 |
--------------------------------------------------------------------------------
/.github/workflows/build.yml:
--------------------------------------------------------------------------------
1 | name: build
2 |
3 | on:
4 | push:
5 | branches:
6 | - master
7 | tags:
8 | - "*-[0-9]+.*"
9 | pull_request:
10 | branches:
11 | - master
12 |
13 | jobs:
14 | build:
15 | runs-on: ubuntu-latest
16 |
17 | steps:
18 | - uses: actions/checkout@v2
19 | - name: Set up Java
20 | uses: actions/setup-java@v3
21 | with:
22 | java-version: '8'
23 | distribution: 'zulu'
24 | cache: 'maven'
25 | - name: Set up CI environment
26 | run: .github/setup.sh
27 | - name: Execute the build
28 | run: .github/build.sh
29 | env:
30 | GPG_KEY_NAME: ${{ secrets.GPG_KEY_NAME }}
31 | GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
32 | MAVEN_USER: ${{ secrets.MAVEN_USER }}
33 | MAVEN_PASS: ${{ secrets.MAVEN_PASS }}
34 | OSSRH_USER: ${{ secrets.OSSRH_USER }}
35 | OSSRH_PASS: ${{ secrets.OSSRH_PASS }}
36 | SIGNING_ASC: ${{ secrets.SIGNING_ASC }}
37 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | /.classpath
2 | /.project
3 | /.idea
4 | /.settings/
5 | /target/
6 | /lib
7 | *.iml
8 | .DS_Store
9 |
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 | Copyright (c) 2017 - 2025, EMBL
2 | All rights reserved.
3 |
4 | Redistribution and use in source and binary forms, with or without modification,
5 | are permitted provided that the following conditions are met:
6 |
7 | 1. Redistributions of source code must retain the above copyright notice, this
8 | list of conditions and the following disclaimer.
9 |
10 | 2. Redistributions in binary form must reproduce the above copyright notice,
11 | this list of conditions and the following disclaimer in the documentation
12 | and/or other materials provided with the distribution.
13 |
14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
18 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24 | POSSIBILITY OF SUCH DAMAGE.
25 |
--------------------------------------------------------------------------------
/docs/PlatybrowserTransforms.md:
--------------------------------------------------------------------------------
1 | # Instructions how to transform files for MMPB
2 |
3 | - Login to the cluster login node.
4 |
5 | - Generate a text file (job script) with below content (modifying the export statements as described below ).
6 |
7 | ```
8 | #!/bin/bash
9 |
10 | export WORKING_DIR="/tmp/elastix"
11 | export TRAFO="/g/cba/exchange/platy-trafos/linear/TransformParameters.BSpline10-3Channels.0.txt"
12 | export OUT="/g/cba/cluster/tischer/elastix-job-000.out"
13 | export ERR="/g/cba/cluster/tischer/elastix-job-000.err"
14 | export INPUT_IMAGE="/g/cba/tischer/tmp/ProSPr6_Ref.tif"
15 | export OUTPUT_IMAGE="/g/arendt/EM_6dpf_segmentation/EM-Prospr/ProSPr6_Ref-SPM.xml"
16 |
17 | srun --mem 16000 -n 1 -N 1 -c 8 -t 30:00 -o $OUT -e $ERR mkdir -p $WORKING_DIR; /g/almf/software/Fiji.app/ImageJ-linux64 --ij2 --headless --run "Transformix" "elastixDirectory='/g/almf/software/elastix_v4.8', workingDirectory='$WORKING_DIR', inputImageFile='$INPUT_IMAGE',transformationFile='$TRAFO',outputFile='$OUTPUT_IMAGE',outputModality='Save as BigDataViewer .xml/.h5',numThreads='1'"
18 | ```
19 |
20 | - Save this file, e.g. with the name `transformix.job`.
21 | - Submit the file as a job: `sbatch transformix.job`
22 |
23 |
24 | The `export` statements have to be adapted for your gene and user.
25 |
26 | - TRAFO
27 | - the transformation to be used
28 | - SPMs: /g/cba/exchange/platy-trafos/linear/TransformParameters.BSpline10-3Channels.0.txt
29 | - uses linear interpolation
30 | - MEDs: /g/cba/exchange/platy-trafos/nn/TransformParameters.BSpline10-3Channels.0.txt
31 | - ueses nearest neighbor interpolation
32 | - OUT
33 | - text output
34 | - use: some file where you have write access
35 | - ERR
36 | - text output of errors
37 | - use: some file where you have write access
38 | - INPUT_IMAGE
39 | - the input image, make sure that the **calibration is correct**, otherwise the transformation will fail!
40 | - OUTPUT_IMAGE
41 | - the output image, must be in folder `/g/arendt/EM_6dpf_segmentation/EM-Prospr/`
42 | - MEDs: must end with -MED.xml
43 | - SPMs: must enfd with -SPM.xml
44 |
45 | ## Alternative
46 |
47 | ## Notes
48 |
49 | - Faster transformation for testing: `TransformParameters.Similarity-3Channels.0.txt`
50 |
51 | ## Issues
52 |
53 | - I did not manage yet to specify a cluster job specific tmp dir. I tried using $TMPDIR, but it did not work. Like this, jobs running on the same node will screw up each other.
54 |
--------------------------------------------------------------------------------
/docs/TransformParameters.0.txt:
--------------------------------------------------------------------------------
1 | (Transform "EulerTransform")
2 | (NumberOfParameters 6)
3 | (TransformParameters -0.000024 -0.000005 -0.000027 0.008708 -0.003337 0.000825)
4 | (InitialTransformParametersFileName "NoInitialTransform")
5 | (UseBinaryFormatForTransformationParameters "false")
6 | (HowToCombineTransforms "Compose")
7 |
8 | // Image specific
9 | (FixedImageDimension 3)
10 | (MovingImageDimension 3)
11 | (FixedInternalImagePixelType "float")
12 | (MovingInternalImagePixelType "float")
13 | (Size 275 259 286)
14 | (Index 0 0 0)
15 | (Spacing 1.0000000000 1.0000000000 1.0000000000)
16 | (Origin 0.0000000000 0.0000000000 0.0000000000)
17 | (Direction 1.0000000000 0.0000000000 0.0000000000 0.0000000000 1.0000000000 0.0000000000 0.0000000000 0.0000000000 1.0000000000)
18 | (UseDirectionCosines "true")
19 |
20 | // EulerTransform specific
21 | (CenterOfRotationPoint 137.0000000000 129.0000000000 142.5000000000)
22 | (ComputeZYX "false")
23 |
24 | // ResampleInterpolator specific
25 | (ResampleInterpolator "FinalBSplineInterpolator")
26 | (FinalBSplineInterpolationOrder 3)
27 |
28 | // Resampler specific
29 | (Resampler "DefaultResampler")
30 | (DefaultPixelValue 0.000000)
31 | (ResultImageFormat "nii")
32 | (ResultImagePixelType "float")
33 | (CompressResultImage "false")
34 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 4.0.0
4 |
5 | org.scijava
6 | pom-scijava
7 | 40.0.0
8 |
9 |
10 |
11 |
12 |
13 |
14 | de.embl.cba
15 | elastix-wrapper
16 | 0.6.1-SNAPSHOT
17 | Fiji plugin for image registration using elastix
18 | A Fiji plugin for image registration using elastix.
19 | https://github.com/embl-cba/elastixWrapper
20 | 2017
21 |
22 | EMBL
23 | https://embl.de/
24 |
25 |
26 |
27 | tischi
28 | Christian Tischer
29 | Christian.Tischer@EMBL.DE
30 |
31 | EMBL Heidelberg
32 | http://www.embl.de
33 |
34 | founder
35 | lead
36 | developer
37 |
38 | +1
39 |
40 |
41 |
42 |
43 | None
44 |
45 |
46 |
47 |
48 | Simplified BSD License
49 | repo
50 |
51 |
52 |
53 |
54 | ImageJ Forum
55 | https://forum.image.sc/
56 |
57 |
58 |
59 | scm:git:https://github.com/embl-cba/elastix-wrapper
60 | scm:git:git@github.com:embl-cba/elastix-wrapper
61 | HEAD
62 | https://github.com/embl-cba/elastix-wrapper
63 |
64 |
65 | de.embl.cba.elastix
66 | bsd_2
67 | EMBL
68 | /Applications/Fiji.app/
69 | Fiji distribution of ImageJ for the life sciences.
70 |
71 | 0.2.0
72 | 1.0.3
73 |
74 |
75 | sign,deploy-to-scijava
76 |
77 |
78 | GitHub
79 | https://github.com/embl-cba/elastix-wrapper/issues
80 |
81 |
82 | GitHub Actions
83 | https://github.com/embl-cba/elastix-wrapper/actions
84 |
85 |
86 |
87 |
88 | maven-jar-plugin
89 |
90 |
91 |
92 | ${main-class}
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 | scijava.public
102 | https://maven.scijava.org/content/groups/public
103 |
104 |
105 |
106 |
107 | org.itc
108 | image-transform-converters
109 | ${image-transform-converters.version}
110 |
111 |
112 | de.embl.cba
113 | metaimage-io
114 | ${metaimage-io.version}
115 |
116 |
117 | sc.fiji
118 | bigdataviewer_fiji
119 |
120 |
121 | junit
122 | junit
123 | test
124 |
125 |
126 |
127 |
--------------------------------------------------------------------------------
/scripts/run_elastix.groovy:
--------------------------------------------------------------------------------
1 | /**
2 | * Open this script in Fiji and click [ Run ]
3 | *
4 | * Open [ Window > Console ] to see the log
5 | *
6 | */
7 |
8 | import bdv.util.Bdv;
9 | import de.embl.cba.elastix.wrapper.elastix.ElastixWrapperSettings;
10 | import de.embl.cba.elastix.wrapper.elastix.ElastixWrapper;
11 | import net.imagej.ImageJ;
12 |
13 |
14 | ElastixWrapperSettings settings = new ElastixWrapperSettings();
15 |
16 | final ImageJ ij = new ImageJ();
17 | settings.logService = ij.log();
18 | settings.elastixDirectory = "/Applications/elastix_macosx64_v4.8" ;
19 | settings.tmpDir = "/Users/tischer/Desktop/elastix-tmp";
20 | settings.fixedImageFilePath = "/g/arendt/EM_6dpf_segmentation/platy-fibsem-datasets/registration/examples/fixed-image-sbem-seg-ganglion.tif";
21 | settings.movingImageFilePath = "/g/arendt/EM_6dpf_segmentation/platy-fibsem-datasets/registration/examples/moving-image-sbem-seg-ganglion.tif";
22 | settings.fixedMaskPath = "/g/arendt/EM_6dpf_segmentation/platy-fibsem-datasets/registration/examples/fixed-image-mask.tif";
23 | settings.initialTransformationFilePath = "g/arendt/EM_6dpf_segmentation/platy-fibsem-datasets/registration/examples/amira-transform.txt";
24 | settings.transformationType = ElastixWrapperSettings.AFFINE;
25 | settings.downSamplingFactors = "10 10 10; 2, 2, 2";
26 | // settings.movingMaskPath = "";
27 | // settings.bSplineGridSpacing = "50 50 50";
28 | settings.iterations = 1; // Set to 1000
29 | settings.spatialSamples = "10000; 10000";
30 | settings.channelWeights = [1.0, 1.0, 3.0, 1.0, 1.0]; // not used in this example
31 | // settings.finalResampler = ElastixSettings.FINAL_RESAMPLER_LINEAR;
32 |
33 | final ElastixWrapper elastixWrapper = new ElastixWrapper( settings );
34 | elastixWrapper.runElastix();
35 |
36 | final Bdv bdv = elastixWrapper.reviewResults();
37 | //bdv.close();
38 | settings.logService.info( "Done!" );
39 |
--------------------------------------------------------------------------------
/src/main/java/de/embl/cba/elastix/commandline/ElastixCaller.java:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * Fiji distribution of ImageJ for the life sciences.
4 | * %%
5 | * Copyright (C) 2017 - 2025 EMBL
6 | * %%
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are met:
9 | *
10 | * 1. Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * 2. Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | * POSSIBILITY OF SUCH DAMAGE.
27 | * #L%
28 | */
29 | package de.embl.cba.elastix.commandline;
30 |
31 | import de.embl.cba.elastix.commandline.settings.ElastixSettings;
32 | import de.embl.cba.elastix.utils.Utils;
33 |
34 | import java.util.ArrayList;
35 | import java.util.List;
36 |
37 | public class ElastixCaller {
38 |
39 | public static final String ELASTIX = "elastix";
40 | public static final String FIXED = "f";
41 | public static final String MOVING = "m";
42 |
43 | ElastixSettings settings;
44 | String executableShellScript;
45 |
46 | public ElastixCaller( ElastixSettings settings ) {
47 | this.settings = settings;
48 | executableShellScript = new ExecutableShellScriptCreator( ELASTIX, settings ).createExecutableShellScript();
49 | }
50 |
51 | public void callElastix()
52 | {
53 | settings.logService.info( "Running elastix... (please wait)" );
54 |
55 | List< String > args = createElastixCallArgs();
56 |
57 | Utils.executeCommand( args, settings.logService );
58 |
59 | settings.logService.info( "...done!" );
60 | }
61 |
62 | private List< String > createElastixCallArgs( )
63 | {
64 | List args = new ArrayList<>();
65 | args.add( executableShellScript );
66 | args.add( "-out" );
67 | args.add( settings.tmpDir );
68 |
69 | addImagesAndMasksToArguments( args );
70 |
71 | args.add( "-p" );
72 | args.add( settings.parameterFilePath );
73 | args.add( "-threads" );
74 | args.add( "" + settings.numWorkers );
75 |
76 | if ( settings.initialTransformationFilePath != null && !settings.initialTransformationFilePath.equals( "" ) )
77 | {
78 | args.add( "-t0" );
79 | args.add( settings.initialTransformationFilePath );
80 | }
81 |
82 | return args;
83 | }
84 |
85 | private void addImagesAndMasksToArguments( List< String > args )
86 | {
87 | addImagesToArguments( args, FIXED, settings.fixedImageFilePaths );
88 |
89 | addImagesToArguments( args, MOVING, settings.movingImageFilePaths );
90 |
91 | if ( settings.fixedMaskFilePaths != null )
92 | addImagesToArguments( args, "fMask", settings.fixedMaskFilePaths );
93 |
94 | if ( settings.movingMaskFilePaths != null )
95 | addImagesToArguments( args, "mMask", settings.movingMaskFilePaths );
96 | }
97 |
98 | private void addImagesToArguments( List< String > args,
99 | String fixedOrMoving,
100 | ArrayList< String > filePaths )
101 | {
102 | int elastixChannelIndex = 0;
103 | for ( String filePath : filePaths ) {
104 | if (filePaths.size() == 1)
105 | args.add("-" + fixedOrMoving);
106 | else
107 | args.add("-" + fixedOrMoving + elastixChannelIndex);
108 |
109 | args.add(filePath);
110 |
111 | elastixChannelIndex++;
112 | }
113 | }
114 |
115 |
116 |
117 | }
118 |
--------------------------------------------------------------------------------
/src/main/java/de/embl/cba/elastix/commandline/ExecutableShellScriptCreator.java:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * Fiji distribution of ImageJ for the life sciences.
4 | * %%
5 | * Copyright (C) 2017 - 2025 EMBL
6 | * %%
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are met:
9 | *
10 | * 1. Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * 2. Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | * POSSIBILITY OF SUCH DAMAGE.
27 | * #L%
28 | */
29 | package de.embl.cba.elastix.commandline;
30 |
31 | import de.embl.cba.elastix.commandline.settings.Settings;
32 | import de.embl.cba.elastix.utils.Utils;
33 | import ij.IJ;
34 |
35 | import java.io.File;
36 | import java.io.IOException;
37 | import java.util.Map;
38 |
39 | import static de.embl.cba.elastix.utils.Utils.saveStringToFile;
40 | import static org.scijava.util.PlatformUtils.*;
41 |
42 | public class ExecutableShellScriptCreator {
43 |
44 | String elastixOrTransformix;
45 | Settings settings;
46 |
47 | public ExecutableShellScriptCreator( String elastixOrTransformix, Settings settings) {
48 | this.elastixOrTransformix = elastixOrTransformix;
49 | this.settings = settings;
50 | }
51 |
52 | public String createExecutableShellScript()
53 | {
54 | if ( isMac() || isLinux() )
55 | {
56 | String executablePath = settings.tmpDir
57 | + File.separator + "run_" + elastixOrTransformix + ".sh";
58 |
59 | String binaryPath = settings.elastixDirectory + File.separator + "bin" + File.separator + elastixOrTransformix;
60 |
61 | if( ! new File( binaryPath ).exists() )
62 | Utils.logErrorAndExit( settings, "Elastix file does not exist: " + binaryPath );
63 |
64 | String shellScriptText = getScriptText();
65 |
66 | saveStringToFile( shellScriptText, executablePath );
67 |
68 | makeExecutable( executablePath );
69 |
70 | return executablePath;
71 |
72 | }
73 | else if ( isWindows() )
74 | {
75 | setElastixSystemPathForWindowsOS();
76 |
77 | String binaryPath = settings.elastixDirectory + File.separator + elastixOrTransformix + ".exe";
78 |
79 | if ( ! new File( binaryPath ).exists() )
80 | Utils.logErrorAndExit( settings, "Elastix file does not exist: " + binaryPath );
81 |
82 | return binaryPath;
83 | }
84 | else
85 | {
86 | Utils.logErrorAndExit( settings, "Could not detect operating system!" );
87 | return null;
88 | }
89 |
90 | }
91 |
92 | private String getScriptText()
93 | {
94 | String shellScriptText = "";
95 | shellScriptText += "#!/bin/bash\n";
96 | shellScriptText += "ELASTIX_PATH=" + settings.elastixDirectory + "\n";
97 |
98 | if ( isMac() )
99 | {
100 | shellScriptText += "export DYLD_LIBRARY_PATH=$ELASTIX_PATH/lib/\n";
101 | }
102 | else if ( isLinux() )
103 | {
104 | shellScriptText += "export LD_LIBRARY_PATH=$ELASTIX_PATH/lib/\n";
105 | }
106 |
107 | shellScriptText += "$ELASTIX_PATH/bin/" + elastixOrTransformix +" $@\n";
108 | return shellScriptText;
109 | }
110 |
111 | private void setElastixSystemPathForWindowsOS()
112 | {
113 | ProcessBuilder pb = new ProcessBuilder();
114 | Map env = pb.environment();
115 | env.put( "PATH", settings.elastixDirectory + ":$PATH");
116 | }
117 |
118 | private void makeExecutable( String executablePath )
119 | {
120 | try
121 | {
122 | Utils.waitOneSecond();
123 | Runtime.getRuntime().exec("chmod +x " + executablePath );
124 | Utils.waitOneSecond();
125 | }
126 | catch ( IOException e )
127 | {
128 | IJ.log( "Could not make file executable: " + executablePath );
129 | e.printStackTrace();
130 | }
131 | }
132 | }
133 |
--------------------------------------------------------------------------------
/src/main/java/de/embl/cba/elastix/commandline/TransformixCaller.java:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * Fiji distribution of ImageJ for the life sciences.
4 | * %%
5 | * Copyright (C) 2017 - 2025 EMBL
6 | * %%
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are met:
9 | *
10 | * 1. Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * 2. Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | * POSSIBILITY OF SUCH DAMAGE.
27 | * #L%
28 | */
29 | package de.embl.cba.elastix.commandline;
30 |
31 | import de.embl.cba.elastix.commandline.settings.TransformixSettings;
32 | import de.embl.cba.elastix.utils.Utils;
33 |
34 | import java.util.ArrayList;
35 | import java.util.List;
36 |
37 | public class TransformixCaller {
38 |
39 | public static final String TRANSFORMIX = "transformix";
40 | TransformixSettings settings;
41 | String executableShellScript;
42 |
43 | public TransformixCaller( TransformixSettings settings ) {
44 | this.settings = settings;
45 | executableShellScript = new ExecutableShellScriptCreator( TRANSFORMIX, settings ).createExecutableShellScript();
46 | }
47 |
48 | public void callTransformix()
49 | {
50 | settings.logService.info( "Running transformix... (please wait)" );
51 |
52 | List< String > args = createTransformixCallArgs();
53 |
54 | Utils.executeCommand( args, settings.logService );
55 |
56 | settings.logService.info( "...done!" );
57 | }
58 |
59 | private List< String > createTransformixCallArgs()
60 | {
61 |
62 | List args = new ArrayList<>();
63 | args.add( executableShellScript );
64 | args.add( "-out" );
65 | args.add( settings.tmpDir );
66 | args.add( "-in" );
67 | args.add( settings.movingImageFilePath );
68 | args.add( "-tp" );
69 | args.add( settings.transformationFilePath );
70 | args.add( "-threads" );
71 | args.add( "" + settings.numWorkers );
72 |
73 | return args;
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/src/main/java/de/embl/cba/elastix/commandline/settings/ElastixSettings.java:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * Fiji distribution of ImageJ for the life sciences.
4 | * %%
5 | * Copyright (C) 2017 - 2025 EMBL
6 | * %%
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are met:
9 | *
10 | * 1. Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * 2. Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | * POSSIBILITY OF SUCH DAMAGE.
27 | * #L%
28 | */
29 | package de.embl.cba.elastix.commandline.settings;
30 |
31 | import de.embl.cba.elastix.wrapper.elastix.ElastixWrapperSettings;
32 |
33 | import java.util.ArrayList;
34 |
35 | public class ElastixSettings extends Settings {
36 |
37 | public String parameterFilePath;
38 | public String initialTransformationFilePath;
39 | // if size >1 will do multi-image registration
40 | // Order of fixed, moving and masks must be the same
41 | public ArrayList fixedImageFilePaths;
42 | public ArrayList movingImageFilePaths;
43 | public ArrayList fixedMaskFilePaths;
44 | public ArrayList movingMaskFilePaths;
45 |
46 | public ElastixSettings() {}
47 |
48 | public ElastixSettings( ElastixWrapperSettings settings ) {
49 | logService = settings.logService;
50 | elastixDirectory = settings.elastixDirectory;
51 | tmpDir = settings.tmpDir;
52 | numWorkers = settings.numWorkers;
53 | headless = settings.headless;
54 | parameterFilePath = settings.parameterFilePath;
55 | initialTransformationFilePath = settings.initialTransformationFilePath;
56 |
57 | fixedImageFilePaths = new ArrayList<>();
58 | fixedMaskFilePaths = new ArrayList<>();
59 | movingImageFilePaths = new ArrayList<>();
60 | movingMaskFilePaths = new ArrayList<>();
61 |
62 | for ( int fixedChannelIndex : settings.fixedToMovingChannel.keySet() ) {
63 | int movingChannelIndex = settings.fixedToMovingChannel.get(fixedChannelIndex);
64 | fixedImageFilePaths.add( settings.stagedFixedImageFilePaths.get(fixedChannelIndex) );
65 | if (settings.stagedFixedMaskFilePaths != null ) {
66 | fixedMaskFilePaths.add(settings.stagedFixedMaskFilePaths.get(fixedChannelIndex));
67 | }
68 | movingImageFilePaths.add( settings.stagedMovingImageFilePaths.get(movingChannelIndex) );
69 | if ( settings.stagedMovingMaskFilePaths != null ) {
70 | movingMaskFilePaths.add(settings.stagedMovingMaskFilePaths.get(movingChannelIndex));
71 | }
72 | }
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/src/main/java/de/embl/cba/elastix/commandline/settings/Settings.java:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * Fiji distribution of ImageJ for the life sciences.
4 | * %%
5 | * Copyright (C) 2017 - 2025 EMBL
6 | * %%
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are met:
9 | *
10 | * 1. Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * 2. Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | * POSSIBILITY OF SUCH DAMAGE.
27 | * #L%
28 | */
29 | package de.embl.cba.elastix.commandline.settings;
30 |
31 | import org.scijava.log.LogService;
32 |
33 | public class Settings {
34 | public LogService logService;
35 | public String elastixDirectory = "/Users/tischi/Downloads/elastix_macosx64_v4.8/";
36 | public String tmpDir;
37 | public int numWorkers = Runtime.getRuntime().availableProcessors();
38 | public boolean headless = false;
39 | }
40 |
--------------------------------------------------------------------------------
/src/main/java/de/embl/cba/elastix/commandline/settings/TransformixSettings.java:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * Fiji distribution of ImageJ for the life sciences.
4 | * %%
5 | * Copyright (C) 2017 - 2025 EMBL
6 | * %%
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are met:
9 | *
10 | * 1. Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * 2. Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | * POSSIBILITY OF SUCH DAMAGE.
27 | * #L%
28 | */
29 | package de.embl.cba.elastix.commandline.settings;
30 |
31 | import de.embl.cba.elastix.wrapper.transformix.TransformixWrapperSettings;
32 |
33 | public class TransformixSettings extends Settings {
34 | public String transformationFilePath;
35 | public String movingImageFilePath;
36 |
37 | public TransformixSettings() {}
38 |
39 | public TransformixSettings( TransformixWrapperSettings settings, int movingFileIndex ) {
40 | logService = settings.logService;
41 | elastixDirectory = settings.elastixDirectory;
42 | tmpDir = settings.tmpDir;
43 | numWorkers = settings.numWorkers;
44 | headless = settings.headless;
45 | transformationFilePath = settings.transformationFilePath;
46 | movingImageFilePath = settings.stagedMovingImageFilePaths.get( movingFileIndex );
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/src/main/java/de/embl/cba/elastix/commands/ElastixCommand.java:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * Fiji distribution of ImageJ for the life sciences.
4 | * %%
5 | * Copyright (C) 2017 - 2025 EMBL
6 | * %%
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are met:
9 | *
10 | * 1. Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * 2. Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | * POSSIBILITY OF SUCH DAMAGE.
27 | * #L%
28 | */
29 | package de.embl.cba.elastix.commands;
30 |
31 | import de.embl.cba.elastix.wrapper.elastix.parameters.DefaultElastixParametersCreator.ParameterStyle;
32 | import de.embl.cba.elastix.wrapper.elastix.ElastixWrapper;
33 | import de.embl.cba.elastix.wrapper.elastix.ElastixWrapperSettings;
34 | import de.embl.cba.elastix.utils.Utils;
35 | import de.embl.cba.elastix.wrapper.elastix.parameters.ElastixParameters;
36 | import de.embl.cba.elastix.wrapper.elastix.parameters.ElastixParameters.TransformationType;
37 | import ij.Prefs;
38 | import ij.gui.GenericDialog;
39 | import org.scijava.Context;
40 | import org.scijava.command.Command;
41 | import org.scijava.log.LogService;
42 | import org.scijava.plugin.Parameter;
43 | import org.scijava.plugin.Plugin;
44 | import org.scijava.ui.UIService;
45 |
46 | import java.io.File;
47 |
48 | @Plugin(type = Command.class, menuPath = "Plugins>Registration>Elastix>Elastix" )
49 | public class ElastixCommand implements Command
50 | {
51 | public static final String NONE = "None";
52 | public static final String SHOW_OUTPUT_IN_IMAGEJ1 = "Show output in ImageJ1";
53 | public static final String SHOW_OUTPUT_IN_BDV = "Show output in Bdv";
54 | public static final String SAVE_TRANSFORMED_AS_TIFF = "Save transformed images in working directory as Tiff";
55 |
56 | public static final String PARAMETERS_DEFAULT = "Default";
57 | public static final String PARAMETERS_CLEM = "CLEM";
58 |
59 | @Parameter( label = "Elastix installation directory", style = "directory" )
60 | public File elastixDirectory;
61 |
62 | @Parameter( label = "Temporary directory for intermediate files", style = "directory" )
63 | public File tmpDir = new File( System.getProperty("java.io.tmpdir") );
64 |
65 | @Parameter( label = "Fixed image" )
66 | public File fixedImageFile;
67 |
68 | @Parameter( label = "Moving image" )
69 | public File movingImageFile;
70 |
71 | @Parameter( label = "Transformation type", choices = {
72 | ElastixParameters.TRANSLATION,
73 | ElastixParameters.EULER,
74 | ElastixParameters.SIMILARITY,
75 | ElastixParameters.AFFINE,
76 | ElastixParameters.SPLINE } )
77 | public String transformationType;
78 |
79 | @Parameter( label = "Grid spacing for BSpline transformation [voxels]", required = false )
80 | public String bSplineGridSpacing = "50,50,50";
81 |
82 | @Parameter( label = "Number of iterations" )
83 | public int numIterations = 1000;
84 |
85 | @Parameter( label = "Number of spatial samples" )
86 | public String numSpatialSamples = "10000";
87 |
88 | @Parameter( label = "Gaussian smoothing sigma [voxels]" )
89 | public String gaussianSmoothingSigmas = "10,10,10";
90 |
91 | @Parameter( label = "Transformation output file", style = "save" )
92 | public File transformationOutputFile;
93 |
94 | @Parameter( label = "Image output modality",
95 | choices = {
96 | NONE,
97 | SHOW_OUTPUT_IN_IMAGEJ1,
98 | SAVE_TRANSFORMED_AS_TIFF
99 | } )
100 | public String outputModality;
101 |
102 | @Parameter( label = "Use fixed image mask" )
103 | public boolean useFixedMask;
104 |
105 | @Parameter( label = "Fixed image mask file", required = false )
106 | public File fixedMaskFile;
107 |
108 | @Parameter( label = "Use moving image mask" )
109 | public boolean useMovingMask;
110 |
111 | @Parameter( label = "Moving image mask file", required = false )
112 | public File movingMaskFile;
113 |
114 | @Parameter( label = "Use initial transformation" )
115 | public boolean useInitialTransformation;
116 |
117 | @Parameter( label = "Initial transformation file", required = false )
118 | public File initialTransformationFile;
119 |
120 | @Parameter( label = "Elastix parameters", choices =
121 | {
122 | PARAMETERS_DEFAULT,
123 | PARAMETERS_CLEM
124 | })
125 | public String elastixParameters = PARAMETERS_DEFAULT;
126 |
127 | @Parameter( label = "Final resampler",
128 | choices = {
129 | ElastixParameters.FINAL_RESAMPLER_LINEAR,
130 | ElastixParameters.FINAL_RESAMPLER_NEAREST_NEIGHBOR
131 | } )
132 | public String finalResampler = ElastixParameters.FINAL_RESAMPLER_LINEAR;
133 |
134 | @Parameter( label = "Weights for multi channel images" )
135 | public String multiChannelWeights = "1.0,3.0,1.0,1.0,1.0,1.0";
136 |
137 | @Parameter
138 | public LogService logService;
139 |
140 | @Parameter
141 | public UIService uiService;
142 |
143 | @Parameter
144 | public Context context;
145 |
146 | private ElastixWrapper elastixWrapper;
147 |
148 | public void run()
149 | {
150 | runElastix();
151 | }
152 |
153 | private void runElastix( )
154 | {
155 | ElastixWrapperSettings settings = getElastixSettings();
156 |
157 | if ( settings == null ) return;
158 |
159 | elastixWrapper = new ElastixWrapper( settings );
160 |
161 | elastixWrapper.runElastix();
162 |
163 | settings.logService.info( "Handling elastix output...." );
164 |
165 | elastixWrapper.saveTransformationFile();
166 |
167 | if ( outputModality.equals( SHOW_OUTPUT_IN_BDV ))
168 | {
169 | elastixWrapper.reviewResults();
170 | }
171 | else if ( outputModality.equals( SHOW_OUTPUT_IN_IMAGEJ1 ))
172 | {
173 | elastixWrapper.reviewResultsInImageJ();
174 | }
175 | else if ( outputModality.equals( SAVE_TRANSFORMED_AS_TIFF ) )
176 | {
177 | elastixWrapper.createTransformedImagesAndSaveAsTiff();
178 | }
179 |
180 | settings.logService.info( "...done!" );
181 | }
182 |
183 | private ElastixWrapperSettings getElastixSettings()
184 | {
185 | ElastixWrapperSettings settings = new ElastixWrapperSettings();
186 |
187 | settings.headless = uiService.isHeadless();
188 | settings.logService = logService;
189 | settings.elastixDirectory = elastixDirectory.toString();
190 |
191 | if ( ! new File( settings.elastixDirectory ).exists() )
192 | Utils.logErrorAndExit( settings, "The elastix directory does not exist: " + settings.elastixDirectory );
193 |
194 | settings.tmpDir = tmpDir.toString();
195 |
196 | if ( useInitialTransformation )
197 | settings.initialTransformationFilePath = initialTransformationFile.toString();
198 | else
199 | settings.initialTransformationFilePath = "";
200 |
201 | if ( useFixedMask )
202 | settings.fixedMaskPath = fixedMaskFile.toString();
203 | else
204 | settings.fixedMaskPath = "";
205 |
206 | if ( useMovingMask )
207 | settings.movingMaskPath = movingMaskFile.toString();
208 | else
209 | settings.movingMaskPath = "";
210 |
211 | settings.fixedImageFilePath = fixedImageFile.toString();
212 | settings.movingImageFilePath = movingImageFile.toString();
213 |
214 | settings.numWorkers = Prefs.getThreads();
215 |
216 | switch (transformationType) {
217 | case ElastixParameters.TRANSLATION:
218 | settings.transformationType = TransformationType.Translation;
219 | break;
220 | case ElastixParameters.EULER:
221 | settings.transformationType = TransformationType.Euler;
222 | break;
223 | case ElastixParameters.SIMILARITY:
224 | settings.transformationType = TransformationType.Similarity;
225 | break;
226 | case ElastixParameters.AFFINE:
227 | settings.transformationType = TransformationType.Affine;
228 | break;
229 | case ElastixParameters.SPLINE:
230 | settings.transformationType = TransformationType.BSpline;
231 | break;
232 | }
233 |
234 | if ( elastixParameters.equals(PARAMETERS_DEFAULT) ) {
235 | settings.elastixParametersStyle = ParameterStyle.Default;
236 | } else if ( elastixParameters.equals(PARAMETERS_CLEM) ) {
237 | settings.elastixParametersStyle = ParameterStyle.CLEM;
238 | }
239 |
240 | settings.iterations = numIterations;
241 | settings.spatialSamples = numSpatialSamples;
242 | settings.downSamplingFactors = gaussianSmoothingSigmas;
243 | settings.bSplineGridSpacing = bSplineGridSpacing;
244 | settings.finalResampler = finalResampler;
245 | settings.channelWeights = Utils.delimitedStringToDoubleArray( multiChannelWeights, "," );
246 |
247 | if ( transformationOutputFile.exists() )
248 | {
249 | GenericDialog gd = new GenericDialog("File exists");
250 | gd.addMessage("The transformation output file exists: " + transformationOutputFile.getAbsolutePath());
251 | gd.enableYesNoCancel("Overwrite", "Exit");
252 | gd.showDialog();
253 |
254 | if (gd.wasCanceled())
255 | {
256 | return null;
257 | }
258 | else if (gd.wasOKed())
259 | {
260 | //
261 | }
262 | else
263 | return null;
264 | }
265 |
266 | settings.transformationOutputFilePath = transformationOutputFile.getAbsolutePath();
267 |
268 | return settings;
269 | }
270 |
271 | }
272 |
273 |
--------------------------------------------------------------------------------
/src/main/java/de/embl/cba/elastix/commands/TransformixCommand.java:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * Fiji distribution of ImageJ for the life sciences.
4 | * %%
5 | * Copyright (C) 2017 - 2025 EMBL
6 | * %%
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are met:
9 | *
10 | * 1. Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * 2. Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | * POSSIBILITY OF SUCH DAMAGE.
27 | * #L%
28 | */
29 | package de.embl.cba.elastix.commands;
30 |
31 | import de.embl.cba.elastix.wrapper.transformix.TransformixWrapperSettings;
32 | import de.embl.cba.elastix.wrapper.transformix.TransformixWrapperSettings.OutputModality;
33 | import de.embl.cba.elastix.utils.Utils;
34 | import de.embl.cba.elastix.wrapper.transformix.TransformixWrapper;
35 | import org.scijava.command.Command;
36 | import org.scijava.log.LogService;
37 | import org.scijava.plugin.Parameter;
38 | import org.scijava.plugin.Plugin;
39 |
40 | import java.io.File;
41 |
42 | @Plugin(type = Command.class, menuPath = "Plugins>Registration>Elastix>Transformix" )
43 | public class TransformixCommand implements Command
44 | {
45 |
46 | @Parameter
47 | public LogService logService;
48 |
49 | @Parameter( label = "Elastix installation directory",
50 | style = "directory" )
51 | public File elastixDirectory;
52 |
53 | @Parameter( label = "Temporary directory for intermediate files", style = "directory" )
54 | public File tmpDir = new File( System.getProperty("java.io.tmpdir") );
55 |
56 | @Parameter( label = "Image" )
57 | public File inputImageFile;
58 |
59 | @Parameter( label = "Transformation" )
60 | public File transformationFile;
61 |
62 | @Parameter( label = "Output modality", choices = {
63 | TransformixWrapperSettings.OUTPUT_MODALITY_SHOW_IMAGES,
64 | TransformixWrapperSettings.OUTPUT_MODALITY_SAVE_AS_TIFF,
65 | TransformixWrapperSettings.OUTPUT_MODALITY_SAVE_AS_BDV
66 | } )
67 | public String outputModality;
68 |
69 | @Parameter( label = "Output file", style = "save", required = false )
70 | public File outputFile;
71 |
72 | @Parameter( label = "Number of threads" )
73 | int numThreads = 1;
74 |
75 | public void run()
76 | {
77 | runTransformix();
78 | }
79 |
80 | private void runTransformix()
81 | {
82 | TransformixWrapperSettings settings = getSettingsFromUI();
83 | TransformixWrapper transformixWrapper = new TransformixWrapper( settings );
84 | transformixWrapper.runTransformix();
85 | }
86 |
87 | private TransformixWrapperSettings getSettingsFromUI()
88 | {
89 | TransformixWrapperSettings settings = new TransformixWrapperSettings();
90 | settings.logService = logService;
91 | settings.elastixDirectory = elastixDirectory.toString();
92 | settings.tmpDir = tmpDir.toString();
93 | settings.movingImageFilePath = inputImageFile.toString();
94 | settings.transformationFilePath = transformationFile.toString();
95 | settings.numWorkers = numThreads;
96 |
97 | switch ( outputModality ) {
98 | case TransformixWrapperSettings.OUTPUT_MODALITY_SHOW_IMAGES:
99 | settings.outputModality = OutputModality.Show_images;
100 | break;
101 | case TransformixWrapperSettings.OUTPUT_MODALITY_SAVE_AS_TIFF:
102 | settings.outputModality = OutputModality.Save_as_tiff;
103 | break;
104 | case TransformixWrapperSettings.OUTPUT_MODALITY_SAVE_AS_BDV:
105 | settings.outputModality = OutputModality.Save_as_bdv;
106 | break;
107 | }
108 |
109 | settings.outputFile = outputFile;
110 |
111 | if ( !settings.outputModality.equals( OutputModality.Show_images ) )
112 | if ( outputFile == null )
113 | Utils.logErrorAndExit( settings,"Please specify an output file.");
114 |
115 | return settings;
116 | }
117 | }
118 |
--------------------------------------------------------------------------------
/src/main/java/de/embl/cba/elastix/logging/IJLazySwingLogger.java:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * Fiji distribution of ImageJ for the life sciences.
4 | * %%
5 | * Copyright (C) 2017 - 2025 EMBL
6 | * %%
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are met:
9 | *
10 | * 1. Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * 2. Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | * POSSIBILITY OF SUCH DAMAGE.
27 | * #L%
28 | */
29 | package de.embl.cba.elastix.logging;
30 |
31 | import ij.IJ;
32 | import javax.swing.*;
33 |
34 | public class IJLazySwingLogger implements Logger {
35 |
36 | private boolean showDebug = false;
37 |
38 | public IJLazySwingLogger() {
39 | }
40 |
41 | @Override
42 | public void setShowDebug(boolean showDebug)
43 | {
44 | this.showDebug = showDebug;
45 | }
46 |
47 | @Override
48 | public boolean isShowDebug()
49 | {
50 | return ( showDebug );
51 | }
52 |
53 |
54 | @Override
55 | public void info(String message){
56 | ijLazySwingLog(String.format("[INFO]: %s", message));
57 | }
58 |
59 | @Override
60 | public void progress( String message, String progress )
61 | {
62 | SwingUtilities.invokeLater(new Runnable() {
63 | public void run()
64 | {
65 | String[] logs = IJ.getLog().split("\n");
66 | if ( logs[logs.length-1].contains(message) )
67 | {
68 | IJ.log(String.format("\\Update:[PROGRESS]: %s %s", message, progress));
69 | }
70 | else
71 | {
72 | IJ.log(String.format("[PROGRESS]: %s %s", message, progress));
73 | }
74 | }
75 | });
76 | }
77 |
78 | @Override
79 | public void error(String _message){
80 | IJ.showMessage(String.format("[ERROR]: %s", _message));
81 | }
82 |
83 | @Override
84 | public void warning(String _message){
85 | ijLazySwingLog(String.format("[WARNING]: %s", _message));
86 | }
87 |
88 | @Override
89 | public void debug(String _message){
90 | if ( showDebug )
91 | {
92 | ijLazySwingLog(String.format("[DEBUG]: %s", _message));
93 | }
94 | }
95 |
96 |
97 | private void ijLazySwingLog(String message)
98 | {
99 | SwingUtilities.invokeLater(new Runnable() {
100 | public void run()
101 | {
102 | IJ.log(message);
103 | }
104 | });
105 | }
106 |
107 | }
108 |
--------------------------------------------------------------------------------
/src/main/java/de/embl/cba/elastix/logging/Logger.java:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * Fiji distribution of ImageJ for the life sciences.
4 | * %%
5 | * Copyright (C) 2017 - 2025 EMBL
6 | * %%
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are met:
9 | *
10 | * 1. Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * 2. Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | * POSSIBILITY OF SUCH DAMAGE.
27 | * #L%
28 | */
29 | package de.embl.cba.elastix.logging;
30 |
31 | public interface Logger {
32 |
33 | void setShowDebug(boolean showDebug);
34 |
35 | boolean isShowDebug();
36 |
37 | void info(String message);
38 |
39 | void progress(String message, String progress);
40 |
41 | void error(String message);
42 |
43 | void warning(String message);
44 |
45 | void debug(String message);
46 | }
47 |
--------------------------------------------------------------------------------
/src/main/java/de/embl/cba/elastix/utils/BatchApplyAmiraTransformationsToBdvXml.java:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * Fiji distribution of ImageJ for the life sciences.
4 | * %%
5 | * Copyright (C) 2017 - 2025 EMBL
6 | * %%
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are met:
9 | *
10 | * 1. Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * 2. Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | * POSSIBILITY OF SUCH DAMAGE.
27 | * #L%
28 | */
29 | package de.embl.cba.elastix.utils;
30 |
31 | import net.imglib2.realtransform.AffineTransform3D;
32 |
33 | import java.io.File;
34 | import java.io.IOException;
35 | import java.nio.charset.StandardCharsets;
36 | import java.nio.file.Files;
37 | import java.nio.file.Path;
38 | import java.util.ArrayList;
39 | import java.util.List;
40 | import java.util.regex.Matcher;
41 | import java.util.regex.Pattern;
42 |
43 | import static de.embl.cba.elastix.utils.TransformConversions.changeTransformToScaledUnits;
44 |
45 | public class BatchApplyAmiraTransformationsToBdvXml
46 | {
47 |
48 | final double[] rotationAxis;
49 | final double rotationAngleInDegrees;
50 | final double[] translationInMicrometer;
51 | final String directory;
52 | final String filePattern;
53 | private static final Pattern sizePattern = Pattern.compile( ".*(.*).*" );
54 | private static final String voxelSizeStart = "";
55 | private static final String voxelSizeEnd = "";
56 | private double[] voxelSizeInMicrometer;
57 | private double[] imageCentreInPixels;
58 | private double[] imageCentreInMicrometer;
59 |
60 | public BatchApplyAmiraTransformationsToBdvXml( double[] rotationAxis,
61 | double rotationAngleInDegrees,
62 | double[] translationInMicrometer,
63 | String directory,
64 | String filePattern )
65 | {
66 | this.rotationAxis = rotationAxis;
67 | this.rotationAngleInDegrees = rotationAngleInDegrees;
68 | this.translationInMicrometer = translationInMicrometer;
69 | this.directory = directory;
70 | this.filePattern = filePattern;
71 |
72 | }
73 |
74 | public void run() throws IOException
75 | {
76 | System.out.println( "Fetching files....");
77 | final List< File > files = Utils.getFileList( new File( directory ), filePattern, false );
78 |
79 | for ( File file : files )
80 | {
81 | if ( file.getName().contains( "OldAligned.xml" ) ) continue;
82 | if ( file.getName().contains( "-test.xml" ) ) continue;
83 | if ( file.getName().contains( "-aligned.xml" ) ) continue;
84 |
85 | setVoxelSizeAndDimensions( file );
86 |
87 | final AffineTransform3D affineTransform3D = TransformConversions.getAmiraAsPixelUnitsAffineTransform3D(
88 | rotationAxis,
89 | rotationAngleInDegrees,
90 | translationInMicrometer,
91 | voxelSizeInMicrometer,
92 | imageCentreInPixels );
93 |
94 | System.out.println( "\n" + file.getName() );
95 | System.out.println( "Transform in pixel units");
96 | System.out.println( TransformConversions.asStringBdvStyle( affineTransform3D ) );
97 |
98 | System.out.println( "Transform in scaled units");
99 | changeTransformToScaledUnits( affineTransform3D, voxelSizeInMicrometer );
100 | System.out.println( TransformConversions.asStringBdvStyle( affineTransform3D ) );
101 |
102 | List< String > fileContent = new ArrayList<>( Files.readAllLines( file.toPath(), StandardCharsets.UTF_8));
103 |
104 | for (int i = 0; i < fileContent.size(); i++) {
105 | if ( fileContent.get(i).contains( "" ))
106 | {
107 | String newAffine = " "
108 | + TransformConversions.asStringBdvStyle( affineTransform3D )
109 | + "";
110 |
111 | fileContent.set(i, newAffine);
112 | break;
113 | }
114 | }
115 |
116 | // TODO: I cannot overwrite the original xml files...why?
117 | final Path path = new File( directory + File.separator + file.getName() + "-aligned.xml" ).toPath();
118 |
119 | Files.write( path, fileContent, StandardCharsets.UTF_8);
120 |
121 | System.out.println( "Written: " + path );
122 | }
123 |
124 | }
125 |
126 |
127 | private void setVoxelSizeAndDimensions( File file ) throws IOException
128 | {
129 | final List< String > lines = Files.readAllLines( file.toPath() );
130 |
131 | boolean isVoxelSize = false;
132 |
133 | for ( String line : lines )
134 | {
135 |
136 | if ( line.contains( voxelSizeStart ) )isVoxelSize = true;
137 | if ( line.contains( voxelSizeEnd ) )isVoxelSize = false;
138 |
139 | final Matcher matcher = sizePattern.matcher( line );
140 |
141 | if ( matcher.matches() )
142 | {
143 | final String[] sizes = matcher.group( 1 ).split( " " );
144 |
145 | if ( isVoxelSize )
146 | {
147 | voxelSizeInMicrometer = new double[ 3 ];
148 | for ( int d = 0; d < sizes.length; ++d ) voxelSizeInMicrometer[ d ] = Double.parseDouble( sizes[ d ] );
149 | }
150 | else
151 | {
152 | imageCentreInPixels = new double[ 3 ];
153 | for ( int d = 0; d < sizes.length; ++d ) imageCentreInPixels[ d ] = Long.parseLong( sizes[ d ] ) / 2.0;
154 | }
155 | }
156 | }
157 |
158 | imageCentreInMicrometer = new double[ 3 ];
159 |
160 | for ( int d = 0; d < imageCentreInMicrometer.length; ++d )
161 | {
162 | imageCentreInMicrometer[ d ] = imageCentreInPixels[ d ] * voxelSizeInMicrometer[ d ];
163 | }
164 |
165 | }
166 |
167 | public static void main( String[] args ) throws IOException
168 | {
169 | final BatchApplyAmiraTransformationsToBdvXml batchApplyAmiraTransformationsToBdvXml = new BatchApplyAmiraTransformationsToBdvXml(
170 | new double[]{ 0.064, 0.762, 0.643 },
171 | 237.0,
172 | new double[]{ 147.9, 48.13, 103.0661 },
173 | "/Volumes/arendt/EM_6dpf_segmentation/EM-Prospr",
174 | ".*parapod-fib.*.xml" );
175 |
176 | // Old one
177 | // final BatchApplyAmiraTransformationsToBdvXml batchApplyAmiraTransformationsToBdvXml = new BatchApplyAmiraTransformationsToBdvXml(
178 | // new double[]{ -0.387, -0.727, -0.565 },
179 | // 107.596,
180 | // new double[]{ 148.578, 45.701, 115.941 },
181 | // "/Volumes/arendt/EM_6dpf_segmentation/EM-Prospr",
182 | // ".*parapod.*.xml" );
183 |
184 | batchApplyAmiraTransformationsToBdvXml.run();
185 |
186 | }
187 | }
188 |
--------------------------------------------------------------------------------
/src/main/java/de/embl/cba/elastix/utils/MonitorThreadPoolStatus.java:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * Fiji distribution of ImageJ for the life sciences.
4 | * %%
5 | * Copyright (C) 2017 - 2025 EMBL
6 | * %%
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are met:
9 | *
10 | * 1. Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * 2. Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | * POSSIBILITY OF SUCH DAMAGE.
27 | * #L%
28 | */
29 | package de.embl.cba.elastix.utils;
30 |
31 | import de.embl.cba.elastix.logging.IJLazySwingLogger;
32 | import de.embl.cba.elastix.logging.Logger;
33 |
34 | import java.util.List;
35 | import java.util.concurrent.Future;
36 |
37 | /**
38 | * Created by tischi on 11/04/17.
39 | */
40 | public class MonitorThreadPoolStatus {
41 |
42 | private static Logger logger = new IJLazySwingLogger();
43 |
44 | public static void showProgressAndWaitUntilDone(List futures,
45 | String message,
46 | int updateFrequencyMilliseconds) {
47 | int done = 0;
48 | while( done != futures.size() )
49 | {
50 | done = 0;
51 | for ( Future f : futures )
52 | {
53 | if (f.isDone() ) done++;
54 | }
55 |
56 | logger.progress( message, done + "/" + futures.size() );
57 |
58 | try {
59 | Thread.sleep(updateFrequencyMilliseconds);
60 | } catch(InterruptedException ex) {
61 | Thread.currentThread().interrupt();
62 | }
63 |
64 | }
65 |
66 | }
67 |
68 | }
69 |
--------------------------------------------------------------------------------
/src/main/java/de/embl/cba/elastix/utils/TransformConversions.java:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * Fiji distribution of ImageJ for the life sciences.
4 | * %%
5 | * Copyright (C) 2017 - 2025 EMBL
6 | * %%
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are met:
9 | *
10 | * 1. Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * 2. Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | * POSSIBILITY OF SUCH DAMAGE.
27 | * #L%
28 | */
29 | package de.embl.cba.elastix.utils;
30 |
31 | import net.imglib2.RandomAccessibleInterval;
32 | import net.imglib2.realtransform.AffineTransform3D;
33 | import net.imglib2.realtransform.Scale;
34 | import net.imglib2.util.Intervals;
35 | import org.apache.commons.math3.geometry.euclidean.threed.Rotation;
36 | import org.apache.commons.math3.geometry.euclidean.threed.RotationConvention;
37 | import org.apache.commons.math3.geometry.euclidean.threed.Vector3D;
38 |
39 | import java.util.stream.LongStream;
40 |
41 | public abstract class TransformConversions
42 | {
43 | public static AffineTransform3D getAmiraAsPixelUnitsAffineTransform3D(
44 | double[] amiraRotationAxis,
45 | double amiraRotationAngleInDegrees,
46 | double[] amiraTranslationVectorInMicrometer,
47 | double[] targetImageVoxelSizeInMicrometer,
48 | double[] targetImageCenterInPixels // this is the center of the rotation
49 | )
50 | {
51 |
52 | // rotate
53 | //
54 | final Vector3D axis = new Vector3D(
55 | amiraRotationAxis[ 0 ],
56 | amiraRotationAxis[ 1 ],
57 | amiraRotationAxis[ 2 ] );
58 |
59 | double angle = amiraRotationAngleInDegrees / 180.0 * Math.PI;
60 |
61 | final AffineTransform3D rotationTransform = getRotationTransform( axis, angle );
62 |
63 | final AffineTransform3D transform3D =
64 | getRotationAroundImageCenterTransform( rotationTransform, targetImageCenterInPixels );
65 |
66 | // translate
67 | //
68 | double[] translationInPixels = new double[ 3 ];
69 |
70 | for ( int d = 0; d < 3; ++d )
71 | {
72 | translationInPixels[ d ] =
73 | amiraTranslationVectorInMicrometer[ d ] / targetImageVoxelSizeInMicrometer[ d ];
74 | }
75 |
76 | transform3D.translate( translationInPixels );
77 |
78 | return transform3D;
79 | }
80 |
81 | public static String get_DOESNOTWORK_USE_INVERSE_AmiraAsElastixAffine3D(
82 | double[] amiraRotationAxis,
83 | double amiraRotationAngleInDegrees,
84 | double[] amiraTranslationVectorInMicrometer,
85 | double targetImageVoxelSizeInMicrometer,
86 | double[] rotationCentreInPixels ) // this is the center of the rotation)
87 | {
88 | // Note: Elastix Spatial Units are millimeters
89 |
90 |
91 | // Amira: T(moving) = R(x - cMoving) + cMoving + t
92 | // Elastix: T(fixed to moving) = R(x - cFixed) + cFixed + t
93 | // - the translations in the end are in the rotated coordinate system
94 |
95 | // TODO: make also work for anisotropic target image
96 |
97 | String out = "Affine:\n";
98 |
99 | // rotate
100 | //
101 |
102 | final Vector3D axis = new Vector3D(
103 | amiraRotationAxis[ 0 ],
104 | amiraRotationAxis[ 1 ],
105 | amiraRotationAxis[ 2 ] );
106 |
107 |
108 | double angle = amiraRotationAngleInDegrees / 180.0 * Math.PI;
109 |
110 | // Note: Transformation in elastix is defined inverse, i.e. from fixed to moving
111 | final AffineTransform3D rotationTransform = getRotationTransform( axis, angle ).inverse();
112 |
113 | for ( int row = 0; row < 3; ++row )
114 | for ( int col = 0; col < 3; ++col )
115 | out += rotationTransform.get( row, col ) + " ";
116 |
117 | // translate
118 | //
119 |
120 | // Note: Transformation in elastix is defined inverse, i.e. from fixed to moving
121 | // Note: the given translation is not applied after rotation!
122 |
123 | double[] translationInMillimeters = new double[ 3 ];
124 |
125 | for ( int d = 0; d < 3; ++d )
126 | {
127 | translationInMillimeters[ d ] = - 1.0 * amiraTranslationVectorInMicrometer[ d ];
128 | translationInMillimeters[ d ] /= 1000.0; // from micro to millimeter
129 | }
130 |
131 | rotationTransform.apply( translationInMillimeters, translationInMillimeters );
132 |
133 | for ( int d = 0; d < 3; ++d )
134 | {
135 | out += translationInMillimeters[ d ] + " ";
136 | }
137 |
138 | // centre of rotation
139 | //
140 |
141 | double[] rotationCentreInMillimeters = new double[ 3 ];
142 | for ( int d = 0; d < 3; ++d )
143 | {
144 | rotationCentreInMillimeters[ d ] = rotationCentreInPixels[ d ] * targetImageVoxelSizeInMicrometer;
145 | rotationCentreInMillimeters[ d ] /= 1000.0; // from micro to millimeter
146 | }
147 |
148 | out += "\nCentre of rotation:\n";
149 | for ( int d = 0; d < 3; ++d )
150 | out += rotationCentreInMillimeters[ d ] + " ";
151 |
152 | return out;
153 | }
154 |
155 | public static AffineTransform3D getRotationAroundImageCenterTransform(
156 | AffineTransform3D rotationTransform,
157 | double[] targetImageCenterInPixelUnits )
158 | {
159 | double[] translationFromCenterToOrigin = new double[ 3 ];
160 | double[] translationFromOriginToCenter = new double[ 3 ];
161 |
162 | for ( int d = 0; d < 3; ++d )
163 | {
164 | translationFromCenterToOrigin[ d ] = - targetImageCenterInPixelUnits[ d ];
165 | translationFromOriginToCenter[ d ] = + targetImageCenterInPixelUnits[ d ];
166 | }
167 |
168 | final AffineTransform3D transform3D = new AffineTransform3D();
169 | transform3D.translate( translationFromCenterToOrigin );
170 | transform3D.preConcatenate( rotationTransform );
171 | final AffineTransform3D transformOriginToCenter = new AffineTransform3D();
172 | transformOriginToCenter.translate( translationFromOriginToCenter );
173 | transform3D.preConcatenate( transformOriginToCenter );
174 | return transform3D;
175 | }
176 |
177 | public static String asStringElastixStyle(
178 | AffineTransform3D affineTransform3D,
179 | double voxelSizeInMillimeter)
180 | {
181 |
182 | String out = "";
183 | for ( int row = 0; row < 3; ++row )
184 | for ( int col = 0; col < 3; ++col )
185 | out += affineTransform3D.get( row, col ) + " ";
186 |
187 |
188 | out += voxelSizeInMillimeter * affineTransform3D.get( 0, 3 ) + " ";
189 | out += voxelSizeInMillimeter * affineTransform3D.get( 1, 3 ) + " ";
190 | out += voxelSizeInMillimeter * affineTransform3D.get( 2, 3 );
191 |
192 | return out;
193 | }
194 |
195 | public static String asStringBdvStyle( AffineTransform3D affineTransform3D )
196 | {
197 |
198 | String out = "";
199 | for ( int row = 0; row < 3; ++row )
200 | for ( int col = 0; col < 4; ++col )
201 | out += String.format( "%.4f", affineTransform3D.get( row, col ) ) + " ";
202 |
203 | return out;
204 | }
205 |
206 | public static AffineTransform3D getRotationTransform(
207 | Vector3D axis,
208 | double angle )
209 | {
210 | final Rotation rotation = new Rotation( axis, angle, RotationConvention.VECTOR_OPERATOR );
211 | final double[][] matrix = rotation.getMatrix();
212 |
213 | final AffineTransform3D rotationTransform = new AffineTransform3D();
214 | for ( int row = 0; row < 3; ++row )
215 | for ( int col = 0; col < 3; ++col )
216 | rotationTransform.set( matrix[ row ][ col ], row, col );
217 | return rotationTransform;
218 | }
219 |
220 | public static double[] getImageCentreInPixelUnits( RandomAccessibleInterval musclesProspr )
221 | {
222 | final long[] dimensions = Intervals.dimensionsAsLongArray( musclesProspr );
223 | return LongStream.of( dimensions ).mapToDouble( l -> l / 2.0 ).toArray();
224 | }
225 |
226 | public static void changeTransformToScaledUnits( AffineTransform3D affineTransform3D, double[] voxelSizeInMicrometer )
227 | {
228 | final Scale scale = new Scale( voxelSizeInMicrometer );
229 | affineTransform3D.concatenate( scale );
230 |
231 | final double[] translation = affineTransform3D.getTranslation();
232 | for ( int d = 0; d < 3; ++d )
233 | {
234 | translation[ d ] *= voxelSizeInMicrometer[ d ];
235 | }
236 |
237 | affineTransform3D.setTranslation( translation );
238 | }
239 |
240 | public static AffineTransform3D getElastixSimilarityAsBdvAffine()
241 | {
242 | // TODO.
243 | // (Transform "SimilarityTransform")
244 | //(NumberOfParameters 7)
245 | //(TransformParameters -0.008415 0.004752 -0.001727 -0.002337 -0.001490 0.003296 0.987273)
246 | //(InitialTransformParametersFileName "/Users/tischer/Documents/rachel-mellwig-em-prospr-registration/transformations/prospr-to-segmentation/TransformParameters.ManualPreAlignment-Affine_actuallyOnlyEuler.txt")
247 | //(HowToCombineTransforms "Compose")
248 | //
249 | //// Image specific
250 | //(FixedImageDimension 3)
251 | //(MovingImageDimension 3)
252 | //(FixedInternalImagePixelType "float")
253 | //(MovingInternalImagePixelType "float")
254 | //(Size 550 518 570)
255 | //(Index 0 0 0)
256 | //(Spacing 0.0005000000 0.0005000000 0.0005000000)
257 | //(Origin 0.0000000000 0.0000000000 0.0000000000)
258 | //(Direction 1.0000000000 0.0000000000 0.0000000000 0.0000000000 1.0000000000 0.0000000000 0.0000000000 0.0000000000 1.0000000000)
259 | //(UseDirectionCosines "false")
260 | //
261 | //// SimilarityTransform specific
262 | //(CenterOfRotationPoint 0.0132582577 0.0387138401 0.1074694348)
263 |
264 |
265 | return null;
266 | }
267 |
268 | public static AffineTransform3D getElastixEulerTransformAsAffineTransformInPixelUnits(
269 | String transform,
270 | String rotation,
271 | double[] imageVoxelSizeInMicrometer )
272 | {
273 | String[] split = transform.split( " " );
274 |
275 | final double[] angles = new double[ 3 ];
276 |
277 | for ( int d = 0; d < 3; ++d )
278 | {
279 | angles[ d ] = Double.parseDouble( split[ d ] );
280 | }
281 |
282 | final double[] translationInPixels = new double[ 3 ];
283 |
284 | for ( int d = 0; d < 3; ++d )
285 | {
286 | translationInPixels[ d ] = Double.parseDouble( split[ d + 3 ] ) / ( 0.001 * imageVoxelSizeInMicrometer[ d ] );
287 | }
288 |
289 |
290 | split = rotation.split( " " );
291 |
292 | final double[] rotationCentreVectorInPixelsPositive = new double[ 3 ];
293 | final double[] rotationCentreVectorInPixelsNegative = new double[ 3 ];
294 |
295 | for ( int d = 0; d < 3; ++d )
296 | {
297 | rotationCentreVectorInPixelsPositive[ d ] = Double.parseDouble( split[ d ] ) / ( 0.001 * imageVoxelSizeInMicrometer[ d ] );
298 | rotationCentreVectorInPixelsNegative[ d ] = - Double.parseDouble( split[ d ] ) / ( 0.001 * imageVoxelSizeInMicrometer[ d ] );
299 | }
300 |
301 |
302 | final AffineTransform3D transform3D = new AffineTransform3D();
303 |
304 | // rotate around rotation centre
305 | //
306 | transform3D.translate( rotationCentreVectorInPixelsNegative ); // + or - ??
307 | for ( int d = 0; d < 3; ++d)
308 | {
309 | transform3D.rotate( d, angles[ d ]);
310 | }
311 | final AffineTransform3D translateBackFromRotationCentre = new AffineTransform3D();
312 | translateBackFromRotationCentre.translate( rotationCentreVectorInPixelsPositive );
313 | transform3D.preConcatenate( translateBackFromRotationCentre );
314 |
315 |
316 | // translate
317 | //
318 | transform3D.translate( translationInPixels );
319 |
320 | return transform3D;
321 | }
322 | }
323 |
--------------------------------------------------------------------------------
/src/main/java/de/embl/cba/elastix/utils/Utils.java:
--------------------------------------------------------------------------------
1 | /*
2 | * #%L
3 | * Fiji distribution of ImageJ for the life sciences.
4 | * %%
5 | * Copyright (C) 2017 - 2025 EMBL
6 | * %%
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are met:
9 | *
10 | * 1. Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * 2. Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | * POSSIBILITY OF SUCH DAMAGE.
27 | * #L%
28 | */
29 |
30 | package de.embl.cba.elastix.utils;
31 |
32 | import de.embl.cba.elastix.commandline.settings.Settings;
33 | import de.embl.cba.metaimage_io.MetaImage_Reader;
34 | import ij.*;
35 | import ij.process.ByteProcessor;
36 | import ij.process.ImageProcessor;
37 | import org.scijava.log.LogService;
38 |
39 | import java.io.*;
40 | import java.util.ArrayList;
41 | import java.util.List;
42 | import java.util.regex.Matcher;
43 | import java.util.regex.Pattern;
44 |
45 | /**
46 | * Created by tischi on 06/11/16.
47 | */
48 |
49 | public abstract class Utils {
50 |
51 | public static boolean verbose = false;
52 | public static String LOAD_CHANNELS_FROM_FOLDERS = "from sub-folders";
53 |
54 | public static List< File > getFileList( File directory, String fileNameRegExp, boolean recursive )
55 | {
56 | final ArrayList< File > files = new ArrayList<>();
57 | populateFileList( directory, fileNameRegExp, files, recursive );
58 | return files;
59 | }
60 |
61 | public static void populateFileList( File directory, String fileNameRegExp, List< File > files, boolean recursive ) {
62 |
63 | // Get all the files from a directory.
64 | File[] fList = directory.listFiles();
65 |
66 | if( fList != null )
67 | {
68 | for ( File file : fList )
69 | {
70 | if ( file.isFile() )
71 | {
72 | final Matcher matcher = Pattern.compile( fileNameRegExp ).matcher( file.getName() );
73 |
74 | if ( matcher.matches() )
75 | files.add( file );
76 | }
77 | else if ( file.isDirectory() && recursive )
78 | {
79 | populateFileList( file, fileNameRegExp, files, recursive );
80 | }
81 | }
82 | }
83 | }
84 |
85 | public static double[] delimitedStringToDoubleArray(
86 | String s, String delimiter) {
87 |
88 | String[] sA = s.split(delimiter);
89 | double[] nums = new double[sA.length];
90 | for (int i = 0; i < nums.length; i++) {
91 | nums[i] = Double.parseDouble(sA[i]);
92 | }
93 |
94 | return nums;
95 | }
96 |
97 | public static int[] delimitedStringToIntegerArray(
98 | String s, String delimiter) {
99 |
100 | String[] sA = s.split(delimiter);
101 | int[] nums = new int[sA.length];
102 | for (int i = 0; i < nums.length; i++) {
103 | nums[i] = Integer.parseInt(sA[i]);
104 | }
105 |
106 | return nums;
107 | }
108 |
109 | public static void saveStringToFile( String text, String path )
110 | {
111 | PrintWriter writer = null;
112 | try
113 | {
114 | writer = new PrintWriter( path, "UTF-8" );
115 | }
116 | catch ( FileNotFoundException e )
117 | {
118 | e.printStackTrace();
119 | }
120 | catch ( UnsupportedEncodingException e )
121 | {
122 | e.printStackTrace();
123 | }
124 | writer.write( text);
125 | writer.close();
126 | }
127 |
128 |
129 | public static void saveStringListToFile( List< String > parameters, String path )
130 | {
131 | try
132 | {
133 | FileWriter writer = new FileWriter( path );
134 | for (String str : parameters)
135 | {
136 | System.out.println( str );
137 | writer.write(str+"\n");
138 | }
139 | writer.close();
140 | }
141 | catch ( Exception e )
142 | {
143 | IJ.showMessage( "Writing file failed: " + path );
144 | System.out.print( e.toString() );
145 | }
146 | }
147 |
148 | public static String convertStreamToStr( InputStream is ) throws IOException {
149 |
150 | if (is != null) {
151 | Writer writer = new StringWriter();
152 |
153 | char[] buffer = new char[1024];
154 | try {
155 | Reader reader = new BufferedReader(new InputStreamReader(is,
156 | "UTF-8"));
157 | int n;
158 | while ((n = reader.read(buffer)) != -1) {
159 | writer.write(buffer, 0, n);
160 | }
161 | } finally {
162 | is.close();
163 | }
164 | return writer.toString();
165 | }
166 | else {
167 | return "";
168 | }
169 | }
170 |
171 |
172 | public static void executeCommand( List< String > args, LogService logService )
173 | {
174 | ProcessBuilder pb = new ProcessBuilder( args );
175 |
176 | String cmd = "";
177 |
178 | for ( String s : pb.command() )
179 | {
180 | cmd = cmd + " " + s;
181 | }
182 |
183 | logService.info("Command launched:" + cmd);
184 |
185 | int numAttempts = 0;
186 | int maxAttempts = 5;
187 |
188 | while ( numAttempts < maxAttempts )
189 | {
190 | try
191 | {
192 | pb.redirectErrorStream( true );
193 | final Process process = pb.start();
194 | InputStream myIS = process.getInputStream();
195 | String tempOut = convertStreamToStr( myIS );
196 | logService.info( tempOut );
197 | break;
198 | }
199 | catch ( Exception e )
200 | {
201 | logService.error( "Error occured during system call" );
202 | logService.error( "" + e );
203 | logService.error( "/nTrying again.../n" );
204 | waitOneSecond();
205 | numAttempts++;
206 | }
207 | }
208 |
209 | }
210 |
211 | public static void waitOneSecond()
212 | {
213 | try
214 | {
215 | Thread.sleep( 1000 );
216 | } catch ( InterruptedException e )
217 | {
218 | e.printStackTrace();
219 | }
220 | }
221 |
222 | public static void convertToMask( ImagePlus imp, float threshold )
223 | {
224 | int width = imp.getWidth();
225 | int height = imp.getHeight();
226 | int size = width*height;
227 | int nSlices = imp.getStackSize();
228 | ImageStack stack1 = imp.getStack();
229 | ImageStack stack2 = new ImageStack(width, height);
230 | float value;
231 | ImageProcessor ip1, ip2;
232 | IJ.showStatus("Converting to mask");
233 | for (int i=1; i<=nSlices; i++) {
234 | IJ.showProgress(i, nSlices);
235 | String label = stack1.getSliceLabel(i);
236 | ip1 = stack1.getProcessor(i);
237 | ip2 = new ByteProcessor(width, height);
238 | for (int j=0; j=threshold )
241 | ip2.set(j, 1);
242 | else
243 | ip2.set(j, 0);
244 | }
245 | stack2.addSlice(label, ip2);
246 | }
247 | imp.setStack(null, stack2);
248 | ImageStack stack = imp.getStack();
249 | stack.setColorModel( LookUpTable.createGrayscaleColorModel(!Prefs.blackBackground));
250 | imp.setStack(null, stack);
251 | if (imp.isComposite()) {
252 | CompositeImage ci = (CompositeImage)imp;
253 | ci.setMode(IJ.GRAYSCALE);
254 | ci.resetDisplayRanges();
255 | ci.updateAndDraw();
256 | }
257 | IJ.showStatus("");
258 | }
259 |
260 | public static void logErrorAndExit( Settings settings, String msg )
261 | {
262 | settings.logService.error( msg );
263 | if ( settings.headless )
264 | System.exit( 1 );
265 | }
266 |
267 | public static ImagePlus loadMetaImage( String directory, String filename )
268 | {
269 | MetaImage_Reader reader = new MetaImage_Reader();
270 | return reader.load( directory, filename, false );
271 | }
272 | }
273 |
--------------------------------------------------------------------------------
/src/main/java/de/embl/cba/elastix/wrapper/BdvManager.java:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * Fiji distribution of ImageJ for the life sciences.
4 | * %%
5 | * Copyright (C) 2017 - 2025 EMBL
6 | * %%
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are met:
9 | *
10 | * 1. Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * 2. Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | * POSSIBILITY OF SUCH DAMAGE.
27 | * #L%
28 | */
29 | package de.embl.cba.elastix.wrapper;
30 |
31 | import bdv.util.*;
32 | import ij.ImagePlus;
33 | import ij.measure.Calibration;
34 | import net.imglib2.RandomAccessibleInterval;
35 | import net.imglib2.img.display.imagej.ImageJFunctions;
36 | import net.imglib2.type.numeric.ARGBType;
37 |
38 | import java.util.ArrayList;
39 |
40 | import static de.embl.cba.elastix.utils.Utils.loadMetaImage;
41 |
42 | public class BdvManager {
43 |
44 | private ArrayList colors;
45 | private Bdv bdv;
46 | private int colorIndex;
47 |
48 | public BdvManager() {
49 | initColors();
50 | }
51 |
52 | private void initColors()
53 | {
54 | colors = new ArrayList<>();
55 | colors.add( new ARGBType( ARGBType.rgba( 000, 255, 000, 255 ) ) );
56 | colors.add( new ARGBType( ARGBType.rgba( 255, 000, 255, 255 ) ) );
57 | colors.add( new ARGBType( ARGBType.rgba( 255, 000, 000, 255 ) ) );
58 | colors.add( new ARGBType( ARGBType.rgba( 000, 000, 255, 255 ) ) );
59 | colors.add( new ARGBType( ARGBType.rgba( 000, 255, 255, 255 ) ) );
60 | colors.add( new ARGBType( ARGBType.rgba( 255, 255, 000, 255 ) ) );
61 |
62 | colors.add( new ARGBType( ARGBType.rgba( 255, 255, 255, 255 ) ) );
63 | colors.add( new ARGBType( ARGBType.rgba( 255, 255, 255, 255 ) ) );
64 | colors.add( new ARGBType( ARGBType.rgba( 255, 255, 255, 255 ) ) );
65 | colors.add( new ARGBType( ARGBType.rgba( 255, 255, 255, 255 ) ) );
66 | colors.add( new ARGBType( ARGBType.rgba( 255, 255, 255, 255 ) ) );
67 | colors.add( new ARGBType( ARGBType.rgba( 255, 255, 255, 255 ) ) );
68 | colors.add( new ARGBType( ARGBType.rgba( 255, 255, 255, 255 ) ) );
69 | colors.add( new ARGBType( ARGBType.rgba( 255, 255, 255, 255 ) ) );
70 | colorIndex = 0;
71 | }
72 |
73 | public Bdv showMetaImageInBdv( String imageDir, String imageName ) {
74 | ImagePlus imagePlus = loadMetaImage( imageDir, imageName );
75 | final BdvStackSource bdvStackSource = showImagePlusInBdv( imagePlus );
76 | bdvStackSource.setColor( colors.get( colorIndex++ ) );
77 | bdv = bdvStackSource.getBdvHandle();
78 | return bdv;
79 | }
80 |
81 | public BdvStackSource showImagePlusInBdv(
82 | ImagePlus imp )
83 | {
84 | final Calibration calibration = imp.getCalibration();
85 |
86 | if ( imp.getNSlices() > 1 )
87 | {
88 | final double[] calib = {
89 | calibration.pixelWidth,
90 | calibration.pixelHeight,
91 | calibration.pixelDepth
92 | };
93 | return BdvFunctions.show(
94 | (RandomAccessibleInterval) ImageJFunctions.wrapReal( imp ),
95 | imp.getTitle(),
96 | BdvOptions.options().addTo( bdv ).axisOrder( AxisOrder.XYZ ).sourceTransform( calib ) );
97 | }
98 | else
99 | {
100 |
101 | final double[] calib = {
102 | calibration.pixelWidth,
103 | calibration.pixelHeight
104 | };
105 |
106 | return BdvFunctions.show(
107 | ( RandomAccessibleInterval ) ImageJFunctions.wrapReal( imp ),
108 | imp.getTitle(),
109 | BdvOptions.options().addTo( bdv ).is2D().sourceTransform( calib ) );
110 | }
111 | }
112 | }
113 |
--------------------------------------------------------------------------------
/src/main/java/de/embl/cba/elastix/wrapper/StagingManager.java:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * Fiji distribution of ImageJ for the life sciences.
4 | * %%
5 | * Copyright (C) 2017 - 2025 EMBL
6 | * %%
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are met:
9 | *
10 | * 1. Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * 2. Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | * POSSIBILITY OF SUCH DAMAGE.
27 | * #L%
28 | */
29 | package de.embl.cba.elastix.wrapper;
30 |
31 | import de.embl.cba.elastix.commandline.settings.Settings;
32 | import de.embl.cba.elastix.utils.Utils;
33 | import de.embl.cba.metaimage_io.MetaImage_Writer;
34 | import ij.IJ;
35 | import ij.ImagePlus;
36 | import ij.plugin.Duplicator;
37 |
38 | import java.io.File;
39 | import java.util.ArrayList;
40 |
41 | public class StagingManager {
42 |
43 | public static final String STAGING_FILE_TYPE = "mhd";
44 | public static final String ELASTIX_FIXED_IMAGE_NAME = "fixed";
45 | public static final String ELASTIX_MOVING_IMAGE_NAME = "moving";
46 | public static final String ELASTIX_FIXED_MASK_IMAGE_NAME = "fixedMask";
47 | public static final String ELASTIX_MOVING_MASK_IMAGE_NAME = "movingMask";
48 |
49 | public static final String MHD = ".mhd";
50 | public static final String RAW = ".raw";
51 |
52 | public static final String ELASTIX_OUTPUT_FILENAME = "result.0";
53 | public static final String TRANSFORMIX_INPUT_FILENAME = "to_be_transformed";
54 | public static final String TRANSFORMIX_OUTPUT_FILENAME = "result";
55 |
56 | private Settings settings;
57 | private ArrayList< String > elastixTmpFilenames;
58 |
59 | public StagingManager ( Settings settings ) {
60 | this.settings = settings;
61 | }
62 |
63 | public void createOrEmptyWorkingDir()
64 | {
65 | settings.logService.info( "Temporary directory is: " + settings.tmpDir );
66 |
67 | setElastixTmpFilenames();
68 |
69 | File directory = new File( settings.tmpDir );
70 |
71 | if (! directory.exists() )
72 | directory.mkdir();
73 | else
74 | for ( String filename : elastixTmpFilenames )
75 | {
76 | final File file = new File( settings.tmpDir, filename );
77 | if ( file.exists() )
78 | file.delete();
79 | }
80 | }
81 |
82 | private void setElastixTmpFilenames()
83 | {
84 | final ArrayList< String > elastixTmpFilenameStumps = new ArrayList<>();
85 | elastixTmpFilenameStumps.add( ELASTIX_FIXED_IMAGE_NAME );
86 | elastixTmpFilenameStumps.add( ELASTIX_MOVING_IMAGE_NAME );
87 | elastixTmpFilenameStumps.add( ELASTIX_MOVING_MASK_IMAGE_NAME );
88 | elastixTmpFilenameStumps.add( ELASTIX_FIXED_MASK_IMAGE_NAME );
89 | elastixTmpFilenameStumps.add( ELASTIX_OUTPUT_FILENAME );
90 | elastixTmpFilenameStumps.add( TRANSFORMIX_OUTPUT_FILENAME );
91 | elastixTmpFilenameStumps.add( TRANSFORMIX_INPUT_FILENAME );
92 |
93 | elastixTmpFilenames = new ArrayList<>();
94 | for ( String filenameStump : elastixTmpFilenameStumps )
95 | addTmpImage( filenameStump );
96 |
97 | for ( int c = 0; c < 10; c++ )
98 | for ( String filenameStump : elastixTmpFilenameStumps )
99 | addTmpImage( getChannelFilename( filenameStump, c ) );
100 | }
101 |
102 | private void addTmpImage( String filename )
103 | {
104 | elastixTmpFilenames.add( filename + MHD );
105 | elastixTmpFilenames.add( filename + RAW );
106 | }
107 |
108 | public ArrayList< String > stageImageAsMhd( String imagePath, String filename )
109 | {
110 | ImagePlus imp = openImage( imagePath );
111 |
112 | int nChannels = imp.getNChannels();
113 |
114 | if ( nChannels > 1 )
115 | {
116 | return stageMultiChannelImagePlusAsMhd( imp, filename );
117 | }
118 | else
119 | {
120 | ArrayList< String > filenames = new ArrayList<>();
121 | filenames.add( stageImagePlusAsMhd( imp, filename ) );
122 | return filenames;
123 | }
124 | }
125 |
126 | private String stageImagePlusAsMhd( ImagePlus imp, String filename )
127 | {
128 | if ( filename.contains( ELASTIX_FIXED_MASK_IMAGE_NAME )
129 | || filename.contains( ELASTIX_MOVING_MASK_IMAGE_NAME ) )
130 | Utils.convertToMask( imp, 0.1F );
131 |
132 | MetaImage_Writer writer = new MetaImage_Writer();
133 | String filenameWithExtension = filename + MHD;
134 | settings.logService.info( "Staging image as mhd: " + filenameWithExtension );
135 | writer.save( imp, settings.tmpDir, filenameWithExtension );
136 | return getPath( filenameWithExtension );
137 | }
138 |
139 | private ArrayList< String > stageMultiChannelImagePlusAsMhd( ImagePlus imp, String filename )
140 | {
141 | ArrayList< String > filePaths = new ArrayList<>( );
142 |
143 | for ( int channelIndex = 0; channelIndex < imp.getNChannels(); ++channelIndex )
144 | {
145 | ImagePlus channelImage = getChannel( imp, channelIndex );
146 |
147 | filePaths.add(
148 | stageImagePlusAsMhd(
149 | channelImage, getChannelFilename( filename, channelIndex ) ) );
150 | }
151 |
152 | return filePaths;
153 | }
154 |
155 | private String getChannelFilename( String filename, int channelIndex )
156 | {
157 | return filename + "-C" + channelIndex;
158 | }
159 |
160 | private ImagePlus getChannel( ImagePlus imp, int channel )
161 | {
162 | Duplicator duplicator = new Duplicator();
163 |
164 | return duplicator.run(
165 | imp,
166 | channel + 1,
167 | channel + 1,
168 | 1,
169 | imp.getNSlices(),
170 | 1,
171 | 1 );
172 | }
173 |
174 | private boolean checkChannelNumber( int nChannelsFixedImage, int nChannelsMovingImage )
175 | {
176 |
177 | if ( nChannelsFixedImage != nChannelsMovingImage )
178 | {
179 | Utils.logErrorAndExit( settings, "Number of channels " +
180 | "in fixed and moving image do not match." );
181 | return false;
182 | }
183 | return true;
184 | }
185 |
186 | public ImagePlus openImage ( String imagePath ) {
187 | ImagePlus imp = IJ.openImage( imagePath );
188 |
189 | if ( imp == null )
190 | {
191 | System.err.println( "[ERROR] The image could not be loaded: "
192 | + imagePath );
193 | if ( settings.headless )
194 | System.exit( 1 );
195 | }
196 |
197 | return imp;
198 | }
199 |
200 | public String getDefaultParameterFilePath()
201 | {
202 | return getPath( "elastix_parameters.txt" );
203 | }
204 |
205 | public String getDefaultTransformationFilePath()
206 | {
207 | return getPath( "TransformParameters.0.txt" );
208 | }
209 |
210 | public String getPath( String fileName )
211 | {
212 | return settings.tmpDir + File.separator + fileName;
213 | }
214 | }
215 |
--------------------------------------------------------------------------------
/src/main/java/de/embl/cba/elastix/wrapper/elastix/ElastixWrapper.java:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * Fiji distribution of ImageJ for the life sciences.
4 | * %%
5 | * Copyright (C) 2017 - 2025 EMBL
6 | * %%
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are met:
9 | *
10 | * 1. Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * 2. Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | * POSSIBILITY OF SUCH DAMAGE.
27 | * #L%
28 | */
29 | package de.embl.cba.elastix.wrapper.elastix;
30 |
31 | import bdv.util.*;
32 | import de.embl.cba.elastix.commandline.ElastixCaller;
33 | import de.embl.cba.elastix.commandline.settings.ElastixSettings;
34 | import de.embl.cba.elastix.utils.Utils;
35 | import de.embl.cba.elastix.wrapper.BdvManager;
36 | import de.embl.cba.elastix.wrapper.StagingManager;
37 | import de.embl.cba.elastix.wrapper.elastix.parameters.DefaultElastixParametersCreator;
38 | import de.embl.cba.elastix.wrapper.elastix.parameters.ElastixParameters;
39 | import de.embl.cba.elastix.wrapper.transformix.TransformixWrapper;
40 | import de.embl.cba.elastix.wrapper.transformix.TransformixWrapperSettings.OutputModality;
41 | import ij.*;
42 | import org.apache.commons.io.FileUtils;
43 |
44 | import java.io.File;
45 | import java.io.IOException;
46 |
47 | import static de.embl.cba.elastix.wrapper.StagingManager.*;
48 |
49 | public class ElastixWrapper
50 | {
51 | private ElastixWrapperSettings settings;
52 | private StagingManager stagingManager;
53 |
54 | public ElastixWrapper( ElastixWrapperSettings settings )
55 | {
56 | this.settings = settings;
57 | this.stagingManager = new StagingManager( settings );
58 | }
59 |
60 | public void runElastix()
61 | {
62 | processSettings();
63 | stagingManager.createOrEmptyWorkingDir();
64 |
65 | if (!stageImages()) {
66 | Utils.logErrorAndExit(settings, "There was an issue staging the images.\n " +
67 | "Maybe the temporary working directory could not be generated.");
68 | return;
69 | }
70 |
71 | setMovingImageParameters();
72 | createElastixParameterFile();
73 | ElastixSettings elastixSettings = new ElastixSettings( settings );
74 | new ElastixCaller( elastixSettings ).callElastix();
75 | }
76 |
77 | private void processSettings()
78 | {
79 | if ( ! settings.elastixDirectory.endsWith( File.separator ) )
80 | settings.elastixDirectory += File.separator;
81 |
82 | if ( ! settings.tmpDir.endsWith( File.separator ) )
83 | settings.tmpDir += File.separator;
84 | }
85 |
86 | private boolean stageImages()
87 | {
88 | settings.stagedFixedImageFilePaths = stagingManager.stageImageAsMhd(
89 | settings.fixedImageFilePath,
90 | ELASTIX_FIXED_IMAGE_NAME );
91 |
92 | settings.stagedMovingImageFilePaths = stagingManager.stageImageAsMhd(
93 | settings.movingImageFilePath,
94 | ELASTIX_MOVING_IMAGE_NAME );
95 |
96 | if ( ! settings.fixedMaskPath.equals( "" ) )
97 | settings.stagedFixedMaskFilePaths = stagingManager.stageImageAsMhd(
98 | settings.fixedMaskPath,
99 | ELASTIX_FIXED_MASK_IMAGE_NAME );
100 |
101 | if ( ! settings.movingMaskPath.equals( "" ) )
102 | settings.stagedMovingMaskFilePaths = stagingManager.stageImageAsMhd(
103 | settings.movingMaskPath,
104 | ELASTIX_MOVING_MASK_IMAGE_NAME );
105 |
106 | setFixedToMovingChannel();
107 |
108 | return true;
109 | }
110 |
111 | private void setFixedToMovingChannel() {
112 | if ( settings.fixedToMovingChannel.size() == 0 )
113 | {
114 | // use all channels for registration
115 | for ( int c = 0; c < settings.stagedFixedImageFilePaths.size(); c++ )
116 | settings.fixedToMovingChannel.put( c, c );
117 | }
118 | }
119 |
120 | private void setMovingImageParameters() {
121 | ImagePlus imp = stagingManager.openImage( settings.movingImageFilePath );
122 | settings.movingImageBitDepth = imp.getBitDepth();
123 | }
124 |
125 | private void createElastixParameterFile()
126 | {
127 | settings.parameterFilePath = stagingManager.getDefaultParameterFilePath();
128 | System.out.println( "Parameter list type: " + settings.elastixParametersStyle );
129 | ElastixParameters parameters =
130 | new DefaultElastixParametersCreator( settings ).getElastixParameters( settings.elastixParametersStyle );
131 |
132 | if ( parameters == null ) {
133 | Utils.logErrorAndExit( settings, "Parameter file could not be created - image bit depth might not be supported" );
134 | }
135 |
136 | parameters.writeParameterFile( settings.parameterFilePath );
137 | }
138 |
139 | /**
140 | * Shows the fixed, moving and transformed moving images
141 | * in BigDataViewer.
142 | *
143 | * @return {@code Bdv} BigDataViewer handle, enabling, e.g., bdv.close()
144 | */
145 | public Bdv reviewResults()
146 | {
147 | TransformixWrapper transformixWrapper = createTransformixWrapper( OutputModality.Save_as_tiff );
148 | transformixWrapper.transformImagesAndHandleOutput();
149 |
150 | BdvManager bdvManager = new BdvManager();
151 | showFixedImagesInBdv( bdvManager );
152 | showMovingImagesInBdv( bdvManager );
153 | return showTransformedImagesInBdv( bdvManager, transformixWrapper );
154 | }
155 |
156 | public void reviewResultsInImageJ()
157 | {
158 | TransformixWrapper transformixWrapper = createTransformixWrapper( OutputModality.Show_images );
159 | showInputImagePlus();
160 | transformixWrapper.transformImagesAndHandleOutput();
161 | }
162 |
163 | public void createTransformedImagesAndSaveAsTiff()
164 | {
165 | TransformixWrapper transformixWrapper = createTransformixWrapper( OutputModality.Save_as_tiff );
166 | transformixWrapper.transformImagesAndHandleOutput();
167 | }
168 |
169 | private TransformixWrapper createTransformixWrapper( OutputModality outputModality ) {
170 | settings.outputModality = outputModality;
171 | settings.transformationFilePath = stagingManager.getDefaultTransformationFilePath();
172 | settings.outputFile = new File( stagingManager.getPath( "transformed" ) );
173 | return new TransformixWrapper( settings );
174 | }
175 |
176 | private Bdv showMovingImagesInBdv( BdvManager bdvManager )
177 | {
178 | Bdv bdv = null;
179 | for ( int index : settings.fixedToMovingChannel.values() )
180 | {
181 | String baseName = new File( settings.stagedMovingImageFilePaths.get(index) ).getName();
182 | bdv = bdvManager.showMetaImageInBdv( settings.tmpDir, baseName );
183 | }
184 | return bdv;
185 | }
186 |
187 | private Bdv showFixedImagesInBdv( BdvManager bdvManager )
188 | {
189 | Bdv bdv = null;
190 | for ( int index : settings.fixedToMovingChannel.keySet() )
191 | {
192 | String baseName = new File( settings.stagedFixedImageFilePaths.get(index) ).getName();
193 | bdv = bdvManager.showMetaImageInBdv( settings.tmpDir, baseName );
194 | }
195 | return bdv;
196 | }
197 |
198 | private Bdv showTransformedImagesInBdv( BdvManager bdvManager, TransformixWrapper transformixWrapper )
199 | {
200 | Bdv bdv = null;
201 | for ( int index : settings.fixedToMovingChannel.values() )
202 | {
203 | bdv = transformixWrapper.showTransformedImage( bdvManager, index );
204 | }
205 | return bdv;
206 | }
207 |
208 | private BdvStackSource showFixedInBdv( BdvManager bdvManager )
209 | {
210 | final ImagePlus templateImp = IJ.openImage( settings.fixedImageFilePath );
211 | return bdvManager.showImagePlusInBdv( templateImp );
212 | }
213 |
214 | public void showTransformationFile()
215 | {
216 | IJ.open( stagingManager.getDefaultTransformationFilePath() );
217 | }
218 |
219 | public void saveTransformationFile()
220 | {
221 | final File transformation =
222 | new File( stagingManager.getDefaultTransformationFilePath() );
223 |
224 | File copied = new File( settings.transformationOutputFilePath );
225 |
226 | try
227 | {
228 | FileUtils.copyFile( transformation, copied);
229 | } catch ( IOException e )
230 | {
231 | e.printStackTrace();
232 | }
233 | }
234 |
235 | public void showInputImagePlus( )
236 | {
237 | ImagePlus fixed;
238 |
239 | fixed = IJ.openImage( settings.fixedImageFilePath );
240 |
241 | fixed.show();
242 |
243 | fixed.setTitle( "fixed" );
244 |
245 | // TODO: The macro recording does not work when using IJ.run(..) inside the plugin
246 | // if ( fixed.getNChannels() > 1 ) IJ.run("Split Channels" );
247 | }
248 | }
249 |
--------------------------------------------------------------------------------
/src/main/java/de/embl/cba/elastix/wrapper/elastix/ElastixWrapperSettings.java:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * Fiji distribution of ImageJ for the life sciences.
4 | * %%
5 | * Copyright (C) 2017 - 2025 EMBL
6 | * %%
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are met:
9 | *
10 | * 1. Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * 2. Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | * POSSIBILITY OF SUCH DAMAGE.
27 | * #L%
28 | */
29 | package de.embl.cba.elastix.wrapper.elastix;
30 |
31 | import de.embl.cba.elastix.wrapper.elastix.parameters.DefaultElastixParametersCreator.ParameterStyle;
32 | import de.embl.cba.elastix.wrapper.elastix.parameters.ElastixParameters;
33 | import de.embl.cba.elastix.wrapper.transformix.TransformixWrapperSettings;
34 |
35 | import java.util.ArrayList;
36 | import java.util.HashMap;
37 | import java.util.Map;
38 |
39 | import static de.embl.cba.elastix.wrapper.elastix.parameters.ElastixParameters.FINAL_RESAMPLER_LINEAR;
40 |
41 | public class ElastixWrapperSettings extends TransformixWrapperSettings
42 | {
43 | // before staging
44 | public String fixedImageFilePath = "";
45 | public String fixedMaskPath = "";
46 | public String movingMaskPath = "";
47 |
48 | // after staging - in order of channels
49 | public ArrayList stagedFixedImageFilePaths;
50 | public ArrayList stagedFixedMaskFilePaths;
51 | public ArrayList stagedMovingMaskFilePaths;
52 |
53 | public String initialTransformationFilePath;
54 | public String parameterFilePath;
55 |
56 | // path to copy calculated transformation to
57 | public String transformationOutputFilePath;
58 |
59 | // minimal settings needed to generate defaults with DefaultElastixParametersCreator
60 | public ParameterStyle elastixParametersStyle = ParameterStyle.Default;
61 | public ElastixParameters.TransformationType transformationType;
62 | public int iterations = 1000;
63 | public String spatialSamples = "10000";
64 | public String downSamplingFactors = "10 10 10";
65 | public String bSplineGridSpacing = "50 50 50";
66 | public String finalResampler = FINAL_RESAMPLER_LINEAR;
67 | public int movingImageBitDepth = 8;
68 | public Map< Integer, Integer > fixedToMovingChannel = new HashMap<>( );
69 | public double[] channelWeights = new double[]{1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,};
70 | }
71 |
--------------------------------------------------------------------------------
/src/main/java/de/embl/cba/elastix/wrapper/elastix/parameters/ElastixParameters.java:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * Fiji distribution of ImageJ for the life sciences.
4 | * %%
5 | * Copyright (C) 2017 - 2025 EMBL
6 | * %%
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are met:
9 | *
10 | * 1. Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * 2. Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | * POSSIBILITY OF SUCH DAMAGE.
27 | * #L%
28 | */
29 | package de.embl.cba.elastix.wrapper.elastix.parameters;
30 |
31 |
32 | import de.embl.cba.elastix.utils.Utils;
33 |
34 | import java.util.ArrayList;
35 | import java.util.List;
36 |
37 | public class ElastixParameters
38 | {
39 | public enum TransformationType
40 | {
41 | Translation,
42 | Euler,
43 | Similarity,
44 | Affine,
45 | BSpline
46 | }
47 |
48 | public static final String TRANSLATION = "Translation";
49 | public static final String EULER = "Euler";
50 | public static final String SIMILARITY = "Similarity";
51 | public static final String AFFINE = "Affine";
52 | public static final String SPLINE = "BSpline";
53 |
54 | public static final String FINAL_RESAMPLER_LINEAR = "FinalLinearInterpolator";
55 | public static final String FINAL_RESAMPLER_NEAREST_NEIGHBOR = "FinalNearestNeighborInterpolator";
56 |
57 | List parameters;
58 | private int nChannels;
59 |
60 | public ElastixParameters( TransformationType transformationType, int nChannels )
61 | {
62 | this.nChannels = nChannels;
63 | this.parameters = new ArrayList<>();
64 | addParameter("Transform", transformationType.toString() + "Transform", false, false );
65 | }
66 |
67 | public void addParameter(
68 | String key,
69 | String value,
70 | boolean isMultiChannelParameter,
71 | boolean isNumeric )
72 | {
73 | String keyValues = "(KEY VALUES)";
74 |
75 | keyValues = setKey( key, keyValues );
76 | keyValues = setValues( value, keyValues, isMultiChannelParameter, isNumeric );
77 |
78 | parameters.add( keyValues );
79 | }
80 |
81 | public void writeParameterFile( String parameterFilePath ) {
82 | System.out.println( "Number of parameters: " + parameters.size() );
83 | System.out.println( "Writing parameter file: " + parameterFilePath );
84 | Utils.saveStringListToFile( parameters, parameterFilePath );
85 | }
86 |
87 | private String setValues( String value, String keyValues, boolean isMultiChannelParameter, boolean isNumeric )
88 | {
89 | String values = "";
90 |
91 | // int n = isMultiChannelParameter ? settings.fixedToMovingChannel.size() : 1;
92 | int n = isMultiChannelParameter ? nChannels : 1;
93 |
94 | for ( int c = 0; c < n; ++c )
95 | if ( isNumeric )
96 | values += value + " ";
97 | else
98 | values += "\"" + value + "\"" + " ";
99 |
100 |
101 | return keyValues.replace( "VALUES", values );
102 |
103 | }
104 |
105 | private String setKey( String key, String keyValues )
106 | {
107 | return keyValues.replace( "KEY", key );
108 | }
109 |
110 | }
111 |
--------------------------------------------------------------------------------
/src/main/java/de/embl/cba/elastix/wrapper/transformix/TransformixWrapper.java:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * Fiji distribution of ImageJ for the life sciences.
4 | * %%
5 | * Copyright (C) 2017 - 2025 EMBL
6 | * %%
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are met:
9 | *
10 | * 1. Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * 2. Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | * POSSIBILITY OF SUCH DAMAGE.
27 | * #L%
28 | */
29 | package de.embl.cba.elastix.wrapper.transformix;
30 |
31 | import bdv.util.Bdv;
32 | import de.embl.cba.elastix.commandline.TransformixCaller;
33 | import de.embl.cba.elastix.commandline.settings.TransformixSettings;
34 | import de.embl.cba.elastix.utils.BdvImagePlusExport;
35 | import de.embl.cba.elastix.wrapper.transformix.TransformixWrapperSettings.OutputModality;
36 | import de.embl.cba.elastix.utils.Utils;
37 | import de.embl.cba.elastix.wrapper.BdvManager;
38 | import de.embl.cba.elastix.wrapper.StagingManager;
39 | import ij.IJ;
40 | import ij.ImagePlus;
41 | import ij.io.FileSaver;
42 |
43 | import java.io.File;
44 | import java.util.ArrayList;
45 |
46 | import static de.embl.cba.elastix.utils.Utils.loadMetaImage;
47 |
48 | public class TransformixWrapper {
49 |
50 | public static final String TRANSFORMIX_INPUT_FILENAME = "to_be_transformed";
51 | public static final String TRANSFORMIX_OUTPUT_FILENAME = "result";
52 |
53 | private TransformixWrapperSettings settings;
54 | private StagingManager stagingManager;
55 | private ArrayList< String > transformedImageFilePaths;
56 |
57 | public TransformixWrapper( TransformixWrapperSettings settings ) {
58 | this.settings = settings;
59 | this.transformedImageFilePaths = new ArrayList<>( );
60 | this.stagingManager = new StagingManager( settings );
61 | }
62 |
63 | public void runTransformix()
64 | {
65 | stagingManager.createOrEmptyWorkingDir();
66 |
67 | settings.stagedMovingImageFilePaths = stagingManager.stageImageAsMhd(
68 | settings.movingImageFilePath, TRANSFORMIX_INPUT_FILENAME );
69 |
70 | transformImagesAndHandleOutput();
71 | }
72 |
73 | public void transformImagesAndHandleOutput() {
74 | for ( int c = 0; c < settings.stagedMovingImageFilePaths.size(); c++ )
75 | transformImageAndHandleOutput( c );
76 | }
77 |
78 | private void transformImageAndHandleOutput( int movingFileIndex )
79 | {
80 | TransformixSettings transformixSettings = new TransformixSettings( settings, movingFileIndex );
81 | new TransformixCaller( transformixSettings ).callTransformix();
82 |
83 | String transformedImageFileName = TRANSFORMIX_OUTPUT_FILENAME
84 | + "."
85 | + StagingManager.STAGING_FILE_TYPE;
86 |
87 | ImagePlus result = loadMetaImage(
88 | settings.tmpDir,
89 | transformedImageFileName );
90 |
91 | if ( result == null )
92 | {
93 | Utils.logErrorAndExit( settings,"The transformed image could not be loaded: "
94 | + settings.tmpDir + File.separator + transformedImageFileName + "\n" +
95 | "Please check the log: " + settings.tmpDir + File.separator + "elastix.log" );
96 |
97 | }
98 |
99 | if ( settings.outputModality.equals( OutputModality.Show_images ) )
100 | {
101 | result.show();
102 | result.setTitle( "transformed-ch" + movingFileIndex );
103 | }
104 | else
105 | {
106 | String outputFile = settings.outputFile.toString();
107 | outputFile = outputFile.replace( ".tif", "" );
108 | outputFile = outputFile.replace( ".xml", "" );
109 |
110 | if ( settings.outputModality.equals( OutputModality.Save_as_tiff ) )
111 | {
112 | final String path = outputFile + "-ch" + movingFileIndex + ".tif";
113 |
114 | transformedImageFilePaths.add( path );
115 |
116 | settings.logService.info( "\nSaving transformed image: " + path );
117 |
118 | new FileSaver( result ).saveAsTiff( path );
119 | }
120 | else if ( settings.outputModality.equals( OutputModality.Save_as_bdv) )
121 | {
122 | String path;
123 | if ( settings.stagedMovingImageFilePaths.size() > 1 )
124 | path = outputFile + "-ch" + movingFileIndex + ".xml";
125 | else
126 | path = outputFile + ".xml";
127 |
128 | settings.logService.info( "\nSaving transformed image: " + path );
129 |
130 | BdvImagePlusExport.saveAsBdv( result, new File( path ) );
131 | }
132 | }
133 |
134 | }
135 |
136 | public Bdv showTransformedImages( BdvManager bdvManager )
137 | {
138 | Bdv bdv = null;
139 | for ( int i = 0; i < transformedImageFilePaths.size(); i++ )
140 | {
141 | bdv = showTransformedImage( bdvManager, i );
142 | }
143 | return bdv;
144 | }
145 |
146 | public Bdv showTransformedImage( BdvManager bdvManager, int imageIndex )
147 | {
148 | ImagePlus imagePlus = IJ.openImage( transformedImageFilePaths.get( imageIndex ) );
149 | return bdvManager.showImagePlusInBdv( imagePlus );
150 | }
151 |
152 | }
153 |
--------------------------------------------------------------------------------
/src/main/java/de/embl/cba/elastix/wrapper/transformix/TransformixWrapperSettings.java:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * Fiji distribution of ImageJ for the life sciences.
4 | * %%
5 | * Copyright (C) 2017 - 2025 EMBL
6 | * %%
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are met:
9 | *
10 | * 1. Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * 2. Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | * POSSIBILITY OF SUCH DAMAGE.
27 | * #L%
28 | */
29 | package de.embl.cba.elastix.wrapper.transformix;
30 |
31 | import de.embl.cba.elastix.commandline.settings.Settings;
32 |
33 | import java.io.File;
34 | import java.util.ArrayList;
35 |
36 | public class TransformixWrapperSettings extends Settings {
37 |
38 | public enum OutputModality
39 | {
40 | Show_images,
41 | Save_as_tiff,
42 | Save_as_bdv
43 | }
44 |
45 | public static final String OUTPUT_MODALITY_SHOW_IMAGES
46 | = "Show images";
47 | public static final String OUTPUT_MODALITY_SAVE_AS_TIFF
48 | = "Save as Tiff";
49 | public static final String OUTPUT_MODALITY_SAVE_AS_BDV
50 | = "Save as BigDataViewer .xml/.h5";
51 |
52 | public TransformixWrapperSettings() {}
53 |
54 | public String transformationFilePath;
55 |
56 | // before staging
57 | public String movingImageFilePath = "";
58 | // after staging - in order of channels
59 | public ArrayList stagedMovingImageFilePaths;
60 |
61 | public OutputModality outputModality;
62 | public File outputFile;
63 | }
64 |
--------------------------------------------------------------------------------
/src/test/java/ExampleElastixAPI.java:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * Fiji distribution of ImageJ for the life sciences.
4 | * %%
5 | * Copyright (C) 2017 - 2025 EMBL
6 | * %%
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are met:
9 | *
10 | * 1. Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * 2. Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | * POSSIBILITY OF SUCH DAMAGE.
27 | * #L%
28 | */
29 | import de.embl.cba.elastix.wrapper.elastix.ElastixWrapperSettings;
30 | import de.embl.cba.elastix.wrapper.elastix.ElastixWrapper;
31 |
32 | import de.embl.cba.elastix.wrapper.elastix.parameters.ElastixParameters;
33 | import net.imagej.ImageJ;
34 |
35 | public class ExampleElastixAPI
36 | {
37 | public static void main( String[] args )
38 | {
39 | final ImageJ ij = new ImageJ();
40 | ij.ui().showUI();
41 |
42 | ElastixWrapperSettings settings = new ElastixWrapperSettings();
43 |
44 | settings.logService = ij.log();
45 | settings.elastixDirectory = "/Applications/elastix_macosx64_v4.8" ;
46 | settings.tmpDir = "/Users/tischer/Desktop/elastix-tmp";
47 | settings.transformationType = ElastixParameters.TransformationType.Euler;
48 | settings.fixedImageFilePath = getImageFilePath( "test-data/fluo01/ellipsoid-horizontal-dxyz200nm.tif" );
49 | settings.movingImageFilePath = getImageFilePath( "test-data/fluo01/ellipsoid-at45degrees-dxyz200nm.tif" );
50 | settings.downSamplingFactors = "10 10 10";
51 | settings.fixedMaskPath = "";
52 | settings.movingMaskPath = "";
53 | // settings.bSplineGridSpacing = "50 50 50";
54 | // settings.iterations = 1000;
55 | // settings.spatialSamples = 10000;
56 | // settings.channelWeights = new double[]{1.0, 3.0, 3.0, 1.0, 1.0};
57 | // settings.finalResampler = ElastixSettings.FINAL_RESAMPLER_LINEAR;
58 |
59 | final ElastixWrapper elastixWrapper = new ElastixWrapper( settings );
60 | elastixWrapper.runElastix();
61 | elastixWrapper.reviewResults();
62 |
63 | settings.logService.info( "Done!" );
64 | }
65 |
66 | private static String getImageFilePath( String relativePath )
67 | {
68 | return ExampleElastixAPI.class.getResource( relativePath ).getFile().toString();
69 | }
70 |
71 | }
72 |
--------------------------------------------------------------------------------
/src/test/java/ExampleTransformixAPI.java:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * Fiji distribution of ImageJ for the life sciences.
4 | * %%
5 | * Copyright (C) 2017 - 2025 EMBL
6 | * %%
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are met:
9 | *
10 | * 1. Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * 2. Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | * POSSIBILITY OF SUCH DAMAGE.
27 | * #L%
28 | */
29 | import de.embl.cba.elastix.wrapper.StagingManager;
30 | import de.embl.cba.elastix.wrapper.transformix.TransformixWrapper;
31 | import de.embl.cba.elastix.wrapper.transformix.TransformixWrapperSettings;
32 | import de.embl.cba.metaimage_io.MetaImage_Reader;
33 | import ij.IJ;
34 | import ij.ImagePlus;
35 | import net.imagej.ImageJ;
36 |
37 | public class ExampleTransformixAPI
38 | {
39 | public static void main( String[] args )
40 | {
41 |
42 | final ImageJ ij = new ImageJ();
43 | ij.ui().showUI();
44 |
45 | final String inputImagePath =
46 | "/Users/tischer/Documents/rachel-mellwig-em-prospr-registration/data/FIB segmentation/muscle.tif";
47 |
48 | IJ.open( inputImagePath );
49 |
50 | TransformixWrapperSettings settings = new TransformixWrapperSettings();
51 |
52 | settings.logService = ij.log();
53 | settings.elastixDirectory = "/Applications/elastix_macosx64_v4.8" ;
54 | settings.tmpDir = "/Users/tischer/Desktop/elastix-tmp";
55 | settings.movingImageFilePath = inputImagePath;
56 | settings.transformationFilePath = "/Users/tischer/Desktop/transform.txt";
57 |
58 | final TransformixWrapper transformixWrapper = new TransformixWrapper( settings );
59 | transformixWrapper.runTransformix();
60 |
61 | MetaImage_Reader reader = new MetaImage_Reader();
62 | final ImagePlus transformed = reader.load(
63 | settings.tmpDir,
64 | StagingManager.TRANSFORMIX_OUTPUT_FILENAME
65 | + "." + StagingManager.STAGING_FILE_TYPE,
66 | false );
67 |
68 | transformed.show();
69 |
70 | settings.logService.info( "Done!" );
71 | }
72 |
73 | }
74 |
--------------------------------------------------------------------------------
/src/test/java/TimElastixAPI.java:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * Fiji distribution of ImageJ for the life sciences.
4 | * %%
5 | * Copyright (C) 2017 - 2025 EMBL
6 | * %%
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are met:
9 | *
10 | * 1. Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * 2. Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | * POSSIBILITY OF SUCH DAMAGE.
27 | * #L%
28 | */
29 | import bdv.util.Bdv;
30 | import de.embl.cba.elastix.wrapper.elastix.ElastixWrapperSettings;
31 | import de.embl.cba.elastix.wrapper.elastix.ElastixWrapper;
32 | import de.embl.cba.elastix.wrapper.elastix.parameters.ElastixParameters;
33 | import net.imagej.ImageJ;
34 |
35 | public class TimElastixAPI
36 | {
37 | public static void main( String[] args )
38 | {
39 |
40 | final ImageJ ij = new ImageJ();
41 | ij.ui().showUI();
42 |
43 | ElastixWrapperSettings settings = new ElastixWrapperSettings();
44 |
45 | settings.logService = ij.log();
46 | settings.elastixDirectory = "/Applications/elastix_macosx64_v4.8" ;
47 | settings.tmpDir = "/Users/tischer/Desktop/elastix-tmp";
48 | settings.transformationType = ElastixParameters.TransformationType.Affine;
49 | settings.fixedImageFilePath = "/Users/tischer/Desktop/3dtemplate.tif";
50 | settings.movingImageFilePath = "/Users/tischer/Desktop/3dstg16.tif";
51 |
52 | /**
53 | * You want to match the first channel (0) in the fixed image,
54 | * - which has only one channel -
55 | * to the second channel (1) in the moving image
56 | * - which has two channels -
57 | */
58 | settings.fixedToMovingChannel.put( 1, 1 );
59 |
60 | settings.downSamplingFactors = "10 10 10";
61 | // settings.fixedMaskPath = "";
62 | // settings.movingMaskPath = "";
63 | // settings.bSplineGridSpacing = "50 50 50";
64 | settings.iterations = 1000;
65 | settings.spatialSamples = "10000";
66 | // settings.channelWeights = new double[]{1.0, 3.0, 3.0, 1.0, 1.0};
67 | // settings.finalResampler = ElastixSettings.FINAL_RESAMPLER_LINEAR;
68 |
69 | final ElastixWrapper elastixWrapper = new ElastixWrapper( settings );
70 | elastixWrapper.runElastix();
71 | final Bdv bdv = elastixWrapper.reviewResults();
72 | //bdv.close();
73 |
74 | settings.logService.info( "Done!" );
75 | }
76 |
77 | private static String getImageFilePath( String relativePath )
78 | {
79 | return TimElastixAPI.class.getResource( relativePath ).getFile().toString();
80 | }
81 |
82 | }
83 |
--------------------------------------------------------------------------------
/src/test/java/command/RunElastixCommand.java:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * Fiji distribution of ImageJ for the life sciences.
4 | * %%
5 | * Copyright (C) 2017 - 2025 EMBL
6 | * %%
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are met:
9 | *
10 | * 1. Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * 2. Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | * POSSIBILITY OF SUCH DAMAGE.
27 | * #L%
28 | */
29 | package command;
30 |
31 | import de.embl.cba.elastix.commands.ElastixCommand;
32 | import net.imagej.ImageJ;
33 |
34 | public class RunElastixCommand
35 | {
36 | public static void main(final String... args)
37 | {
38 | final ImageJ ij = new ImageJ();
39 | ij.ui().showUI();
40 | ij.command().run( ElastixCommand.class, true );
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/test/java/command/RunTransformixCommand.java:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * Fiji distribution of ImageJ for the life sciences.
4 | * %%
5 | * Copyright (C) 2017 - 2025 EMBL
6 | * %%
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are met:
9 | *
10 | * 1. Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * 2. Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | * POSSIBILITY OF SUCH DAMAGE.
27 | * #L%
28 | */
29 | package command;
30 |
31 | import de.embl.cba.elastix.commands.TransformixCommand;
32 | import net.imagej.ImageJ;
33 |
34 | public class RunTransformixCommand
35 | {
36 | public static void main(final String... args)
37 | {
38 | final ImageJ ij = new ImageJ();
39 | ij.ui().showUI();
40 | ij.command().run( TransformixCommand.class, true );
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/test/java/explore/ExploreSimpleElastix.txt:
--------------------------------------------------------------------------------
1 | package explore;
2 |
3 | import org.apache.ivy.core.sort.SilentNonMatchingVersionReporter;
4 | import org.itk.simple.ElastixImageFilter;
5 | import org.itk.simple.Image;
6 | import org.itk.simple.SimpleITK;
7 |
8 | public class ExploreSimpleElastix {
9 |
10 | public static final String ROOT_DIR = "/Users/tischer/Documents/fiji-plugin-elastixWrapper/src/test/resources";
11 |
12 | public static void main( String[] args )
13 | {
14 | // gaussianBlur();
15 | runElastix();
16 | }
17 |
18 | private static void runElastix()
19 | {
20 | final ElastixImageFilter elastix = new ElastixImageFilter();
21 | Image fixed = SimpleITK.readImage(ROOT_DIR + "/test-data/sbem.mhd" );
22 | Image moving = SimpleITK.readImage(ROOT_DIR + "/test-data/sbem.mhd" );
23 | elastix.setFixedImage( fixed );
24 | elastix.setMovingImage( fixed );
25 | elastix.setParameterMap( SimpleITK.getDefaultParameterMap("rigid") );
26 | elastix.execute();
27 | final Image resultImage = elastix.getResultImage();
28 | }
29 |
30 | private static void gaussianBlur()
31 | {
32 | Image image = SimpleITK.readImage(ROOT_DIR + "/test-data/sbem.mhd" );
33 | Image output = SimpleITK.discreteGaussian(image);
34 | SimpleITK.writeImage(output, ROOT_DIR + "/tmp/sbem-blur.mhd");
35 | }
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/src/test/java/explore/ExploreTmpDir.java:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * Fiji distribution of ImageJ for the life sciences.
4 | * %%
5 | * Copyright (C) 2017 - 2025 EMBL
6 | * %%
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are met:
9 | *
10 | * 1. Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * 2. Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | * POSSIBILITY OF SUCH DAMAGE.
27 | * #L%
28 | */
29 | package explore;
30 |
31 | public class ExploreTmpDir
32 | {
33 | public static void main( String[] args )
34 | {
35 | System.out.println(System.getProperty("java.io.tmpdir"));
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/test/java/tests/TestElastix.java:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * Fiji distribution of ImageJ for the life sciences.
4 | * %%
5 | * Copyright (C) 2017 - 2025 EMBL
6 | * %%
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are met:
9 | *
10 | * 1. Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * 2. Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | * POSSIBILITY OF SUCH DAMAGE.
27 | * #L%
28 | */
29 | package tests;
30 |
31 | import de.embl.cba.elastix.wrapper.elastix.ElastixWrapperSettings;
32 | import de.embl.cba.elastix.wrapper.elastix.ElastixWrapper;
33 | import de.embl.cba.elastix.wrapper.elastix.parameters.ElastixParameters;
34 | import net.imagej.ImageJ;
35 |
36 | import java.io.File;
37 |
38 | public class TestElastix
39 | {
40 | // FIXME:
41 | // 1. Make this test headless
42 | // 2. Add an actual test (assert)
43 | // 3. Make this also run in the GitHub actions
44 |
45 | //@Test
46 | public static void registerEulerSingleChannelImage()
47 | {
48 | final ImageJ ij = new ImageJ();
49 | ij.ui().showUI();
50 |
51 | ElastixWrapperSettings settings = new ElastixWrapperSettings();
52 |
53 | settings.logService = ij.log();
54 | settings.elastixDirectory = "/Applications/elastix-5.2.0-mac" ;
55 | settings.tmpDir = new File("src/test/resources/test-data/fluo01/tmp").getAbsolutePath();
56 | settings.transformationType = ElastixParameters.TransformationType.Euler;
57 | settings.fixedImageFilePath = new File("src/test/resources/test-data/fluo01/ellipsoid-horizontal-dxyz200nm.tif").getAbsolutePath();
58 | settings.movingImageFilePath = new File("src/test/resources/test-data/fluo01/ellipsoid-at45degrees-dxyz200nm.tif").getAbsolutePath();
59 | settings.downSamplingFactors = "10 10";
60 | settings.fixedMaskPath = "";
61 | settings.movingMaskPath = "";
62 |
63 | final ElastixWrapper elastixWrapper = new ElastixWrapper( settings );
64 | elastixWrapper.runElastix();
65 |
66 | // Bdv
67 | elastixWrapper.reviewResults();
68 |
69 | // ImageJ
70 | elastixWrapper.reviewResultsInImageJ();
71 |
72 | // Save as Tiff
73 | elastixWrapper.createTransformedImagesAndSaveAsTiff();
74 |
75 | settings.logService.info( "Done!" );
76 | }
77 |
78 | public static void main( String[] args )
79 | {
80 | new TestElastix().registerEulerSingleChannelImage();
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/src/test/java/tests/TestElastixAndTransformixCLEM.java:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * Fiji distribution of ImageJ for the life sciences.
4 | * %%
5 | * Copyright (C) 2017 - 2025 EMBL
6 | * %%
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are met:
9 | *
10 | * 1. Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * 2. Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | * POSSIBILITY OF SUCH DAMAGE.
27 | * #L%
28 | */
29 | package tests;
30 |
31 | import de.embl.cba.elastix.wrapper.elastix.ElastixWrapperSettings;
32 | import de.embl.cba.elastix.wrapper.elastix.ElastixWrapper;
33 | import de.embl.cba.elastix.wrapper.elastix.parameters.ElastixParameters;
34 | import de.embl.cba.elastix.wrapper.transformix.TransformixWrapper;
35 | import de.embl.cba.elastix.wrapper.transformix.TransformixWrapperSettings;
36 | import net.imagej.ImageJ;
37 |
38 | import java.io.File;
39 |
40 |
41 | public class TestElastixAndTransformixCLEM
42 | {
43 | //@Test
44 | public void registerFluoToEM()
45 | {
46 | final ImageJ ij = new ImageJ();
47 | ij.ui().showUI();
48 |
49 | ElastixWrapperSettings settings = new ElastixWrapperSettings();
50 |
51 | settings.logService = ij.log();
52 | settings.elastixDirectory = "/Applications/elastix-5.2.0-mac" ;
53 | settings.tmpDir = "/Users/tischer/Documents/elastixWrapper/src/test/resources/test-data/clem/tmp";
54 | settings.transformationType = ElastixParameters.TransformationType.BSpline;
55 | settings.fixedImageFilePath = "/Users/tischer/Documents/elastixWrapper/src/test/resources/test-data/clem/em.tif";
56 | settings.movingImageFilePath = "/Users/tischer/Documents/elastixWrapper/src/test/resources/test-data/clem/fluo_green.tif";
57 | settings.downSamplingFactors = "2 2";
58 | settings.bSplineGridSpacing = "100 100";
59 | settings.fixedMaskPath = "";
60 | settings.movingMaskPath = "";
61 |
62 | final ElastixWrapper elastixWrapper = new ElastixWrapper( settings );
63 | elastixWrapper.runElastix();
64 |
65 | // Bdv
66 | elastixWrapper.reviewResults();
67 |
68 | settings.logService.info( "Done!" );
69 | }
70 |
71 | //@Test
72 | public void transformTwoChannelFluo()
73 | {
74 | TransformixWrapperSettings settings = new TransformixWrapperSettings();
75 |
76 | final ImageJ ij = new ImageJ();
77 |
78 | settings.logService = ij.log();
79 | settings.elastixDirectory = "/Applications/elastix_macosx64_v4.8" ;
80 | settings.tmpDir = "/Users/tischer/Desktop/elastix-tmp";
81 | settings.movingImageFilePath = "/Users/tischer/Documents/fiji-plugin-elastixWrapper/src/test/resources/test-data/clem/fluo_red_green.tif";
82 | settings.transformationFilePath = "/Users/tischer/Documents/fiji-plugin-elastixWrapper/src/test/resources/test-data/clem/tmp/TransformParameters.0.txt";
83 |
84 | settings.outputModality = TransformixWrapperSettings.OutputModality.Save_as_tiff;
85 | settings.outputFile = new File( "/Users/tischer/Documents/fiji-plugin-elastixWrapper/src/test/resources/test-data/clem/aligned" );
86 |
87 | final TransformixWrapper transformixWrapper = new TransformixWrapper( settings );
88 |
89 | transformixWrapper.runTransformix();
90 |
91 | settings.logService.info( "Done!" );
92 | }
93 |
94 |
95 | public static void main( String[] args )
96 | {
97 | new TestElastixAndTransformixCLEM().registerFluoToEM();
98 | new TestElastixAndTransformixCLEM().transformTwoChannelFluo();
99 | }
100 |
101 |
102 |
103 | }
104 |
--------------------------------------------------------------------------------
/src/test/java/tests/TestTransformix.java:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * Fiji distribution of ImageJ for the life sciences.
4 | * %%
5 | * Copyright (C) 2017 - 2025 EMBL
6 | * %%
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are met:
9 | *
10 | * 1. Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * 2. Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | * POSSIBILITY OF SUCH DAMAGE.
27 | * #L%
28 | */
29 | package tests;
30 |
31 | import de.embl.cba.elastix.wrapper.transformix.TransformixWrapper;
32 | import de.embl.cba.elastix.wrapper.transformix.TransformixWrapperSettings;
33 | import net.imagej.ImageJ;
34 |
35 | import java.io.File;
36 |
37 | public class TestTransformix
38 | {
39 | //@Test
40 | public void registerSingleChannelImageAndSaveAsTiff()
41 | {
42 | TransformixWrapperSettings settings = new TransformixWrapperSettings();
43 |
44 | final ImageJ ij = new ImageJ();
45 |
46 | settings.logService = ij.log();
47 | settings.elastixDirectory = "/Applications/elastix_macosx64_v4.8" ;
48 | settings.tmpDir = "/Users/tischer/Desktop/elastix-tmp";
49 | settings.movingImageFilePath = "/Users/tischer/Documents/elastixWrapper/src/test/resources/test-data/fluo01/ellipsoid-at45degrees-dxyz200nm.tif";
50 | settings.transformationFilePath = "/Users/tischer/Documents/elastixWrapper/src/test/resources/test-data/fluo01/tmp/TransformParameters.0.txt";
51 | settings.outputModality = TransformixWrapperSettings.OutputModality.Save_as_tiff;
52 | settings.outputFile = new File( "/Users/tischer/Documents/elastixWrapper/src/test/resources/test-data/fluo01/transformed-ellipsoid" );
53 |
54 | final TransformixWrapper transformixWrapper = new TransformixWrapper( settings );
55 |
56 | transformixWrapper.runTransformix();
57 |
58 | settings.logService.info( "Done!" );
59 | }
60 |
61 | public static void main( String[] args )
62 | {
63 | new TestTransformix().registerSingleChannelImageAndSaveAsTiff();
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/src/test/java/users/rachel/RachelParapodRegistration.java:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * Fiji distribution of ImageJ for the life sciences.
4 | * %%
5 | * Copyright (C) 2017 - 2025 EMBL
6 | * %%
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are met:
9 | *
10 | * 1. Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * 2. Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | * POSSIBILITY OF SUCH DAMAGE.
27 | * #L%
28 | */
29 | package users.rachel;
30 |
31 | import bdv.util.Bdv;
32 | import de.embl.cba.elastix.wrapper.elastix.ElastixWrapperSettings;
33 | import de.embl.cba.elastix.wrapper.elastix.ElastixWrapper;
34 | import de.embl.cba.elastix.wrapper.elastix.parameters.ElastixParameters;
35 | import net.imagej.ImageJ;
36 |
37 | public class RachelParapodRegistration
38 | {
39 | public static void main( String[] args )
40 | {
41 | final ImageJ ij = new ImageJ();
42 | ij.ui().showUI();
43 |
44 | ElastixWrapperSettings settings = new ElastixWrapperSettings();
45 |
46 | settings.logService = ij.log();
47 | settings.elastixDirectory = "/Applications/elastix_macosx64_v4.8" ;
48 | settings.tmpDir = "/Users/tischer/Desktop/elastix-tmp";
49 |
50 | settings.fixedImageFilePath = "/Users/tischer/Documents/rachel-mellwig-em-prospr-registration/data/ganglion-segmentation/spem-seg-ganglion.tif";
51 |
52 | settings.movingImageFilePath = "/Users/tischer/Documents/rachel-mellwig-em-prospr-registration/data/ganglion-segmentation/fib-sem-seg-ganglion.tif";
53 |
54 | settings.fixedMaskPath = "/Users/tischer/Documents/rachel-mellwig-em-prospr-registration/data/ganglion-segmentation/spem-mask-ganglion.tif";
55 |
56 | settings.initialTransformationFilePath = "/Users/tischer/Documents/rachel-mellwig-em-prospr-registration/data/ganglion-segmentation/amira-transform.txt";
57 |
58 | settings.transformationType = ElastixParameters.TransformationType.Affine;
59 | settings.downSamplingFactors = "10 10 10; 2, 2, 2";
60 | // settings.movingMaskPath = "";
61 | // settings.bSplineGridSpacing = "50 50 50";
62 | settings.iterations = 1000;
63 | settings.spatialSamples = "10000; 10000";
64 | settings.channelWeights = new double[]{1.0, 1.0, 3.0, 1.0, 1.0};
65 | // settings.finalResampler = ElastixSettings.FINAL_RESAMPLER_LINEAR;
66 |
67 | final ElastixWrapper elastixWrapper = new ElastixWrapper( settings );
68 | elastixWrapper.runElastix();
69 |
70 | final Bdv bdv = elastixWrapper.reviewResults();
71 | //bdv.close();
72 |
73 | settings.logService.info( "Done!" );
74 | }
75 |
76 | private static String getImageFilePath( String relativePath )
77 | {
78 | return RachelParapodRegistration.class.getResource( relativePath ).getFile().toString();
79 | }
80 |
81 | }
82 |
--------------------------------------------------------------------------------
/src/test/java/users/sultan/TransformXRayDataUsingAmiraEulerTransform.java:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * Fiji distribution of ImageJ for the life sciences.
4 | * %%
5 | * Copyright (C) 2017 - 2025 EMBL
6 | * %%
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are met:
9 | *
10 | * 1. Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * 2. Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | * POSSIBILITY OF SUCH DAMAGE.
27 | * #L%
28 | */
29 | package users.sultan;
30 |
31 | import de.embl.cba.elastix.utils.BatchApplyAmiraTransformationsToBdvXml;
32 |
33 | import java.io.IOException;
34 |
35 | public class TransformXRayDataUsingAmiraEulerTransform
36 | {
37 | public static void main( String[] args ) throws IOException
38 | {
39 | final BatchApplyAmiraTransformationsToBdvXml applyAmira = new BatchApplyAmiraTransformationsToBdvXml(
40 | new double[]{ -0.27, 0.81, 0.51 },
41 | 71.7,
42 | new double[]{ -54.6, 2.59, 53.39 },
43 | "/Volumes/cba/exchange/Sultan",
44 | ".*-transform.xml"
45 | );
46 |
47 | applyAmira.run();
48 | }
49 |
50 | }
51 |
--------------------------------------------------------------------------------
/src/test/java/users/sultan/TransformXRayUsingAmiraEulerViaElastix.java:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * Fiji distribution of ImageJ for the life sciences.
4 | * %%
5 | * Copyright (C) 2017 - 2025 EMBL
6 | * %%
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are met:
9 | *
10 | * 1. Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * 2. Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 | * POSSIBILITY OF SUCH DAMAGE.
27 | * #L%
28 | */
29 | package users.sultan;
30 |
31 | import de.embl.cba.elastix.wrapper.transformix.TransformixWrapper;
32 | import de.embl.cba.elastix.wrapper.transformix.TransformixWrapperSettings;
33 | import ij.IJ;
34 | import ij.ImagePlus;
35 | import itc.converters.AffineTransform3DToElastixAffine3D;
36 | import itc.converters.AmiraEulerToAffineTransform3D;
37 | import itc.transforms.elastix.ElastixAffineTransform3D;
38 | import itc.transforms.elastix.ElastixTransform;
39 | import net.imagej.ImageJ;
40 | import net.imglib2.realtransform.AffineTransform3D;
41 |
42 | public class TransformXRayUsingAmiraEulerViaElastix
43 | {
44 | public static void main( String[] args )
45 | {
46 | final ImageJ imageJ = new ImageJ();
47 | imageJ.ui().showUI();
48 |
49 | final String xRayPath = "/Users/tischer/Documents/sultan-schwab/platy_90_02_neuropile_1um.tif";
50 | final ImagePlus xRayImp = IJ.openImage( xRayPath );
51 |
52 | double[] translationInMicrometer = new double[]{ -54.6, 2.59, 53.39 };
53 | double[] rotationAxis = new double[]{ -0.27, 0.81, 0.51 };
54 | double rotationAngleDegrees = 71.7;
55 |
56 | final double[] imageVoxelSizeInMicrometer = { 1.0, 1.0, 1.0 };
57 |
58 | final double[] rotationCentreInMicrometer = new double[ 3 ];
59 | rotationCentreInMicrometer[ 0 ] = xRayImp.getWidth() / 2.0 * imageVoxelSizeInMicrometer[ 0 ];
60 | rotationCentreInMicrometer[ 1 ] = xRayImp.getHeight() / 2.0 * imageVoxelSizeInMicrometer[ 1 ];
61 | rotationCentreInMicrometer[ 2 ] = xRayImp.getNSlices() / 2.0 * imageVoxelSizeInMicrometer[ 1 ];
62 |
63 | final AffineTransform3D affineTransform3DInMillimeter =
64 | AmiraEulerToAffineTransform3D.convert(
65 | rotationAxis,
66 | rotationAngleDegrees,
67 | translationInMicrometer,
68 | rotationCentreInMicrometer );
69 |
70 |
71 | /**
72 | * This must be the dimensions of the image that we would like to produce
73 | * with transformix, e.g. the dimensions of the image that we would like to match,
74 | * using this transform as an initial transform, here this is this one:
75 | * /Volumes/cba/exchange/Sultan/prospr_neuropile_0.4um.tif
76 | *
77 | */
78 |
79 | final AffineTransform3DToElastixAffine3D affineTransform3DToElastixAffine3D
80 | = new AffineTransform3DToElastixAffine3D(
81 | ElastixTransform.FINAL_LINEAR_INTERPOLATOR,
82 | ElastixTransform.RESULT_IMAGE_PIXEL_TYPE_UNSIGNED_CHAR,
83 | new Double[]{ 0.0004, 0.0004, 0.0004 },
84 | new Integer[]{ 687, 648, 713 }
85 | );
86 |
87 | // invert, because elastix transform goes from output to input
88 | final AffineTransform3D inverse = affineTransform3DInMillimeter.inverse();
89 |
90 | final ElastixAffineTransform3D elastixAffineTransform3D
91 | = affineTransform3DToElastixAffine3D.convert( inverse );
92 |
93 | final String elastixTransformPath =
94 | "/Users/tischer/Desktop/elastix-affine-transform.txt";
95 | elastixAffineTransform3D.save( elastixTransformPath );
96 |
97 |
98 | TransformixWrapperSettings settings = new TransformixWrapperSettings();
99 |
100 | settings.logService = imageJ.log();
101 | settings.elastixDirectory = "/Applications/elastix_macosx64_v4.8";
102 | settings.tmpDir = "/Users/tischer/Desktop/elastix-tmp/";
103 | settings.movingImageFilePath = xRayPath;
104 | settings.transformationFilePath = elastixTransformPath;
105 | settings.numWorkers = 4;
106 | settings.outputModality = TransformixWrapperSettings.OutputModality.Show_images;
107 | // settings.outputFile = outputFile;
108 |
109 | TransformixWrapper transformixWrapper = new TransformixWrapper( settings );
110 | transformixWrapper.runTransformix();
111 |
112 |
113 |
114 | }
115 |
116 | }
117 |
--------------------------------------------------------------------------------
/src/test/resources/2d-movie--affine--crop.tif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/embl-cba/elastix-wrapper/23bf891e9630f87d20028adeb8b1fcaf0f576775/src/test/resources/2d-movie--affine--crop.tif
--------------------------------------------------------------------------------
/src/test/resources/2d-movie--affine.mhd:
--------------------------------------------------------------------------------
1 | ObjectType = Image
2 | NDims = 3
3 | BinaryData = True
4 | BinaryDataByteOrderMSB = True
5 | DimSize = 512 512 11
6 | ElementSize = 1.0 1.0 1.0
7 | ElementType = MET_UCHAR
8 | ElementDataFile = 2d-movie--affine.raw
9 |
--------------------------------------------------------------------------------
/src/test/resources/2d-movie--affine.raw:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/embl-cba/elastix-wrapper/23bf891e9630f87d20028adeb8b1fcaf0f576775/src/test/resources/2d-movie--affine.raw
--------------------------------------------------------------------------------
/src/test/resources/2d-movie--affine.tif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/embl-cba/elastix-wrapper/23bf891e9630f87d20028adeb8b1fcaf0f576775/src/test/resources/2d-movie--affine.tif
--------------------------------------------------------------------------------
/src/test/resources/Thomas--Platynereis.tif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/embl-cba/elastix-wrapper/23bf891e9630f87d20028adeb8b1fcaf0f576775/src/test/resources/Thomas--Platynereis.tif
--------------------------------------------------------------------------------
/src/test/resources/TransformParameters.45degreeEllispoid.txt:
--------------------------------------------------------------------------------
1 | (Transform "EulerTransform")
2 | (NumberOfParameters 6)
3 | (TransformParameters -0.000071 -0.000138 0.785744 -0.000001 0.000003 -0.000000)
4 | (InitialTransformParametersFileName "NoInitialTransform")
5 | (HowToCombineTransforms "Compose")
6 |
7 | // Image specific
8 | (FixedImageDimension 3)
9 | (MovingImageDimension 3)
10 | (FixedInternalImagePixelType "float")
11 | (MovingInternalImagePixelType "float")
12 | (Size 61 54 100)
13 | (Index 0 0 0)
14 | (Spacing 0.0002000000 0.0002000000 0.0002000000)
15 | (Origin 0.0000000000 0.0000000000 0.0000000000)
16 | (Direction 1.0000000000 0.0000000000 0.0000000000 0.0000000000 1.0000000000 0.0000000000 0.0000000000 0.0000000000 1.0000000000)
17 | (UseDirectionCosines "false")
18 |
19 | // EulerTransform specific
20 | (CenterOfRotationPoint 0.0059999998 0.0052999999 0.0098999997)
21 | (ComputeZYX "false")
22 |
23 | // ResampleInterpolator specific
24 | (ResampleInterpolator "FinalLinearInterpolator")
25 |
26 | // Resampler specific
27 | (Resampler "DefaultResampler")
28 | (DefaultPixelValue 0.000000)
29 | (ResultImageFormat "mhd")
30 | (ResultImagePixelType "unsigned char")
31 | (CompressResultImage "false")
32 |
--------------------------------------------------------------------------------
/src/test/resources/ellipsoid-voxels100x100x100-voxelSizes200x200x200nm.tif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/embl-cba/elastix-wrapper/23bf891e9630f87d20028adeb8b1fcaf0f576775/src/test/resources/ellipsoid-voxels100x100x100-voxelSizes200x200x200nm.tif
--------------------------------------------------------------------------------
/src/test/resources/test-data/big-warp-landmarks.csv:
--------------------------------------------------------------------------------
1 | "Pt-0","true","297.5787400201193","109.44425932190408","82.04744749848706","206.12314685655818","143.6080611875288","45.352926843766284"
2 | "Pt-1","true","299.04720787042214","165.60780391292533","88.18433749034442","166.29169234461943","193.6664958186921","53.31748222951228"
3 | "Pt-2","true","73.30383562160131","121.83420739604622","72.59492226475172","119.1235874277524","74.70475328524704","266.81038921076095"
4 | "Pt-3","true","70.76829604347287","148.64113185053688","72.63175341908182","98.05430550683639","101.42374551867532","271.02412547589313"
5 | "Pt-4","true","264.3103893057476","138.31404179276228","60.53369265857616","158.96187843765966","147.88017388859427","80.8902664389517"
6 |
--------------------------------------------------------------------------------
/src/test/resources/test-data/big-warp-transformations.rtf:
--------------------------------------------------------------------------------
1 | {\rtf1\ansi\ansicpg1252\cocoartf1671\cocoasubrtf600
2 | {\fonttbl\f0\fswiss\fcharset0 Helvetica;}
3 | {\colortbl;\red255\green255\blue255;}
4 | {\*\expandedcolortbl;;}
5 | \paperw11900\paperh16840\margl1440\margr1440\vieww10800\viewh8400\viewkind0
6 | \pard\tx566\tx1133\tx1700\tx2267\tx2834\tx3401\tx3968\tx4535\tx5102\tx5669\tx6236\tx6803\pardirnatural\partightenfactor0
7 |
8 | \f0\fs24 \cf0 Big Warp Transforms\
9 | \
10 | Similarity:\
11 | 3d-affine: (0.2631659750292986, 0.2728152883093439, -0.8421807709743863, 246.3565248635497, -0.5994842563176209, 0.7014132763310869, 0.039887406048063165, 128.0280556665454, 0.6513948564132443, 0.5352982320152232, 0.37695292383424855, -147.204085589971)\
12 | \
13 | Affine:\
14 | 3d-affine: (0.01134177311347223, 0.16657060193977435, -0.9656998551304313, 315.831323585586, -0.46444896764962446, 0.7151510623243773, 0.08750736870578868, 99.16241815030575, 0.9818742042131522, 0.7860775402246405, 0.5782337020321564, -258.7272560955562)\
15 | \
16 | \
17 | \pard\tx566\tx1133\tx1700\tx2267\tx2834\tx3401\tx3968\tx4535\tx5102\tx5669\tx6236\tx6803\pardirnatural\partightenfactor0
18 | \cf0 (0.01134177311347223, 0.16657060193977435, -0.9656998551304313, 315.831323585586, -0.46444896764962446, 0.7151510623243773, 0.08750736870578868, 99.16241815030575, 0.9818742042131522, 0.7860775402246405, 0.5782337020321564, -258.7272560955562)\
19 | \
20 | 0.2631659750292986 0.2728152883093439 -0.8421807709743863 246.3565248635497 -0.5994842563176209 0.7014132763310869 0.039887406048063165 128.0280556665454 0.6513948564132443 0.5352982320152232 0.37695292383424855 -147.204085589971\
21 | \
22 | Inverse:\
23 | \
24 | 0.30853515546731747 -0.7028338986549241 0.763693761215507 126.39165059265875 0.31984798712300605 0.822335236291694 0.6275823583113649 -91.69593281311793 -0.987370708068317 0.04676389880894393 0.44193870026743215 302.3133076115644\
25 | }
--------------------------------------------------------------------------------
/src/test/resources/test-data/clem/aligned-ch0.tif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/embl-cba/elastix-wrapper/23bf891e9630f87d20028adeb8b1fcaf0f576775/src/test/resources/test-data/clem/aligned-ch0.tif
--------------------------------------------------------------------------------
/src/test/resources/test-data/clem/aligned-ch1.tif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/embl-cba/elastix-wrapper/23bf891e9630f87d20028adeb8b1fcaf0f576775/src/test/resources/test-data/clem/aligned-ch1.tif
--------------------------------------------------------------------------------
/src/test/resources/test-data/clem/em.tif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/embl-cba/elastix-wrapper/23bf891e9630f87d20028adeb8b1fcaf0f576775/src/test/resources/test-data/clem/em.tif
--------------------------------------------------------------------------------
/src/test/resources/test-data/clem/fluo_green.tif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/embl-cba/elastix-wrapper/23bf891e9630f87d20028adeb8b1fcaf0f576775/src/test/resources/test-data/clem/fluo_green.tif
--------------------------------------------------------------------------------
/src/test/resources/test-data/clem/fluo_red_green.tif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/embl-cba/elastix-wrapper/23bf891e9630f87d20028adeb8b1fcaf0f576775/src/test/resources/test-data/clem/fluo_red_green.tif
--------------------------------------------------------------------------------
/src/test/resources/test-data/clem/tmp/TransformParameters.0.txt:
--------------------------------------------------------------------------------
1 | (Transform "BSplineTransform")
2 | (NumberOfParameters 364)
3 | (TransformParameters -0.000000 0.000000 0.000002 0.000001 0.000001 0.000001 0.000000 0.000000 0.000000 0.000000 0.000000 -0.000000 -0.000000 -0.000000 0.000002 -0.000245 -0.000933 -0.000393 -0.000254 -0.000112 -0.000088 -0.000080 0.000057 0.000026 0.000013 0.000001 0.000000 -0.000014 -0.000918 -0.001986 -0.001050 -0.001265 -0.000551 -0.000774 -0.000475 0.000471 0.000359 0.000238 0.000015 0.000000 0.000011 -0.001227 -0.001191 -0.000804 -0.000841 -0.000379 -0.000362 -0.000060 -0.000561 -0.000008 0.000223 -0.000008 0.000000 0.000103 -0.000579 -0.000976 -0.001010 -0.000653 -0.000372 -0.000290 0.000199 0.000168 0.000512 0.000451 -0.000021 -0.000000 -0.000221 -0.001349 -0.000514 -0.000882 -0.000256 -0.000306 -0.000084 0.000019 0.000348 0.000212 0.000522 -0.000006 0.000000 -0.000342 -0.001313 -0.000610 -0.000354 -0.000298 -0.000268 0.000344 0.000100 0.000634 0.000809 0.000717 0.000020 -0.000001 0.000202 0.000025 -0.000307 -0.000287 -0.000134 0.000115 0.000248 0.000359 0.000778 -0.000045 0.002172 0.000141 -0.000005 -0.000193 -0.000765 -0.000395 -0.000099 0.000121 0.000253 0.000260 0.000936 0.000371 0.001304 0.005444 0.000239 -0.000001 -0.000081 -0.000184 0.000023 0.000113 -0.000003 0.000730 0.000665 0.000935 0.000008 0.002459 0.003942 0.000106 -0.000000 0.000000 0.000002 0.000009 0.000021 0.000035 0.000142 0.000185 0.000218 0.000096 0.000566 0.000599 0.000012 0.000000 -0.000000 0.000000 -0.000000 -0.000000 -0.000000 -0.000000 0.000000 0.000000 0.000000 0.000002 0.000001 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 -0.000000 -0.000000 -0.000000 -0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 -0.000000 0.000000 0.000000 -0.000038 -0.000036 -0.000008 -0.000002 -0.000000 -0.000000 -0.000000 -0.000000 0.000000 0.000000 -0.000000 0.000014 0.000449 0.000308 -0.000367 -0.000451 -0.000549 -0.000421 -0.000038 -0.000054 -0.000071 -0.000091 -0.000004 0.000000 0.000041 0.001330 0.002282 0.001229 0.001507 0.000652 0.000537 0.000813 0.000407 0.000137 -0.001535 -0.000084 0.000000 0.000086 0.001323 0.001017 0.000706 0.000799 0.000982 0.000657 0.000297 -0.000054 0.000715 -0.000736 -0.000022 0.000000 0.000098 0.001055 0.000703 0.001039 0.000364 0.000424 0.000347 0.000336 0.000072 -0.000128 -0.000195 0.000004 -0.000000 0.000100 0.000779 0.001002 0.000392 0.000512 0.000032 -0.000146 0.000016 -0.000628 -0.000150 -0.000556 -0.000023 -0.000000 -0.000015 0.000262 0.000504 0.000095 -0.000080 -0.000152 0.000101 -0.000330 -0.000389 -0.000653 -0.000806 -0.000017 0.000000 0.000083 0.000613 -0.000015 -0.000060 -0.000035 -0.000562 -0.000610 -0.000700 -0.000668 -0.001037 -0.000338 0.000008 -0.000000 -0.000014 0.001019 0.000128 -0.000104 -0.000396 -0.000279 -0.000330 -0.000727 -0.000811 -0.001096 0.000565 0.000027 -0.000000 -0.000120 -0.000369 -0.001086 -0.001050 -0.000378 -0.001548 -0.001509 -0.001077 -0.001816 -0.001335 0.000860 0.000020 -0.000000 -0.000002 -0.000011 -0.000083 -0.000121 -0.000071 -0.000398 -0.000505 -0.000823 -0.001303 -0.000312 0.000337 0.000005 -0.000000 0.000000 -0.000000 0.000000 0.000000 0.000000 0.000000 -0.000000 -0.000002 -0.000005 0.000002 0.000003 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000)
4 | (InitialTransformParametersFileName "NoInitialTransform")
5 | (HowToCombineTransforms "Compose")
6 |
7 | // Image specific
8 | (FixedImageDimension 2)
9 | (MovingImageDimension 2)
10 | (FixedInternalImagePixelType "float")
11 | (MovingInternalImagePixelType "float")
12 | (Size 941 1003)
13 | (Index 0 0)
14 | (Spacing 0.0001003200 0.0001003200)
15 | (Origin 0.0000000000 0.0000000000)
16 | (Direction 1.0000000000 0.0000000000 0.0000000000 1.0000000000)
17 | (UseDirectionCosines "false")
18 |
19 | // BSplineTransform specific
20 | (GridSize 13 14)
21 | (GridIndex 0 0)
22 | (GridSpacing 0.0100320001 0.0100320001)
23 | (GridOrigin -0.0130416002 -0.0149476802)
24 | (GridDirection 1.0000000000 0.0000000000 0.0000000000 1.0000000000)
25 | (BSplineTransformSplineOrder 3)
26 | (UseCyclicTransform "false")
27 |
28 | // ResampleInterpolator specific
29 | (ResampleInterpolator "FinalLinearInterpolator")
30 |
31 | // Resampler specific
32 | (Resampler "DefaultResampler")
33 | (DefaultPixelValue 0.000000)
34 | (ResultImageFormat "mhd")
35 | (ResultImagePixelType "unsigned char")
36 | (CompressResultImage "false")
37 |
--------------------------------------------------------------------------------
/src/test/resources/test-data/clem/tmp/elastix_parameters.txt:
--------------------------------------------------------------------------------
1 | (Transform "BSplineTransform")
2 | (MaximumNumberOfIterations 1000)
3 | (ImagePyramidSchedule 2 2)
4 | (NumberOfSpatialSamples 10000)
5 | (FinalGridSpacingInVoxels 100 100 )
6 | (Registration "MultiResolutionRegistration")
7 | (CheckNumberOfSamples "false" )
8 | (NumberOfResolutions 1)
9 | (FixedImagePyramid "FixedSmoothingImagePyramid" )
10 | (MovingImagePyramid "MovingSmoothingImagePyramid" )
11 | (AutomaticTransformInitialization "true")
12 | (AutomaticTransformInitializationMethod "CenterOfGravity")
13 | (ImageSampler "RandomCoordinate" )
14 | (NewSamplesEveryIteration "true")
15 | (ResultImagePixelType "unsigned char")
16 | (DefaultPixelValue 0)
17 | (Optimizer "AdaptiveStochasticGradientDescent")
18 | (WriteTransformParametersEachIteration "false")
19 | (WriteTransformParametersEachResolution "false")
20 | (WriteResultImageAfterEachResolution "false")
21 | (WritePyramidImagesAfterEachResolution "false")
22 | (FixedInternalImagePixelType "float")
23 | (MovingInternalImagePixelType "float")
24 | (UseDirectionCosines "false")
25 | (Interpolator "LinearInterpolator" )
26 | (ResampleInterpolator "FinalLinearInterpolator")
27 | (AutomaticParameterEstimation "true")
28 | (AutomaticScalesEstimation "true")
29 | (Metric "AdvancedMattesMutualInformation" )
30 | (NumberOfHistogramBins 32)
31 | (HowToCombineTransforms "Compose")
32 | (ErodeMask "false")
33 | (WriteResultImage "false")
34 |
--------------------------------------------------------------------------------
/src/test/resources/test-data/clem/tmp/fixed.mhd:
--------------------------------------------------------------------------------
1 | ObjectType = Image
2 | NDims = 2
3 | BinaryData = True
4 | BinaryDataByteOrderMSB = True
5 | DimSize = 941 1003
6 | ElementSize = 1.003200007383552E-4 1.003200007383552E-4
7 | ElementType = MET_UCHAR
8 | ElementDataFile = fixed.raw
9 |
--------------------------------------------------------------------------------
/src/test/resources/test-data/clem/tmp/fixed.raw:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/embl-cba/elastix-wrapper/23bf891e9630f87d20028adeb8b1fcaf0f576775/src/test/resources/test-data/clem/tmp/fixed.raw
--------------------------------------------------------------------------------
/src/test/resources/test-data/clem/tmp/moving.mhd:
--------------------------------------------------------------------------------
1 | ObjectType = Image
2 | NDims = 2
3 | BinaryData = True
4 | BinaryDataByteOrderMSB = True
5 | DimSize = 941 1003
6 | ElementSize = 1.003200007383552E-4 1.003200007383552E-4
7 | ElementType = MET_UCHAR
8 | ElementDataFile = moving.raw
9 |
--------------------------------------------------------------------------------
/src/test/resources/test-data/clem/tmp/moving.raw:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/embl-cba/elastix-wrapper/23bf891e9630f87d20028adeb8b1fcaf0f576775/src/test/resources/test-data/clem/tmp/moving.raw
--------------------------------------------------------------------------------
/src/test/resources/test-data/clem/tmp/result.mhd:
--------------------------------------------------------------------------------
1 | ObjectType = Image
2 | NDims = 2
3 | BinaryData = True
4 | BinaryDataByteOrderMSB = False
5 | CompressedData = False
6 | TransformMatrix = 1 0 0 1
7 | Offset = 0 0
8 | CenterOfRotation = 0 0
9 | ElementSpacing = 0.00010032 0.00010032
10 | DimSize = 941 1003
11 | AnatomicalOrientation = ??
12 | ElementType = MET_UCHAR
13 | ElementDataFile = result.raw
14 |
--------------------------------------------------------------------------------
/src/test/resources/test-data/clem/tmp/result.raw:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/embl-cba/elastix-wrapper/23bf891e9630f87d20028adeb8b1fcaf0f576775/src/test/resources/test-data/clem/tmp/result.raw
--------------------------------------------------------------------------------
/src/test/resources/test-data/clem/tmp/run_elastix.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | ###
4 | # #%L
5 | # Fiji distribution of ImageJ for the life sciences.
6 | # %%
7 | # Copyright (C) 2017 - 2025 EMBL
8 | # %%
9 | # Redistribution and use in source and binary forms, with or without
10 | # modification, are permitted provided that the following conditions are met:
11 | #
12 | # 1. Redistributions of source code must retain the above copyright notice,
13 | # this list of conditions and the following disclaimer.
14 | # 2. Redistributions in binary form must reproduce the above copyright notice,
15 | # this list of conditions and the following disclaimer in the documentation
16 | # and/or other materials provided with the distribution.
17 | #
18 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
22 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 | # POSSIBILITY OF SUCH DAMAGE.
29 | # #L%
30 | ###
31 | ELASTIX_PATH=/Applications/elastix_macosx64_v4.8/
32 | export DYLD_LIBRARY_PATH=$ELASTIX_PATH/lib/
33 | $ELASTIX_PATH/bin/elastix $@
34 |
--------------------------------------------------------------------------------
/src/test/resources/test-data/clem/tmp/run_transformix.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | ###
4 | # #%L
5 | # Fiji distribution of ImageJ for the life sciences.
6 | # %%
7 | # Copyright (C) 2017 - 2025 EMBL
8 | # %%
9 | # Redistribution and use in source and binary forms, with or without
10 | # modification, are permitted provided that the following conditions are met:
11 | #
12 | # 1. Redistributions of source code must retain the above copyright notice,
13 | # this list of conditions and the following disclaimer.
14 | # 2. Redistributions in binary form must reproduce the above copyright notice,
15 | # this list of conditions and the following disclaimer in the documentation
16 | # and/or other materials provided with the distribution.
17 | #
18 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
22 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 | # POSSIBILITY OF SUCH DAMAGE.
29 | # #L%
30 | ###
31 | ELASTIX_PATH=/Applications/elastix_macosx64_v4.8/
32 | export DYLD_LIBRARY_PATH=$ELASTIX_PATH/lib/
33 | $ELASTIX_PATH/bin/transformix $@
34 |
--------------------------------------------------------------------------------
/src/test/resources/test-data/clem/tmp/transformed-ch0.tif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/embl-cba/elastix-wrapper/23bf891e9630f87d20028adeb8b1fcaf0f576775/src/test/resources/test-data/clem/tmp/transformed-ch0.tif
--------------------------------------------------------------------------------
/src/test/resources/test-data/clem/tmp/transformix.log:
--------------------------------------------------------------------------------
1 |
2 | transformix is started at Mon Jul 20 15:56:42 2020.
3 |
4 | which transformix: /Applications/elastix_macosx64_v4.8//bin/transformix
5 | transformix runs at: Christians-MacBook-Pro.local
6 | Mac OS X 10.14.6 (x64), 18G95
7 | with 16384 MB memory, and 2 cores @ 2500 MHz.
8 | Running transformix with parameter file "/Users/tischer/Documents/fiji-plugin-elastixWrapper/src/test/resources/test-data/clem/tmp//TransformParameters.0.txt".
9 |
10 | Reading the elastix parameters from file ...
11 |
12 | Installing all components.
13 | InstallingComponents was successful.
14 |
15 | ERROR: OpenCL device: Intel(R) Iris(TM) Plus Graphics 640 , does not support 'double' computations. Consider updating it.
16 | OpenCL processing is disabled.
17 | ELASTIX version: 4.800
18 | Command line options from ElastixBase:
19 | -in /Users/tischer/Documents/fiji-plugin-elastixWrapper/src/test/resources/test-data/clem/tmp//moving.mhd
20 | -out /Users/tischer/Documents/fiji-plugin-elastixWrapper/src/test/resources/test-data/clem/tmp/
21 | -threads 4
22 | -tp /Users/tischer/Documents/fiji-plugin-elastixWrapper/src/test/resources/test-data/clem/tmp//TransformParameters.0.txt
23 | -def unspecified, so no input points transformed
24 | -jac unspecified, so no det(dT/dx) computed
25 | -jacmat unspecified, so no dT/dx computed
26 |
27 | =============== start of ParameterFile: /Users/tischer/Documents/fiji-plugin-elastixWrapper/src/test/resources/test-data/clem/tmp//TransformParameters.0.txt ===============
28 | (Transform "BSplineTransform")
29 | (NumberOfParameters 364)
30 | (TransformParameters -0.000000 0.000000 0.000002 0.000001 0.000001 0.000001 0.000000 0.000000 0.000000 0.000000 0.000000 -0.000000 -0.000000 -0.000000 0.000002 -0.000245 -0.000933 -0.000393 -0.000254 -0.000112 -0.000088 -0.000080 0.000057 0.000026 0.000013 0.000001 0.000000 -0.000014 -0.000918 -0.001986 -0.001050 -0.001265 -0.000551 -0.000774 -0.000475 0.000471 0.000359 0.000238 0.000015 0.000000 0.000011 -0.001227 -0.001191 -0.000804 -0.000841 -0.000379 -0.000362 -0.000060 -0.000561 -0.000008 0.000223 -0.000008 0.000000 0.000103 -0.000579 -0.000976 -0.001010 -0.000653 -0.000372 -0.000290 0.000199 0.000168 0.000512 0.000451 -0.000021 -0.000000 -0.000221 -0.001349 -0.000514 -0.000882 -0.000256 -0.000306 -0.000084 0.000019 0.000348 0.000212 0.000522 -0.000006 0.000000 -0.000342 -0.001313 -0.000610 -0.000354 -0.000298 -0.000268 0.000344 0.000100 0.000634 0.000809 0.000717 0.000020 -0.000001 0.000202 0.000025 -0.000307 -0.000287 -0.000134 0.000115 0.000248 0.000359 0.000778 -0.000045 0.002172 0.000141 -0.000005 -0.000193 -0.000765 -0.000395 -0.000099 0.000121 0.000253 0.000260 0.000936 0.000371 0.001304 0.005444 0.000239 -0.000001 -0.000081 -0.000184 0.000023 0.000113 -0.000003 0.000730 0.000665 0.000935 0.000008 0.002459 0.003942 0.000106 -0.000000 0.000000 0.000002 0.000009 0.000021 0.000035 0.000142 0.000185 0.000218 0.000096 0.000566 0.000599 0.000012 0.000000 -0.000000 0.000000 -0.000000 -0.000000 -0.000000 -0.000000 0.000000 0.000000 0.000000 0.000002 0.000001 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 -0.000000 -0.000000 -0.000000 -0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 -0.000000 0.000000 0.000000 -0.000038 -0.000036 -0.000008 -0.000002 -0.000000 -0.000000 -0.000000 -0.000000 0.000000 0.000000 -0.000000 0.000014 0.000449 0.000308 -0.000367 -0.000451 -0.000549 -0.000421 -0.000038 -0.000054 -0.000071 -0.000091 -0.000004 0.000000 0.000041 0.001330 0.002282 0.001229 0.001507 0.000652 0.000537 0.000813 0.000407 0.000137 -0.001535 -0.000084 0.000000 0.000086 0.001323 0.001017 0.000706 0.000799 0.000982 0.000657 0.000297 -0.000054 0.000715 -0.000736 -0.000022 0.000000 0.000098 0.001055 0.000703 0.001039 0.000364 0.000424 0.000347 0.000336 0.000072 -0.000128 -0.000195 0.000004 -0.000000 0.000100 0.000779 0.001002 0.000392 0.000512 0.000032 -0.000146 0.000016 -0.000628 -0.000150 -0.000556 -0.000023 -0.000000 -0.000015 0.000262 0.000504 0.000095 -0.000080 -0.000152 0.000101 -0.000330 -0.000389 -0.000653 -0.000806 -0.000017 0.000000 0.000083 0.000613 -0.000015 -0.000060 -0.000035 -0.000562 -0.000610 -0.000700 -0.000668 -0.001037 -0.000338 0.000008 -0.000000 -0.000014 0.001019 0.000128 -0.000104 -0.000396 -0.000279 -0.000330 -0.000727 -0.000811 -0.001096 0.000565 0.000027 -0.000000 -0.000120 -0.000369 -0.001086 -0.001050 -0.000378 -0.001548 -0.001509 -0.001077 -0.001816 -0.001335 0.000860 0.000020 -0.000000 -0.000002 -0.000011 -0.000083 -0.000121 -0.000071 -0.000398 -0.000505 -0.000823 -0.001303 -0.000312 0.000337 0.000005 -0.000000 0.000000 -0.000000 0.000000 0.000000 0.000000 0.000000 -0.000000 -0.000002 -0.000005 0.000002 0.000003 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000)
31 | (InitialTransformParametersFileName "NoInitialTransform")
32 | (HowToCombineTransforms "Compose")
33 |
34 | // Image specific
35 | (FixedImageDimension 2)
36 | (MovingImageDimension 2)
37 | (FixedInternalImagePixelType "float")
38 | (MovingInternalImagePixelType "float")
39 | (Size 941 1003)
40 | (Index 0 0)
41 | (Spacing 0.0001003200 0.0001003200)
42 | (Origin 0.0000000000 0.0000000000)
43 | (Direction 1.0000000000 0.0000000000 0.0000000000 1.0000000000)
44 | (UseDirectionCosines "false")
45 |
46 | // BSplineTransform specific
47 | (GridSize 13 14)
48 | (GridIndex 0 0)
49 | (GridSpacing 0.0100320001 0.0100320001)
50 | (GridOrigin -0.0130416002 -0.0149476802)
51 | (GridDirection 1.0000000000 0.0000000000 0.0000000000 1.0000000000)
52 | (BSplineTransformSplineOrder 3)
53 | (UseCyclicTransform "false")
54 |
55 | // ResampleInterpolator specific
56 | (ResampleInterpolator "FinalLinearInterpolator")
57 |
58 | // Resampler specific
59 | (Resampler "DefaultResampler")
60 | (DefaultPixelValue 0.000000)
61 | (ResultImageFormat "mhd")
62 | (ResultImagePixelType "unsigned char")
63 | (CompressResultImage "false")
64 |
65 |
66 | =============== end of ParameterFile: /Users/tischer/Documents/fiji-plugin-elastixWrapper/src/test/resources/test-data/clem/tmp//TransformParameters.0.txt ===============
67 |
68 |
69 | Reading input image ...
70 | Reading input image took 0.003661 s
71 | Calling all ReadFromFile()'s ...
72 | Calling all ReadFromFile()'s took 0.000407 s
73 | Transforming points ...
74 | The command-line option "-def" is not used, so no points are transformed
75 | Transforming points done, it took 0.00s
76 | Compute determinant of spatial Jacobian ...
77 | The command-line option "-jac" is not used, so no det(dT/dx) computed.
78 | Computing determinant of spatial Jacobian done, it took 0.00s
79 | Compute spatial Jacobian (full matrix) ...
80 | The command-line option "-jacmat" is not used, so no dT/dx computed.
81 | Computing spatial Jacobian done, it took 0.00s
82 | Resampling image and writing to disk ...
83 | Resampling took 0.13s
84 |
85 | transformix has finished at Mon Jul 20 15:56:43 2020.
86 | Total time elapsed: 0.2s.
87 |
88 |
--------------------------------------------------------------------------------
/src/test/resources/test-data/fluo01/ellipsoid-at45degrees-dxyz200nm.tif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/embl-cba/elastix-wrapper/23bf891e9630f87d20028adeb8b1fcaf0f576775/src/test/resources/test-data/fluo01/ellipsoid-at45degrees-dxyz200nm.tif
--------------------------------------------------------------------------------
/src/test/resources/test-data/fluo01/ellipsoid-horizontal-dxyz200nm.tif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/embl-cba/elastix-wrapper/23bf891e9630f87d20028adeb8b1fcaf0f576775/src/test/resources/test-data/fluo01/ellipsoid-horizontal-dxyz200nm.tif
--------------------------------------------------------------------------------
/src/test/resources/test-data/fluo01/tmp/TransformParameters.0.txt:
--------------------------------------------------------------------------------
1 | (CenterOfRotationPoint 0.005699999999999965 0.005399999999999827 0.00980000000000017)
2 | (ComputeZYX "false")
3 | (Direction 1 0 0 0 1 0 0 0 1)
4 | (FixedImageDimension 3)
5 | (FixedInternalImagePixelType "float")
6 | (HowToCombineTransforms "Compose")
7 | (Index 0 0 0)
8 | (InitialTransformParameterFileName "NoInitialTransform")
9 | (MovingImageDimension 3)
10 | (MovingInternalImagePixelType "float")
11 | (NumberOfParameters 6)
12 | (Origin 0 0 0)
13 | (Size 61 54 100)
14 | (Spacing 0.00019999999999999998 0.00019999999999999998 0.00019999999999999998)
15 | (Transform "EulerTransform")
16 | (TransformParameters 0.0000714503519143064 -0.000125317318707849 0.7857090262713201 0.000020257574348628572 -0.00023761196622144073 -1.588592611628173e-7)
17 | (UseDirectionCosines "false")
18 |
19 | // ResampleInterpolator specific
20 | (ResampleInterpolator "FinalLinearInterpolator")
21 |
22 | // Resampler specific
23 | (CompressResultImage "false")
24 | (DefaultPixelValue 0)
25 | (Resampler "DefaultResampler")
26 | (ResultImageFormat "mhd")
27 | (ResultImagePixelType "unsigned char")
28 |
--------------------------------------------------------------------------------
/src/test/resources/test-data/fluo01/tmp/elastix_parameters.txt:
--------------------------------------------------------------------------------
1 | (Transform "EulerTransform" )
2 | (MaximumNumberOfIterations 1000 )
3 | (CheckNumberOfSamples "false" )
4 | (NumberOfResolutions 1 )
5 | (ImagePyramidSchedule 10 10 )
6 | (FinalGridSpacingInVoxels 50 50 50 )
7 | (NewSamplesEveryIteration "true" )
8 | (DefaultPixelValue 0 )
9 | (Optimizer "AdaptiveStochasticGradientDescent" )
10 | (WriteTransformParametersEachIteration "false" )
11 | (WriteTransformParametersEachResolution "false" )
12 | (WriteResultImageAfterEachResolution "false" )
13 | (WritePyramidImagesAfterEachResolution "false" )
14 | (FixedInternalImagePixelType "float" )
15 | (MovingInternalImagePixelType "float" )
16 | (UseDirectionCosines "false" )
17 | (AutomaticParameterEstimation "true" )
18 | (AutomaticScalesEstimation "true" )
19 | (HowToCombineTransforms "Compose" )
20 | (ErodeMask "false" )
21 | (ResultImagePixelType "unsigned char" )
22 | (NumberOfSpatialSamples 10000 )
23 | (Registration "MultiResolutionRegistration" )
24 | (FixedImagePyramid "FixedSmoothingImagePyramid" )
25 | (MovingImagePyramid "MovingSmoothingImagePyramid" )
26 | (AutomaticTransformInitialization "true" )
27 | (AutomaticTransformInitializationMethod "CenterOfGravity" )
28 | (ImageSampler "RandomCoordinate" )
29 | (Interpolator "LinearInterpolator" )
30 | (ResampleInterpolator "FinalLinearInterpolator" )
31 | (Metric "AdvancedMattesMutualInformation" )
32 | (NumberOfHistogramBins 32 )
33 | (WriteResultImage "false" )
34 |
--------------------------------------------------------------------------------
/src/test/resources/test-data/fluo01/tmp/fixed.mhd:
--------------------------------------------------------------------------------
1 | ObjectType = Image
2 | NDims = 3
3 | BinaryData = True
4 | BinaryDataByteOrderMSB = True
5 | DimSize = 61 54 100
6 | ElementSize = 1.9999999999999998E-4 1.9999999999999998E-4 1.9999999999999998E-4
7 | ElementType = MET_UCHAR
8 | ElementDataFile = fixed.raw
9 |
--------------------------------------------------------------------------------
/src/test/resources/test-data/fluo01/tmp/fixed.raw:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/embl-cba/elastix-wrapper/23bf891e9630f87d20028adeb8b1fcaf0f576775/src/test/resources/test-data/fluo01/tmp/fixed.raw
--------------------------------------------------------------------------------
/src/test/resources/test-data/fluo01/tmp/moving.mhd:
--------------------------------------------------------------------------------
1 | ObjectType = Image
2 | NDims = 3
3 | BinaryData = True
4 | BinaryDataByteOrderMSB = True
5 | DimSize = 61 54 100
6 | ElementSize = 1.9999999999999998E-4 1.9999999999999998E-4 1.9999999999999998E-4
7 | ElementType = MET_UCHAR
8 | ElementDataFile = moving.raw
9 |
--------------------------------------------------------------------------------
/src/test/resources/test-data/fluo01/tmp/moving.raw:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/embl-cba/elastix-wrapper/23bf891e9630f87d20028adeb8b1fcaf0f576775/src/test/resources/test-data/fluo01/tmp/moving.raw
--------------------------------------------------------------------------------
/src/test/resources/test-data/fluo01/tmp/result.mhd:
--------------------------------------------------------------------------------
1 | ObjectType = Image
2 | NDims = 3
3 | BinaryData = True
4 | BinaryDataByteOrderMSB = False
5 | CompressedData = False
6 | TransformMatrix = 1 0 0 0 1 0 0 0 1
7 | Offset = 0 0 0
8 | CenterOfRotation = 0 0 0
9 | AnatomicalOrientation = RAI
10 | ElementSpacing = 0.00019999999999999998 0.00019999999999999998 0.00019999999999999998
11 | DimSize = 61 54 100
12 | ElementType = MET_UCHAR
13 | ElementDataFile = result.raw
14 |
--------------------------------------------------------------------------------
/src/test/resources/test-data/fluo01/tmp/result.raw:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/embl-cba/elastix-wrapper/23bf891e9630f87d20028adeb8b1fcaf0f576775/src/test/resources/test-data/fluo01/tmp/result.raw
--------------------------------------------------------------------------------
/src/test/resources/test-data/fluo01/tmp/run_elastix.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | ###
4 | # #%L
5 | # Fiji distribution of ImageJ for the life sciences.
6 | # %%
7 | # Copyright (C) 2017 - 2025 EMBL
8 | # %%
9 | # Redistribution and use in source and binary forms, with or without
10 | # modification, are permitted provided that the following conditions are met:
11 | #
12 | # 1. Redistributions of source code must retain the above copyright notice,
13 | # this list of conditions and the following disclaimer.
14 | # 2. Redistributions in binary form must reproduce the above copyright notice,
15 | # this list of conditions and the following disclaimer in the documentation
16 | # and/or other materials provided with the distribution.
17 | #
18 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
22 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 | # POSSIBILITY OF SUCH DAMAGE.
29 | # #L%
30 | ###
31 | ELASTIX_PATH=/Applications/elastix-5.2.0-mac/
32 | export DYLD_LIBRARY_PATH=$ELASTIX_PATH/lib/
33 | $ELASTIX_PATH/bin/elastix $@
34 |
--------------------------------------------------------------------------------
/src/test/resources/test-data/fluo01/tmp/run_transformix.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | ###
4 | # #%L
5 | # Fiji distribution of ImageJ for the life sciences.
6 | # %%
7 | # Copyright (C) 2017 - 2025 EMBL
8 | # %%
9 | # Redistribution and use in source and binary forms, with or without
10 | # modification, are permitted provided that the following conditions are met:
11 | #
12 | # 1. Redistributions of source code must retain the above copyright notice,
13 | # this list of conditions and the following disclaimer.
14 | # 2. Redistributions in binary form must reproduce the above copyright notice,
15 | # this list of conditions and the following disclaimer in the documentation
16 | # and/or other materials provided with the distribution.
17 | #
18 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
22 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 | # POSSIBILITY OF SUCH DAMAGE.
29 | # #L%
30 | ###
31 | ELASTIX_PATH=/Applications/elastix-5.2.0-mac/
32 | export DYLD_LIBRARY_PATH=$ELASTIX_PATH/lib/
33 | $ELASTIX_PATH/bin/transformix $@
34 |
--------------------------------------------------------------------------------
/src/test/resources/test-data/fluo01/tmp/transformed-ch0.tif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/embl-cba/elastix-wrapper/23bf891e9630f87d20028adeb8b1fcaf0f576775/src/test/resources/test-data/fluo01/tmp/transformed-ch0.tif
--------------------------------------------------------------------------------
/src/test/resources/test-data/fluo01/tmp/transformix.log:
--------------------------------------------------------------------------------
1 |
2 | transformix is started at Tue Feb 4 22:12:02 2025.
3 |
4 | which transformix: /Applications/elastix-5.2.0-mac//bin/transformix
5 | transformix version: 5.2.0
6 | Git revision SHA: ebb429a33bdf3248c2137fc4adb4259a2ec7db24
7 | Git revision date: Thu Jul 18 14:42:31 2024 +0200
8 | Build date: Jul 18 2024 13:00:59
9 | Compiler: Clang version Apple LLVM 14.0.0 (clang-1400.0.29.202)
10 | Compiler: GCC version Apple LLVM 14.0.0 (clang-1400.0.29.202)
11 | Memory address size: 64-bit
12 | CMake version: 3.24.2
13 | ITK version: 5.4.0
14 |
15 | Command-line arguments:
16 | -out /Users/tischer/Documents/elastixWrapper/src/test/resources/test-data/fluo01/tmp/ -in /Users/tischer/Documents/elastixWrapper/src/test/resources/test-data/fluo01/tmp//moving.mhd -tp /Users/tischer/Documents/elastixWrapper/src/test/resources/test-data/fluo01/tmp//TransformParameters.0.txt -threads 8
17 |
18 | transformix runs at: mac-korbel52.fritz.box
19 | macOS 13.5 (x64), 22G74
20 | with 24576 MB memory, and 8 cores @ 2400 MHz.
21 | Running transformix with parameter file "/Users/tischer/Documents/elastixWrapper/src/test/resources/test-data/fluo01/tmp//TransformParameters.0.txt".
22 |
23 | Reading the elastix parameters from file ...
24 |
25 | Installing all components.
26 | InstallingComponents was successful.
27 |
28 | ELASTIX version: 5.2.0
29 | Command line options from ElastixBase:
30 | -in /Users/tischer/Documents/elastixWrapper/src/test/resources/test-data/fluo01/tmp//moving.mhd
31 | -out /Users/tischer/Documents/elastixWrapper/src/test/resources/test-data/fluo01/tmp/
32 | -threads 8
33 | -tp /Users/tischer/Documents/elastixWrapper/src/test/resources/test-data/fluo01/tmp//TransformParameters.0.txt
34 | -def unspecified, so no input points transformed
35 | -jac unspecified, so no det(dT/dx) computed
36 | -jacmat unspecified, so no dT/dx computed
37 |
38 | =============== start of ParameterFile: /Users/tischer/Documents/elastixWrapper/src/test/resources/test-data/fluo01/tmp//TransformParameters.0.txt ===============
39 | (CenterOfRotationPoint 0.005699999999999965 0.005399999999999827 0.00980000000000017)
40 | (ComputeZYX "false")
41 | (Direction 1 0 0 0 1 0 0 0 1)
42 | (FixedImageDimension 3)
43 | (FixedInternalImagePixelType "float")
44 | (HowToCombineTransforms "Compose")
45 | (Index 0 0 0)
46 | (InitialTransformParameterFileName "NoInitialTransform")
47 | (MovingImageDimension 3)
48 | (MovingInternalImagePixelType "float")
49 | (NumberOfParameters 6)
50 | (Origin 0 0 0)
51 | (Size 61 54 100)
52 | (Spacing 0.00019999999999999998 0.00019999999999999998 0.00019999999999999998)
53 | (Transform "EulerTransform")
54 | (TransformParameters 0.0000714503519143064 -0.000125317318707849 0.7857090262713201 0.000020257574348628572 -0.00023761196622144073 -1.588592611628173e-7)
55 | (UseDirectionCosines "false")
56 |
57 | // ResampleInterpolator specific
58 | (ResampleInterpolator "FinalLinearInterpolator")
59 |
60 | // Resampler specific
61 | (CompressResultImage "false")
62 | (DefaultPixelValue 0)
63 | (Resampler "DefaultResampler")
64 | (ResultImageFormat "mhd")
65 | (ResultImagePixelType "unsigned char")
66 |
67 |
68 | =============== end of ParameterFile: /Users/tischer/Documents/elastixWrapper/src/test/resources/test-data/fluo01/tmp//TransformParameters.0.txt ===============
69 |
70 |
71 | Reading input image ...
72 | Reading input image took 0.0021832 s
73 | Calling all ReadFromFile()'s ...
74 | Calling all ReadFromFile()'s took 9.20296e-05 s
75 | Transforming points ...
76 | The command-line option "-def" is not used, so no points are transformed
77 | Transforming points done, it took 0.00s
78 | Compute determinant of spatial Jacobian ...
79 | The command-line option "-jac" is not used, so no det(dT/dx) computed.
80 | Computing determinant of spatial Jacobian done, it took 0.00s
81 | Compute spatial Jacobian (full matrix) ...
82 | The command-line option "-jacmat" is not used, so no dT/dx computed.
83 | Computing spatial Jacobian done, it took 0.00s
84 | Resampling image and writing to disk ...
85 | Resampling took 0.00s
86 |
87 | transformix has finished at Tue Feb 4 22:12:02 2025.
88 | Total time elapsed: 0.1s.
89 |
90 |
--------------------------------------------------------------------------------
/src/test/resources/test-data/fluo01/transformed-ellipsoid-ch0.tif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/embl-cba/elastix-wrapper/23bf891e9630f87d20028adeb8b1fcaf0f576775/src/test/resources/test-data/fluo01/transformed-ellipsoid-ch0.tif
--------------------------------------------------------------------------------
/src/test/resources/test-data/sbem-mask.ome.tif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/embl-cba/elastix-wrapper/23bf891e9630f87d20028adeb8b1fcaf0f576775/src/test/resources/test-data/sbem-mask.ome.tif
--------------------------------------------------------------------------------
/src/test/resources/test-data/sbem-segmented-neuropil.ome.tif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/embl-cba/elastix-wrapper/23bf891e9630f87d20028adeb8b1fcaf0f576775/src/test/resources/test-data/sbem-segmented-neuropil.ome.tif
--------------------------------------------------------------------------------
/src/test/resources/test-data/sbem.mhd:
--------------------------------------------------------------------------------
1 | ObjectType = Image
2 | NDims = 3
3 | BinaryData = True
4 | BinaryDataByteOrderMSB = True
5 | DimSize = 275 259 286
6 | ElementSize = 1.0 1.0 1.0
7 | ElementType = MET_UCHAR
8 | ElementDataFile = sbem.raw
9 |
--------------------------------------------------------------------------------
/src/test/resources/test-data/sbem.ome.tif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/embl-cba/elastix-wrapper/23bf891e9630f87d20028adeb8b1fcaf0f576775/src/test/resources/test-data/sbem.ome.tif
--------------------------------------------------------------------------------
/src/test/resources/test-data/sbem.raw:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/embl-cba/elastix-wrapper/23bf891e9630f87d20028adeb8b1fcaf0f576775/src/test/resources/test-data/sbem.raw
--------------------------------------------------------------------------------
/src/test/resources/test-data/xray-manually-similarity-aligned.ome.tif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/embl-cba/elastix-wrapper/23bf891e9630f87d20028adeb8b1fcaf0f576775/src/test/resources/test-data/xray-manually-similarity-aligned.ome.tif
--------------------------------------------------------------------------------
/src/test/resources/test-data/xray-segmented-neuropil-manually-similarity-aligned.ome.tif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/embl-cba/elastix-wrapper/23bf891e9630f87d20028adeb8b1fcaf0f576775/src/test/resources/test-data/xray-segmented-neuropil-manually-similarity-aligned.ome.tif
--------------------------------------------------------------------------------
/src/test/resources/test-data/xray-segmented-neuropil.ome.tif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/embl-cba/elastix-wrapper/23bf891e9630f87d20028adeb8b1fcaf0f576775/src/test/resources/test-data/xray-segmented-neuropil.ome.tif
--------------------------------------------------------------------------------
/src/test/resources/test-data/xray.ome.tif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/embl-cba/elastix-wrapper/23bf891e9630f87d20028adeb8b1fcaf0f576775/src/test/resources/test-data/xray.ome.tif
--------------------------------------------------------------------------------
/src/test/resources/tmp/sbem-blur.mhd:
--------------------------------------------------------------------------------
1 | ObjectType = Image
2 | NDims = 3
3 | BinaryData = True
4 | BinaryDataByteOrderMSB = False
5 | CompressedData = False
6 | TransformMatrix = 1 0 0 0 1 0 0 0 1
7 | Offset = 0 0 0
8 | CenterOfRotation = 0 0 0
9 | AnatomicalOrientation = RAI
10 | ElementSpacing = 1 1 1
11 | DimSize = 275 259 286
12 | ElementType = MET_UCHAR
13 | ElementDataFile = sbem-blur.raw
14 |
--------------------------------------------------------------------------------
/src/test/resources/tmp/sbem-blur.raw:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/embl-cba/elastix-wrapper/23bf891e9630f87d20028adeb8b1fcaf0f576775/src/test/resources/tmp/sbem-blur.raw
--------------------------------------------------------------------------------