Using sgolayfilt in derivative analysis of absorption images
3 views (last 30 days)
Show older comments
I want to apply this equation to my absorption images at 655 nm

This code enables me to do that
fileDirectory = "/Volumes/Extreme_SSD/HPLC validation images";
filename = dir(fullfile(fileDirectory, '*aph.nc'));
nFileDirectory = length(filename);
%create directories for the chlorophyll (yearwise)
outputFolder = "/Volumes/Extreme_SSD/HPLC validation images";
for i=1:nFileDirectory
nFileAph = strcat(filename(i).folder, "/", filename(i).name);
ncdisp(nFileAph);
info = ncinfo(nFileAph);
dim = cell2mat({info.Variables.Dimensions});
ncol = dim(2).Length;
nrow = dim(1).Length;
aph654 = ncread(nFileAph, "a_ph_654");
aph656 = ncread(nFileAph, 'a_ph_656');
deltaLambda = 1; % nm
% derivative of 655
aph_deriv_655 = (aph656 - aph654) / (2 * deltaLambda);
end
now I am confused how to use filter such as sgolayfilt (window = 7, wavlength gap 5 nm) in the derived image.
1 Comment
Walter Roberson
on 28 Jun 2025
dim = cell2mat({info.Variables.Dimensions});
It seems likely to me that the above line could be coded as
dim = [info.Variables.Dimensions];
Answers (1)
Star Strider
on 27 Jun 2025
The sgolayfilt function is used in signal processing of one-dimensional signals, not image processing of two-dimensional arrays. It creates a FIR smoothing filter (essentially a lowpass filter), however it is not obvious to me how your 'window' and wavelength gap would translate to framelength and polynomial order. It operates on each column of a matrix. (As a general rule, I use a third-order polynomial, and experiment with the framelength to get the result I want.) Filtering your matrix using sgolayfilt, transposing it and filtering it a second time using the same sgolayfilt call, and transposing it back to the original orientation could work. You will have to experiment to see if that produces an acceptable result.
The imfilter function can do image filtering, however it requires a multidimensional filter, and sgolay creates a unidimensional filter. It is not obvious how vector operations on two sgolay filters (not using sgolayfilt) would work to create a two-dimensional filter and retain the desired spectral characteristics.
What do you actually want to do?
4 Comments
Star Strider
on 28 Jun 2025
It would probably be best for you to use the imgaussfilt function, since the Gaussian fspecial filter is no longer recommended.
(Answers is having serious problems currently. My apologies for the delay.)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!