How to plot Intensity vs wavelength of an image?
32 views (last 30 days)
Show older comments
Quintus on 26 Jan 2023
Commented: DGM on 29 Jan 2023
I want to take an image as input and detect the colors' wavelengths in that image. Then I need to determine the intensities of those wavelengths and plot intensity vs wavelength. Is it doable?
Image Analyst on 26 Jan 2023
In general, no, though attempts have been made with various assumptions about the illuminant and spectral responsivities of the camera sensor. You can have the same color with many, many different spectra, so which spectra do you pick?
DGM on 29 Jan 2023
I realized that underfilling the curve was a bit more of a hassle, so here's an example.
% get image
inpict = imread('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1277300/image.png');
% crop out relevant region
% this relies on the pattern being grid-aligned
inpict = imcrop(inpict,[72 68 305 20]);
% convert to grayscale somehow
%inpict = mean(im2double(inpict),3); % average?
%inpict = rgb2gray(im2double(inpict)); % BT601 luma?
inpict = imapplymatrix([0.2126 0.7152 0.0722],im2double(inpict)); % BT709 luma?
% ... or use some sort of system-specific intensity calibration information
% generate profile by averaging off-axis
% again, this relies on the pattern being grid-aligned
profile = mean(inpict,1);
% rough frequency calibration
lbref = [494 693]; % wavelengths of known peaks
idx = [77 209]; % the indices in profile corresponding to those peaks (manually picked)
lambda = interp1(idx,lbref,1:numel(profile),'linear','extrap');
% generate patch vertex coordinates
xx = [lambda fliplr(lambda)];
yy = [profile zeros(size(profile))];
% create color data for each vertex pair
CT = getcdata(lambda);
cc = [1:numel(lambda), numel(lambda):-1:1];
% plot the profile
function CT = getcdata(vtxlambda)
% location of gradient breakpoints (in wavelength)
x0 = [312 381 403 419 440 492 512 580 646 652 779 927];
CT0 = [0 0 0; 0 0 0; 0.353 0 0.563; 0.353 0 1; 0 0 1; 0 1 1;
0 1 0; 1 1 0; 1 0 0; 1 0 0; 0 0 0; 0 0 0];
% look up colormap colors for each vertex lambda
CT = interp1(x0,CT0,vtxlambda,'linear','extrap');
You could generate the pseudocolor map however you choose, but I derived this from the screenshot.
Find more on Image Arithmetic in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!