Comments (1)
Hi @chengjiawang,
There are two ways to visualize the deformed grid:
- Create a mesh grid. Then apply the displacement field to the mesh grid:
def plot_grid(gridx,gridy, **kwargs):
for i in range(gridx.shape[1]):
plt.plot(gridx[i,:], gridy[i,:], **kwargs)
for i in range(gridx.shape[0]):
plt.plot(gridx[:,i], gridy[:,i], **kwargs)
# Assume an image has size 384 x 384
x = np.arange(0, 384, 1)
y = np.arange(0, 384, 1)
X, Y = np.meshgrid(x, y)
u = displacement_field[0, 0, :, :] #batch, channel, size_x, size_y
v = displacement_field[0, 1, :, :] #batch, channel, size_x, size_y
for i in range(0, 384):
for j in range(0, 384):
# Apply displacements
X[i, j] = X[i, j] - u[i, j]
Y[i, j] = Y[i, j] - v[i, j]
plt.figure()
plot_grid(X, Y, color="C0")
plt.title('Deformed grid')
plt.show()
- Create an image with a "synthetic" mesh grid. Then apply the displacement field to the image:
# Assume an image has size 160 x 192 x 224
def mk_grid_img(grid_step, line_thickness=1, grid_sz=(160, 192, 224)):
grid_img = np.zeros(grid_sz)
for j in range(0, grid_img.shape[1], grid_step):
grid_img[:, j+line_thickness-1, :] = 1
for i in range(0, grid_img.shape[2], grid_step):
grid_img[:, :, i+line_thickness-1] = 1
grid_img = grid_img[None, None, ...]
grid_img = torch.from_numpy(grid_img).cuda()
return grid_img
grid_img = mk_grid_img(8, 1, (160, 192, 224))
def_grid = spatial_transformation_function(grid_img.float(), displacement_field.cuda())
def_grid = def_grid.detach().cpu().numpy()[0, 0, :, :, :]
plt.figure()
plt.imshow(img[80, :, :], cmap='gray') # visualize an arbitrary slice
plt.title('Deformed grid')
plt.show()
We used method 2 in our papers because it's more robust and straightforward, and I think the VoxelMorph paper used a similar method as well.
I hope this is helpful.
Junyu
from vit-v-net_for_3d_image_registration_pytorch.
Related Issues (9)
- test the model HOT 3
- How do you setting your data in order to run python train.py? HOT 2
- The process of making and loading datasets HOT 17
- The process of making data HOT 2
- How to use the pretrained model? HOT 1
- Why doesn't the model use the Vecint function? HOT 1
- train error HOT 2
- trainning error HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vit-v-net_for_3d_image_registration_pytorch.