uncbiag / mermaid Goto Github PK
View Code? Open in Web Editor NEWImage registration using pytorch
License: Other
Image registration using pytorch
License: Other
In ImageIO.read() the spacing was flipped to match the order of numpy array dimensions. However, it was not flipped back when writing into an image file using ImageIO.write().
I am looking for Cross model image registration for some of my projects and I am wondering will it support cross-modal images.
Zenodo enables creation of an open source scientific software citation, complete with a DOI. This enable recognition of the work and reproducibility through identification of computational dependencies.
An GitHub README badge with the citation that is automatically updated when a GitHub Release is created can be generated as documented here:
Hello,
I was wondering if there was something to describe what the consensus model is actually doing?
Is there a paper that could be used as a reference as well?
@marcniethammer any advice (as the contributor) would be appreciated!
Thank you!
For some reason this code crashes
testRegistrationGenericMultiscaleCustom.py
MySVFNet (
)
Registering new similarity measure mySSD in factory
Optimizing for at most 20 iterations
Warning: optimizer name = lbfgs_ls specified, but ignored since optimizer was set explicitly
Traceback (most recent call last):
File "testRegistrationGenericMultiscaleCustom.py", line 160, in
mo.optimize()
File "/afs/cs.unc.edu/home/mn/private/research/programming/git/mermaid/pyreg/multiscale_optimizer.py", line 625, in optimize
ssOpt.optimize()
File "/afs/cs.unc.edu/home/mn/private/research/programming/git/mermaid/pyreg/multiscale_optimizer.py", line 446, in optimize
self.optimizer_instance.step(self._closure)
File "/playpen/anaconda2/lib/python2.7/site-packages/torch/optim/adam.py", line 39, in step
loss = closure()
File "/afs/cs.unc.edu/home/mn/private/research/programming/git/mermaid/pyreg/multiscale_optimizer.py", line 327, in _closure
self.rec_phiWarped = self.model(self.identityMap, self.ISource)
File "/playpen/anaconda2/lib/python2.7/site-packages/torch/nn/modules/module.py", line 224, in call
result = self.forward(*input, **kwargs)
TypeError: forward() takes exactly 2 arguments (3 given)
It would be good to have an option of doing interpolation that is better than linear interpolation. For example, b-splines would be good. This would be useful in particularly also for the low-res parameterizations.
Maps are currently all in [-1,1]^d and ignore the spacing. This is problematic because the Gaussian kernels for regularization rely on this spacing.
Instead the maps should be in the range of the spatial extent of an image (for a given spacing).
Requires a change of the core interpolation functions to do this mapping (as these rely on the canonical [-1,1] mapping).
Must the moving image and the reference image have the same spaing?
si.register_images(I0, I1, spacing, model_name='lddmm_shooting_map',
nr_of_iterations=100,
use_multi_scale=False,
visualize_step=5,
optimizer_name='sgd',
learning_rate=0.1,
rel_ftol=1e-7,
json_config_out_filename=('test2d_tst.json',
'test2d_tst_with_comments.json'),
params='test2d_tst.json',
recording_step=None)
I0 and I1 must have the same spacing?Must I0 and I0 be resampled to the same spacing before registration?
Currently, the energies are divided by the batch-size, so that the energies stay the same independent of the size of the batch. But this is not a good idea, because then one requires a different learning rate for different batch sizes.
Needs to be fixed (i.e., remove division by batch-size for all the energy terms), but maybe add a display option that also displays energy normalized by batch if desired.
The upsampling and downsampling is unnatural. As it uses (current_size-1)/(desired_size-1). This is strange. If one has a 4x4 image with spacing 1/3 it will become a spacing of 1 one upsampled to 2x2 instead of 2/3. To properly support this an origin should be introduced.
The inverse map output is wrong when the initial map is not the identity map. It can be corrected by manually set the initial inverse map.
After I modified the value of example_img_len in the script example_minimal_registration_without_simple_interface.py, the result seems to be wrong, the mesh does not change after iteration, and converges to the tolerance in step 29. When the image data size becomes 640*360, do I need to modify other parameters?
Hi,
Thank you for sharing such brilliant codes.
Could you provide more detailed documents for implementation, such as reference papers?
I am a beginner to LDDMM. I have read several papers about LDDMM. But I can not figure out what method you used in the codes.
Thank you very much.
Hello @marcniethammer,
Thank you for making the code available, really interesting work.
I was looking into some of the code, in particular for the STN in 3D. I noticed that you are moving the channels around, here:
I have also another question that is not about your code in particular but it is in general about the Pytorch grid_sample function. As you can see from my question , I am still not sure about how to correctly use grid_sample in case of registration. Have you solved this problem yourself?
In class NCCSimilarity, def compute_similarity has input parameters I0, I1 but tries to compute ncc with cI0, cI1. One of them needs to be renamed.
The atlas builder runs svf registration in a for loop and uses model properties from the previous registration for the current registration. A function that clears the model beforehand is needed.
I've been getting this message from pip
:
DEPRECATION: mermaid 0.3.2 has a non-standard dependency specifier torch>=1.7torchvision. pip 23.3 will enforce this behaviour change. A possible replacement is to upgrade to a newer version of mermaid or contact the author to suggest that they release a version with a conforming dependency specifiers. Discussion can be found at pypa/pip#12063
python setup.py install does not install the settings folder to the python library
I used this code to train my own data set. My data set came from ADNI. I used 240 pieces as the training set, 70 pieces as the verification set, and 34 pieces as the test set.I did not change other parameters, but the result of training test is worse than Voxelmorph. Could you please give me some opinion analysis.
In lines 45/46 the attribute 'smooth_scalar_field' needs to be updated to the new name 'smooth'.
Accidently I tried to register an image to itself using the multi_scale optimizer, but the code breaks. It should return an identity map. (It works when single scale optimizer is used.)
Hi,
How can I force the register_image on CPU? By default, example_simple_interface.py seems always run on GPU, even if CUDA_ON was set to false.
Thank you
The dimensions are not correct after ifft, because of the real fft in CUDA (for the Fourier filtering).
Fixed currently with a quick hack for map_low_res_factor which makes sure the last dimension is even. Needs a more proper solution.
variable dim is not defined in line 692, unless self.squeeze_image is true in line 616.
Code needs to be adapted to work with the newer pytorch. Currently only runs with pytorch 0.3.x
Hi,
How can write the registration result to a nifti file?
Thank you
LNCC output will be out of the range [0,1] when the images have large area with zero value.
Steps to reproduce:
params = pars.ParameterDict()
params['square_example_images']['len_s'] = 10
params['square_example_images']['len_l'] = 30
I0,I1,spacing = EG.CreateSquares(dim=3, add_noise_to_bg=False).create_image_pair(np.array([64, 64, 64]),params=params)
params['model']['registration_model']['type'] = "svf_vector_momentum_map"
params['model']['registration_model']['similarity_measure']['type'] = "lncc"
opt = MO.SimpleSingleScaleRegistration(I0,
I1,
spacing,
sz,
params,
compute_inverse_map=False)
opt.register()
The log shows as follows:
0-Tot: E=099.4140 | simE=099.4140 | regE=000.0000 | optParE=000.0000 | relF= n/a |
0-Img: E=099.4140 | simE=099.4140 | regE=000.0000 |
Line 16 that is loading the json file does not match the file's name and directory. Could you please update it to:
params.load_JSON('../test/json/svf_momentum_base_config.json')
when i run the jupyter --example_simple_interface.
the test2d_tst.json can't find in the repository.
and there's an error
Could not open file = test2d_tst.json; ignoring request.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.