#!/usr/bin/env python # coding: utf-8 # # Heightmap Demo # stough 202- # # In this quick demo I wanted to show how an image can be seen as a height-map, where the xy-plane is the domain of the image, while the z-axis represents the image intensity. This is easy enough with [matplotlib's 3D plotting](https://matplotlib.org/mpl_toolkits/mplot3d/tutorial.html) capability. Specifically I would refer you to the examples [here](https://matplotlib.org/mpl_toolkits/mplot3d/tutorial.html#surface-plots). # In[ ]: get_ipython().run_line_magic('matplotlib', 'widget') import matplotlib.pyplot as plt from matplotlib import cm from mpl_toolkits.mplot3d import Axes3D import numpy as np from skimage import color # For importing from alternative directory sources import sys sys.path.insert(0, '../dip_utils') from matrix_utils import arr_info from vis_utils import vis_image # In[ ]: I = color.rgb2gray(plt.imread('../dip_pics/D_image.jpg')) # In[ ]: arr_info(I) # In[ ]: vis_image(I, cmap='gray') # In[ ]: X, Y = np.meshgrid(range(0,I.shape[0]), range(0,I.shape[1]), indexing='ij') # In[ ]: fig = plt.figure(figsize=(5,5)) ax = fig.add_subplot(111, projection='3d') ax.plot_surface(X, Y, I, cmap=cm.coolwarm); # The argument `projection='3d'` means the `ax` returned is a [Axes3D](https://matplotlib.org/mpl_toolkits/mplot3d/tutorial.html) object. We then call that object's `plot_surface` method with a colormap so that the colors change as a function of the image intensity, or z coordinate. # # Note also that 3D plotting normalizes the units for a square output, even while the original image may not be. Lastly, code that does this surface plotting has been added to [vis_utils](../dip_utils/vis_utils.py) if we need it in the future. # In[ ]: