I try to render the classic rice.png image for an image processing class but I cannot get the result I want.
import matplotlib.pyplot as plt
import numpy as np
from scipy import misc
from matplotlib import cm
from mpl_toolkits.mplot3d import Axes3D
# rice.png is the image one can find on the internet
rice = misc.imread('rice.png')
height, width = rice.shape
fig = plt.figure(2)
ax = fig.gca(projection='3d')
X = np.arange(0, height, 1)
Y = np.arange(0, width, 1)
X, Y = np.meshgrid(X, Y)
surf = ax.plot_surface(X, Y, rice, cmap=cm.coolwarm, linewidth=0)
plt.title('3D representation of image')
plt.show()
I tried using set_zticks but the ticks overflow as in the image above, I tried also the solutions one can see here but it overflows also and/or give poor result.
My goal is to have something like what can be seen in the paragraph how can I do so ?
[edit] I have already seen this question that gives a less complete answer that what can be found in the other link I gave earlier (idea of overriding the proj fonction).
However, I am not happy with the results. First because it means I have to change a functions in the matplotlib library (if I follow the SO solution) and as I will share my code with other students from my class, I do not want to do so. Then because it does not give me the same result (see later) it does not center the image, it just change the scale then cut the above part.
[edit2] update of the code