You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to create a function in Pyvips that perform elastic deformation transformations. I managed to get the function itself to work, however the algorithm I am trying to implement expects uniform sampled noise in the [0,1] range[1]. My question is if there is such a function in Pyvips, since I managed to only find gaussian, perlin, and worley noise.
The way I circumvented this is by using an inverse box-muller transformation on two independent Gaussians, but I recon that this is not the most efficient way to do this.
P.s.: is there a way to set the seed globally for the noise functions, or is defined per function?
defelastic_deformation(image, sigma=16, alpha=1):
width, height, channels=image.width, image.height, image.bands# Create a random displacement field, pyvips does not have uniform# instead, use a Gaussian and convert using Box-Muller inversez1=pyvips.Image.gaussnoise(width, height, sigma=1.0, mean=0.0, seed=1)
z2=pyvips.Image.gaussnoise(width, height, sigma=1.0, mean=0.0, seed=1)
# Compute box-muller inverse to get approximate uniform valuesdx= (-(z1*z1+z2*z2) /2).exp()
dx= (2*dx-1).gaussblur(sigma) *alphady= (z1/z2).atan()
dy= (2*dy-1).gaussblur(sigma) *alphagrid=pyvips.Image.xyz(image.width, image.height)
map=grid+dx.bandjoin([dy])
image=image.mapim(map, interpolate=pyvips.Interpolate.new('bilinear'), background=[255, 255, 255])
returnimage
[1] Simard2003] Simard, Steinkraus and Platt, "Best Practices for Convolutional Neural Networks applied to Visual Document Analysis", in Proc. of the International Conference on Document Analysis and Recognition, 2003
The text was updated successfully, but these errors were encountered:
Hi,
I'm trying to create a function in Pyvips that perform elastic deformation transformations. I managed to get the function itself to work, however the algorithm I am trying to implement expects uniform sampled noise in the [0,1] range[1]. My question is if there is such a function in Pyvips, since I managed to only find gaussian, perlin, and worley noise.
The way I circumvented this is by using an inverse box-muller transformation on two independent Gaussians, but I recon that this is not the most efficient way to do this.
P.s.: is there a way to set the seed globally for the noise functions, or is defined per function?
[1] Simard2003] Simard, Steinkraus and Platt, "Best Practices for Convolutional Neural Networks applied to Visual Document Analysis", in Proc. of the International Conference on Document Analysis and Recognition, 2003
The text was updated successfully, but these errors were encountered: