limit the search for maximums to a specific region
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Vittorio Locatelli
el 12 de Mayo de 2022
Comentada: Voss
el 13 de Mayo de 2022
Good morning,
I am writing because, as the title suggests, I need to limit the search for maximums in a specific region. What I have to do is basically obtain a specific section from an image to find the color spectrum and from this identify the peaks approximately from 1500 to 3000 pixels.
In the findpeaks tab I have not found anything that can do for me.
I turn to you hoping for constructive help.
Thanks in advance for the answers.
% % mostra imgrifpixelscaled
figure
imshow(imgrifassps)
% % cattura punti di riferimento; nota: considera 10mm, mantieniti al centro della figura e prendi il primo punto a sinistra e il secondo punto a destra, infine la sezione di riferimento assoluta e poi relativa
[x,y]=ginput(4);
% % crea sezione di riferimento assoluto
sezionerifass=imgrifassps(round(y(3)),:);
% % fitting sezione rif ass
[xData, yData]=prepareCurveData( [], sezionerifass );
ft=fittype( 'smoothingspline' );
opts=fitoptions( 'Method', 'SmoothingSpline' );
opts.SmoothingParam=0.001;
[fitresult,gof]=fit( xData, -yData, ft, opts );
% % crea variabile sezione di riferimento assoluto fittata
sezionerifassfit=fitresult(xData);
% % trova picchi sezione di riferimento assoluto fittata
[prifass,locsrifass]=findpeaks(sezionerifassfit,"MinPeakHeight",-100,"NPeaks",7);
0 comentarios
Respuesta aceptada
Voss
el 13 de Mayo de 2022
Instead of inputting the entire array into findpeaks, you can simply input the part of the array you want to search, and then adjust the outputted indices appropriately.
% a signal with some peaks
t = 0:0.01:8*pi;
y = sin(t);
plot(t,y)
ylim([-1.1 1.1]);
hold on
% find the locations of the peaks in y
[~,idx] = findpeaks(y)
% plot them in red
plot(t(idx),y(idx),'ro','MarkerFaceColor','r')
% now find the peaks just among index 500 to index 1500 of y
[~,idx] = findpeaks(y(500:1500))
% adjust the indices of the peaks
% (index 1 in y(500:1500) corresponds to index 500 in y)
idx = idx+499
% plot them in green
plot(t(idx),y(idx),'g.')
% show the search region for reference
xline(t([500 1500]),'--')
2 comentarios
Voss
el 13 de Mayo de 2022
You're welcome!
If everything makes sense, please click 'Accept This Answer'. Otherwise, let me know any questions you have. I appreciate it!
Más respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!