Skip to content

Commit

Permalink
Add rainbow colormap
Browse files Browse the repository at this point in the history
  • Loading branch information
lkaraba committed Dec 13, 2024
1 parent 1f5c7f7 commit abdc2f7
Show file tree
Hide file tree
Showing 7 changed files with 158 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
% % function to set ticks of X-axis and Y-axis

function SetXLimYLimXTick(handle,xmin,xmax,ymin,ymax)

set(handle,'XLim',[xmin xmax]);
set(handle,'YLim',[ymin ymax]);

xtvec=[xmin ,get(gca,'XTick'), xmax];
ytvec=[ymin ,get(gca,'YTick'), ymax];

xtvec=unique(xtvec);
ytvec=unique(ytvec);

set(handle,'XTick',xtvec);
set(handle,'YTick',ytvec);

% % ---------------------------------------
% % This program or any other program(s) supplied with it does not provide any warranty direct or implied.
% % This program is free to use/share for non-commercial purpose only.
% % Kindly reference the work.
% % Author: Dr. Murtaza Khan
% % LinkedIn: http://www.linkedin.com/pub/dr-murtaza-khan/19/680/3b3
% % ResearchGate: http://www.researchgate.net/profile/Murtaza_Khan2/
% % ---------------------------------------
37 changes: 37 additions & 0 deletions plotting/Colormaps/RainbowColormap/RainbowColormap/main.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
clc, close all, clear all

dx = 0.8; % amount of blue and red at the beginning & end of the colormap
n = 32; % number of entries in the rainbow colormap
[cmapRainbow, g, f]=rainbow_cmap(n, dx);
% % -----------------------------------------------
% % Display an image in bone and rainbow colormaps
load spine
figure, image(X), colormap(bone), title('\bf Image in Bone colormap');
figure, image(X), colormap(cmapRainbow), title('\bf Image in Rainbow colormap');

% % -----------------------------------------------
% % Plot transfer functions of rainbow colormap
figure, hold on
plot(g,cmapRainbow(:,1),'r','linewidth',2); %red
plot(g,cmapRainbow(:,2),'g','linewidth',2); %green
plot(g,cmapRainbow(:,3),'b','linewidth',2); %blue
% legend('R','G','B');
handle1=gca;
SetXLimYLimXTick(handle1,0,6,-0.1,1.1);
grid on
title('\bf Rainbow colormap transfer functions');
xlabel('\bf Scalar value g');
ylabel('\bf Transfer functions: R, G, B');


% % -----------------------------------------------
% % This program or any other program(s) supplied with it does not provide any warranty direct or implied.
% % This program is free to use/share for non-commercial purpose only.
% % Kindly reference the work.
% % Author: Dr. Murtaza Khan
% % LinkedIn: http://www.linkedin.com/pub/dr-murtaza-khan/19/680/3b3
% % ResearchGate: http://www.researchgate.net/profile/Murtaza_Khan2/
% % -----------------------------------------------



41 changes: 41 additions & 0 deletions plotting/Colormaps/RainbowColormap/RainbowColormap/rainbow_cmap.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
% % INPUT
% % n: number of entries in the rainbow colormap
% % dx: it controls the amount of pure blue and red used at the
% % beginning and the end of the colormap, respectively

% % OUTPUT
% % cmapRainbow: Rainbow color map values of Red, Green, Blue
% % g: scalar values between dx & (6-dx)
% % f: n values between 0 and 1. g is evaluated at these values

function [cmapRainbow, g, f]=rainbow_cmap(n, dx)

f = linspace(0,1,n); % generates n points between 0 and 1.

cmapRainbow=[];
for i=1:n
g(i) = (6 - 2*dx) * f(i) + dx ; %scale f between dx and (6-dx)
R = max(0, (3 - abs(g(i) - 4) - abs(g(i) - 5))/2);
G = max(0, (4 - abs(g(i) - 2) - abs(g(i) - 4))/2);
B = max(0, (3 - abs(g(i) - 1) - abs(g(i) - 2))/2);
cmapRainbow(i,:)=[R, G, B];
end

g=g'; %change g to column vector
f=f'; %change f to column vector


% % -----------------------------------------------
% % This program or any other program(s) supplied with it does not provide any warranty direct or implied.
% % This program is free to use/share for non-commercial purpose only.
% % Kindly reference the work.
% % Author: Dr. Murtaza Khan
% % LinkedIn: http://www.linkedin.com/pub/dr-murtaza-khan/19/680/3b3
% % ResearchGate: http://www.researchgate.net/profile/Murtaza_Khan2/
% % -----------------------------------------------






Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions plotting/Colormaps/RainbowColormap/RainbowColormap/readme.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Rainbow Colormap
---------------------------------------
Unzip the archive, add to current working directory and run the main.m program. Following MATLAB files are included in the archive:

main.m
A simple test program to plot:
(1) Transfer function of Rainbow Colormap
(2) Display two images, one in bone colormap and one in rainbow colormap

rainbow_cmap.m
A function to compute Rainbow colormap values.


SetXLimYLimXTick.m
A function to set ticks of X-axis and Y-axis

---------------------------------------
% % This program or any other program(s) supplied with it does not provide any warranty direct or implied.
% % This program is free to use/share for non-commercial purpose only.
% % Kindly reference the work.
% % Author: Dr. Murtaza Khan
% % LinkedIn: http://www.linkedin.com/pub/dr-murtaza-khan/19/680/3b3
% % ResearchGate: http://www.researchgate.net/profile/Murtaza_Khan2/
---------------------------------------

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Murtaza Khan, "Rainbow Colormap", June. 2015.
----------------------------------------------

LaTeX

\bibitem{KhanJune2015}
Murtaza Khan, \emph{Rainbow Colormap}, June 2015.
24 changes: 24 additions & 0 deletions plotting/Colormaps/RainbowColormap/license.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Copyright (c) 2015, Murtaza Khan
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the distribution

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.

0 comments on commit abdc2f7

Please sign in to comment.