Fork me on GitHub

Pseudocolor schemes for elemental maps

Python's Matplotlib is a simple and effective tool for applying pseudocolor schemes to grayscale elemental maps obtained with an electron microprobe or scanning electron microscope. The code below imports a grayscale image of Mn-zoning in prograde garnet and colorizes it for use in a talk or publication.

Apply a pseudocolor scheme

png

# Setup python environment
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import numpy as np
%matplotlib inline

# Read grayscale image
img = mpimg.imread('grt-wds-mn.png')

# Apply a pseudocolor scheme
lum_img = img[:,:,0]

# plot grayscale map
fig = plt.figure(figsize=(8, 5))
plt.subplot(121)
plt.imshow(img)
plt.title('Greyscale WDS Map')
plt.axis('off');

# plot pseudocolor map
plt.subplot(122)
imgplot = plt.imshow(lum_img)
plt.title('Pseudocolor WDS Map')
plt.axis('off');

# save to png
fig.subplots_adjust(hspace=0.3, wspace=0.05)
plt.savefig('grt-clr.png', dpi=300, bbox_inches='tight')

Apply a gaussian blur

Compositional can often be visually enhanced by applying a weak- to moderate gaussian blur. SciPy profides a simple an effective means of interpolating an image with a gaussian filter by scaling the sigma value.

png

from scipy.ndimage.filters import gaussian_filter

# plot grayscale map
fig = plt.figure(figsize=(12, 5))
plt.subplot(131)
plt.imshow(lum_img)
plt.axis('off');
plt.title('Pseudocolor map, no blur')

# plot gaussian blur, sigma = 1
plt.subplot(132)
sigma1 = gaussian_filter(lum_img, 1)
plt.imshow(sigma1)
plt.axis('off');
plt.title('Pseudocolor map, sigma = 1')

# plot gaussian blur, sigma = 2
plt.subplot(133)
sigma2 = gaussian_filter(lum_img, 2)
plt.imshow(sigma2)
plt.axis('off');
plt.title('Pseudocolor map, sigma = 2')

# save to png
fig.subplots_adjust(hspace=0.3, wspace=0.05)
plt.savefig('grt-blur.png', dpi=300, bbox_inches='tight')

Comments !

social