Findpeaks creates empty arrays in for loop
2 ビュー (過去 30 日間)
古いコメントを表示
Hello,
I'm defining a for loop to use on a laser stripe image and does the following:
- takes a row
- filters the row ( I take only the bigest and lowest peak)
- gets the gradient
- use findpeaks to get the position and value of the gradient max and min
- create a line between these two points
- get the 0 crossing
Right now im able to get the 0 crossing of just one line. Im stuck in the "for" loop as the findpeaks function is creating empty arrays I dont know why!
The aim is to get the 0 crossing of all the image rows, then plot all.
Please any help?
img_peaks = NaN(rows, 1);
xp = [];
yp = [];
Xn=[];
Yn=[];
for i=1:rows
img_puntos(i,:)=img(i,:);
%filtrado
filtrado=sgolayfilt(double(img_puntos(i,:)),3,33 );
for k=1:length(filtrado)
if filtrado(k)<0
filtrado(k)=0;
end
end
%derivada
derivada=gradient(filtrado);
%maximo y minimo
[yp,xp]=findpeaks(derivada); % HERE IS THE PROBLEM!!!
[Xn,Yn]=findpeaks(-derivada);% HERE IS THE PROBLEM!!!
%coeficientes de la recta
% coeficientes = polyfit([Xp, Xn], [Yp, -Yn], 1);
% m = coeficientes (1);
% n = coeficientes (2);
% % 0 crossing
% zerocross= -m/n;
img_peaks(i) = subpixel;
end
1 件のコメント
dpb
2021 年 3 月 15 日
Not the problem with the data, but in MATLAB replace
for k=1:length(filtrado)
if filtrado(k)<0
filtrado(k)=0;
end
end
with
filtrado(filtrado<0)=0;
The problem in your code is that you didn't write code to handle the possibility a given row in the image may, indeed, not have a discernible peak.
We have no way to know anything about whether there's some way to be able to help findpeaks locate minimal excursions or not without the data to observe; generally it is pretty adept--but, it's designed for typical time series one obtains from things like measurements of acceleration or the like; depending upon what your image looks like, it might not be the best tool.
Or, there just may not be any discernible peaks in the data you have...
回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!