tueimage / gryds

A Python package for geometric transformations of images for data augmentation in deep learning
https://tue-image.nl
GNU General Public License v3.0
63 stars 14 forks source link

Get exact location of sampling grid points #1

Closed gfotedar closed 5 years ago

gfotedar commented 5 years ago

Is there a way to get the exact location of sampling grid points so I can display the grid before and after BSpline deformation superimposed on the image?

keppenhof commented 5 years ago

Yes, the Grid class has a grid attribute that has the coordinates scaled between zero and one. You can multiply them by the size of the image using the scaled_to() method to get the exact locations:

grid = gryds.Grid(image_shape)
transformed_grid = grid.transform(some_transform, ...)
resized_grid = transformed_grid.scaled_to(image_shape)

The locations in image coordinates are in resized_grid.grid

gfotedar commented 5 years ago

That is not actually what I am looking for. Like in your example on your home page, in this part of code:

# Define a random 3x3 B-spline grid for a 2D image:
random_grid = np.random.rand(2, 3, 3)
random_grid -= 0.5
random_grid /= 5

You define a random_grid of size 3x3. I am looking for locations of these 9 points in [row,column] format, before and after the deformation. I can find their locations after the deformation, using what you told me above, but I need to know the locations before deformation to do that.

keppenhof commented 5 years ago

If I understand you correctly you are looking for the coordinates of the B-spline transformation's control points before the transformation.

These are never explicitly computed in the code. Instead the grid (like the random_grid in the code you reference) is resized to the size of the image you want to transform using B-spline interpolation.

Therefore, you can assume the B-spline control points are evenly distributed over the image's domain, i.e. in 2D