Code covered by the BSD License  

Highlights from
Spectral and XYZ Color Functions

3.90909

3.9 | 11 ratings Rate this file 86 Downloads (last 30 days) File Size: 33.29 KB File ID: #7021
image thumbnail

Spectral and XYZ Color Functions

by Jeff Mather

 

01 Mar 2005 (Updated 08 Nov 2010)

Label plots with spectra. Convert wavelengths to RGB. Functions for color matching and illuminants.

| Watch this File

File Information
Description

This is the beginning of a set of functions for working with color as wavelengths (spectral color) and in the xyY and XYZ color spaces.

Current functionality includes:

spectrumLabel - Add a color bar containing the visible spectrum to a plot's X axis.

spectrumRGB - Converts wavelengths of light to equivalent RGB values (in the sRGB space).

colorMatchFcn - Raw data of popular color matching functions (spectra to XYZ) for various standard observers:
  * CIE 1931 2-degree
  * CIE 1964 10-degree
  * CIE 1931 2-degree modified by Judd (1951)
  * CIE 1931 2-degree modified by Judd (1951) and Vos (1978)
  * Stiles and Burch 2-degree (1955)
  * Stiles and Burch 10-degree (1959)

illuminant - Raw data for the A, D65, and E standard illuminants.

Acknowledgements
This submission has inspired the following:
Perceptually improved colormaps , MKPJ - perceptually improved Jet colormap
Required Products Image Processing Toolbox
MATLAB release MATLAB 7.0.1 (R14SP1)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (16)
21 Jul 2005 Wu John

Good job! Thank you,but how about the other light source in illuminate.m?

01 Oct 2005 colour rainbow

could you able to create function for r2xyz
for 1xm or 1xn matrix

18 Oct 2005 marwan reyadh

please how can i convert an image from RGB of size n*n*3 to an image with of size n*n*n

28 Oct 2005 Levent Onural

Thanks a lot, I have been looking for how I could generate the matching functions for 5 hours. Excellent piece of work...

06 Apr 2006 ben taylor

Does anyone know hot to convert it the other way? I have an RGB image of black body radiation and I am writing a program that will give me a 3d temperature plot, but I need to convert from RGB to wavelength to temperature.

Thanks,

03 Jan 2007 Vishnuvenkatesh Dhage  
26 Apr 2007 NOne None

None

20 Jun 2007 jeongwoon lee  
12 Dec 2007 Neeraj Adsul  
07 Oct 2008 Franck Riberi

Need demo files absolutely.

19 May 2010 Mike Vasilescu

how do I get the spectrumon jpg?

20 Sep 2010 Matteo Niccoli

Great submission!

04 Sep 2011 springface

Thanks to this excellent work, I've been able to image a spectrum plot with both the characteristic peaks marked in colors and intensity plot shown. The code is as following.

%%%%%%%%%%%%%%%%%%%%%%
function SpecRGB_Intensity(wavelength,intensity, peak_threshold)
% wavelength and intensity are vectors
% the characteristic peaks are chosen if the value of the peak
% is bigger than the peak_threshold.
% by springface

sRGB = spectrumRGB(wavelength);

%% Transform spectrum plot into an image, marked by colors
len_wave = length(wavelength);
len_inten = 1000;
intensity_plot = max(intensity):-max(intensity)/(len_inten-1):0;
wavelength_plot = wavelength;

intensity_num = ones(size(intensity));

for cc = 1: len_wave
    if intensity(cc)>=0
        [C,I] = min(abs(intensity(cc)- intensity_plot));
        intensity_num(cc) = len_inten-I;
    end
end

im_plot = ones(len_inten,len_wave,3);

for cc = 1: len_wave
    im_plot(1:intensity_num(cc),cc,:) = repmat(sRGB(1,cc,:),intensity_num(cc),1);
end

%% mark the non-peak area as black
spec_idx = intensity < peak_threshold;
sRGB(1,spec_idx,:) = zeros(1,sum(spec_idx),3);

%% Plot figures
figure;

whitegap_len = 2;
RGBspec_len = 100;

RGBspec_range = max(intensity)+whitegap_len+RGBspec_len+1:max(intensity)+1;

imagesc(wavelength_plot,[RGBspec_range,intensity_plot],...
    cat(1,repmat(sRGB,RGBspec_len,1),ones(whitegap_len,len_wave,3),im_plot));
set(gca,'YTick',[])
%%%%%%%%%%%%%%%%%%%%%%

04 Sep 2011 springface

but there seems to be a scale off. I don't know how to solve that. Please help!

01 Jan 2012 Li

I got this error information:
"the selected cell cannot be evaluated because it contains an invalid statement".
"??? Input argument "formulary" is undefined."
Any idea why this happen? Thank you!

07 Feb 2012 Guido

Help!
I'm trying to use spectrumLabel for a calculated absorption spectrum.
It works fine from the command window, but I'm not able to put the color axis in a plot which is rendered to a GUI.
Here is the piece of code that I put in the .m file. The plot of the extinction, scattering and absorption spectra are sent to the axes style GUI handles.axes1:
----------------------------
axes(handles.axes1);
plot(wave,qext,wave,qsca,wave,qabs);
title('Spectrum');
xlabel('Wavelength (nm)');
ylabel('Arbitrary units');
spectrumLabel(handles.axes1);
-------------------------------
Apparently, the spectrumLabel is put at the right position but with zero or very small vertical dimension.
Thank you!

Please login to add a comment or rating.
Updates
08 Nov 2010

BSD License

Tag Activity for this File
Tag Applied By Date/Time
color Jeff Mather 22 Oct 2008 07:42:16
spectrum label color spectra wavelength d65 illuminant visible c Jeff Mather 22 Oct 2008 07:42:16
spectrum label color spectra wavelength d65 illuminant visible c Ture VP 17 Nov 2008 05:29:11
color Shin-Ying Lu 31 Mar 2009 18:00:28
spectrum label color spectra wavelength d65 illuminant visible c Byeong-Seok 17 Jun 2010 22:01:27
color Byeong-Seok 17 Jun 2010 22:01:29
color long Chang 03 Aug 2011 12:45:31

Contact us at files@mathworks.com