1

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()

But that gives me this : graphe

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.

enter image description here

[edit2] update of the code

Community
  • 1
  • 1
M0rkHaV
  • 432
  • 1
  • 4
  • 16
  • I think this is a duplicate, though I was a bit surprised when my voting to close was the final word on closing the question. if it's not a duplicate, please explain why and I'll try to reopen. – tom10 Aug 15 '15 at 23:14
  • I edited the question. I understand that it seemed like a duplicate, I should have been more precise in my question. – M0rkHaV Aug 16 '15 at 16:28
  • 1
    Please edit the code so that it can run without forcing us to guess which libraries you are using. Furthermore, based on the assumption that `misc` is `matplotlib.pyplot` and that rice.png is the image that I downloaded from the specified link, your code does not run (on my end) because of `ValueError: too many values to unpack` that is thrown by your `height, width = rice.shape` line. – Bas Jansen Aug 16 '15 at 23:38
  • Done. Now copy and paste is enough if you have the librairies installed. – M0rkHaV Aug 17 '15 at 11:42

0 Answers0