scipy.ndimage.zoom result depends on image size

烂漫一生 提交于 2019-12-04 07:35:18

i'ts been a while since you posted your question... in case you're still interested, I had a similar problem and used the following:

import skimage
data_new = skimage.transform.resize(data_old, [new_shape_x, new_shape_z], order = 0)

Make sure you set order = 0, because the default is order = 1, which will result in a first order spline interpolation between the values (this causes the tiles to blur at their boundaries).

Anyway, I don't know if that's a good way to do it, it worked for me though. I can't answer if it's a bug, because I really don't know enough about programming to answer that. Furthermore I also tried to use the the scipy.ndimage.interpolation.zoom function, but then the boundaries of the tiles weren't where they should be, like in your case. Therefore I used skimage.

In case you're interested in the context: I worked on fracture-mechanics and needed to create random strength-distributions that are varying smoothly. So I created a surface with a combination of sinus and cosinus funcitons, that had a certain number of periods in x and z direction. Then I took the absolute value of that surface and multiplied it with an irregular chessboard-like surface. The numbers of tiles in each direction on the chessboard-like surface had to match the number of periods/2 in the corresponding strength-variation surface. The final surface was calculated as follows (piecewise addition and multiplication):

strength_surface[i,j] = strength_mean[i,j] + random_grid[i,j] * strength_variation[i,j]

where random_grid had to be resized to match the shape of the other surfaces.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!