limit the search for maximums to a specific region

1 回表示 (過去 30 日間)
Vittorio Locatelli
Vittorio Locatelli 2022 年 5 月 12 日
コメント済み: Voss 2022 年 5 月 13 日
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);

採用された回答

Voss
Voss 2022 年 5 月 13 日
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)
idx = 1×4
158 786 1415 2043
% 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))
idx = 1×2
287 916
% adjust the indices of the peaks
% (index 1 in y(500:1500) corresponds to index 500 in y)
idx = idx+499
idx = 1×2
786 1415
% plot them in green
plot(t(idx),y(idx),'g.')
% show the search region for reference
xline(t([500 1500]),'--')
  2 件のコメント
Vittorio Locatelli
Vittorio Locatelli 2022 年 5 月 13 日
Thank you very much, now that you have told me the solution is quite simple. Thanks again.
Voss
Voss 2022 年 5 月 13 日
You're welcome!
If everything makes sense, please click 'Accept This Answer'. Otherwise, let me know any questions you have. I appreciate it!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDescriptive Statistics についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by