Created
December 19, 2018 21:42
-
-
Save neonb88/dbdab1d05f735ae4bc38b6a1e09bbb84 to your computer and use it in GitHub Desktop.
demonstrates bugs with scipy.ndimage.rotate()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import matplotlib.pyplot as plt | |
import numpy as np | |
from scipy.ndimage import rotate | |
from mpl_toolkits.mplot3d import Axes3D | |
def print_loc_discrete(arr): | |
''' | |
for bools (ie. if the val of the arr is either on or off, not a number) | |
''' | |
# TODO: merge this func with the other (as of December 16, 2018 it was called "print_loc_continuous(arr)") and auto-detect whether there are bools or continuous datatypes | |
if len(arr.shape) == 3: | |
for x in range(arr.shape[0]): | |
for y in range(arr.shape[1]): | |
for z in range(arr.shape[2]): | |
if arr[x,y,z]: | |
print "on loc is {0}, {1}, {2}.".format(x,y,z) | |
return arr | |
def print_loc_continuous(arr): | |
''' | |
for ints, floating pt nums | |
''' | |
if len(arr.shape) == 3: | |
for x in range(arr.shape[0]): | |
for y in range(arr.shape[1]): | |
for z in range(arr.shape[2]): | |
if arr[x,y,z]: | |
print "at loc ({0}, {1}, {2}), val is {3}.".format(x,y,z,arr[x,y,z]) | |
return arr | |
model=np.zeros((8,8,8)).astype('uint8'); uint8_max=np.iinfo('uint8').max | |
model[2:4,2:4,2:4]=int(round(uint8_max/2.)) | |
#angle=90.0 | |
angle=181.1 | |
xy=(0,1) | |
xz=(0,2) | |
yz=(1,2) | |
#plot | |
print_loc_continuous(model) | |
fig = plt.figure() | |
ax = fig.gca(projection='3d') | |
x_str='this is the x axis'; y_str='this is the y axis'; z_str='this is the z axis' | |
ax.set_xlabel(x_str); ax.set_ylabel(y_str); ax.set_zlabel(z_str) | |
ax.voxels(model, edgecolor='k') | |
plt.show() | |
plt.close() | |
print "\n"*3 | |
print "now rotating... \n\n" | |
model=rotate(model, angle, axes=xz) | |
print_loc_continuous(model) | |
# 5,5,2 for ax=xy, angle=180. | |
# 5,2,5 for ax=xz, angle=180. | |
fig = plt.figure() | |
ax = fig.gca(projection='3d') | |
ax.set_xlabel(x_str); ax.set_ylabel(y_str); ax.set_zlabel(z_str) | |
ax.voxels(model, edgecolor='k') | |
plt.show() | |
plt.close() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment