image thumbnail

Julia

by

 

Become a cyber explorer and use Julia to navigate the Fractal world!

C=make_colour_matrix(A,cmap,NaN_colour)
%make_colour_matrix
% Function that takes a two dimensional array of intensities
% and converts this into am RGB array for use in the imwrite.m function
%
% LAST UPDATED by Andy French. 07/03/2011
%
% Syntax: C=make_colour_matrix(A,cmap)
%
% A      - M x N array of 'intensities', these should be normalised such as
%          the magnitudes will be in the interval [0,1.
% cmap   - Colour map. i.e.  cmap=colormap('prism')
% NaN_colour
%        - [R,G,B] vector of NaN colours
%
% C      - M x N x 3 RGB matrix. Each page corresponds to RGB colurs
%          (respectively) in the range [0,1];

function C=make_colour_matrix(A,cmap,NaN_colour)

%Get dimensions of colourmap and initialise red, green and blue vectors
cmap_dim=size(cmap);
red=zeros(1,cmap_dim(1));
green=zeros(1,cmap_dim(1));
blue=zeros(1,cmap_dim(1));
red(:)=cmap(:,1);
green(:)=cmap(:,2);
blue(:)=cmap(:,3);

%Define colour scale 0...1 to enable the colormap to be interpolated
cscale=linspace(0,1,cmap_dim(1));

%Initialise output RGB matrix
C=zeros([size(A),3]);

%Determine R,G,B components of C using linear interpolation of the
%colormap. Set NaNs to be the specified NaN colour.
C_red=interp1(cscale,red,A);
C_red(find(isnan(C_red)==1))=NaN_colour(1);
C_green=interp1(cscale,green,A);
C_green(find(isnan(C_green)==1))=NaN_colour(2);
C_blue=interp1(cscale,blue,A);
C_blue(find(isnan(C_blue)==1))=NaN_colour(3);
C(:,:,1)=C_red;
C(:,:,2)=C_green;
C(:,:,3)=C_blue;

%End of code

Contact us