Introduction
In my last post I described how to create a powerful, nondirectional shading for a geophysical surface using the slope of the data to assign the shading intensity (i.e. areas of greater slope are assigned darker shading). Today I will show hot to create a similar effect in Matlab.
Since the data set I use is from my unpublished thesis in Geology, I am not able to share it, and you will have to use your own data, but the Matlab code is simply adapted. The code snippets below assume you have a geophysical surface already imported in the workspace and stored in a variable called “data”, as well as the derivative in a variable called “data_slope”.
Method 1 – with a slope mask and transparency
Some time ago I read this interesting Image Processing blog post by Steve Eddins at Mathworks on overlaying images using transparency. I encourage readers to take a look at this and other posts by Steve, he’s great! That particular blog post gave me the idea to use transparency and the slope to create my favorite shading in Matlab.
In addition to the code below you will need normalise.m from Peter Kovesi‘s website, and to import the color palette cube1.
%% alpha transparency code snippet black = cat(3, zeros(size(data)), zeros(size(data)), ... zeros(size(data))); % make a truecolor all-black image gray=black+0.2; % make a truecolor all-gray image alphaI=normalise(data_slope); % create transparency weight matrix % using data_slope imagesc(data);colormap(cube1); % display data hold on h = imagesc(gray); % overlay gray image on data hold off set(h, 'AlphaData', alphaI); % set transparency of gray layer using axis equal; % weight matrix axis tight; axis off;
And here is the result in Figure 1 below – not bad!
Figure 1. Shaded using transparency