Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The dimension of warp in register.py #544

Open
FindSmart opened this issue Aug 30, 2023 · 3 comments
Open

The dimension of warp in register.py #544

FindSmart opened this issue Aug 30, 2023 · 3 comments

Comments

@FindSmart
Copy link

Hi,
The pictures I use are two-dimensional, with a pixel size of 480*640. After deep learning, I use register.py to obtain the displacement field (warp). When I apply the displacement field to the original image, I find that the ndarray of the warp image is (2, 480, 640), what displacement do the two layers here represent?
Thank you so much!

@adalca
Copy link
Collaborator

adalca commented Aug 30, 2023

@FindSmart can you give us the command you run with register.py, and what exactly is [2, 480, 640] ? That sounds like the warp itself --- (x, y) displacement --- not the warped image

@FindSmart
Copy link
Author

FindSmart commented Aug 31, 2023

@FindSmart can you give us the command you run with register.py, and what exactly is [2, 480, 640] ? That sounds like the warp itself --- (x, y) displacement --- not the warped image

Thanks for your reply!
I run register.py on Windows, so i don't use any commands. Here is the code I modified:
for i in range(1, 201):
directory1 = r'D:\PersonalFiles\niigzregister-2'
directory2 = r'D:\PersonalFiles\niigzregister-2after'
directory3 = r'D:\PersonalFiles\warp-2'
filename = str(i)
extension = '.nii.gz'

string_moving = os.path.join(directory1, filename + extension)
string_moved = os.path.join(directory2, filename + extension)
string_warp = os.path.join(directory3, filename + extension)
# parse commandline args
parser = argparse.ArgumentParser()
parser.add_argument('--moving', default=string_moving, help='moving image (source) filename')
parser.add_argument('--fixed', default=r'D:\PersonalFiles\niigzregister-2\1.nii.gz', help='fixed image (target) filename')
parser.add_argument('--moved', default=_string_moved_, help='warped image output filename')
parser.add_argument('--model', default=r'D:\PersonalFiles\voxelmorph-dev\scripts\torch\2023.7.18 dashu 1.6x 20ms doudong register\3000.pt', help='pytorch model for nonlinear registration')
parser.add_argument('--warp', default=string_warp , help='output warp deformation filename')
parser.add_argument('-g', '--gpu', help='GPU number(s) - if not supplied, CPU is used')
parser.add_argument('--multichannel', action='store_true',
                    help='specify that data has multiple channels')
args = parser.parse_args()

The output 'warp' is [2,480,640], and it really means (x, y) displacement. I have just come into contact with this field, so I don’t really understand these. I want to apply the warp image to the original image for registration, should i move the x and y pixels of the original image according to the warp separately?

@adalca
Copy link
Collaborator

adalca commented Aug 31, 2023

a warp field tells you how to move pixels/voxels in one image to match up with the other one.
Our tutorial at https://tutorial.voxelmorph.net/ should help you understand these concepts.

Our register.py script will apply the warp to one image and warp it. It outputs (saves) both the warp and the warped image, so you should already have what you need from it. In general, to warp one moving image using a warp we use:

moved = vxm.networks.Transform(inshape, nb_feats=nb_feats).predict([moving, warp])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants