フィルターのクリア

help in creating a loop

69 ビュー (過去 30 日間)
Mario
Mario 2024 年 7 月 7 日 0:27
コメント済み: Umar 2024 年 7 月 14 日 4:02
Hi all,
I trying to correlate PIV images ( about 100 image). I used the below code that can correlate only the first 2 pair of images and I want to modify the loop so it can correlate the rest images. can somebody help me in modifying the loop?
for i= 1: 100;
for j= 1: 100;
max_correlation=0;
test_xmin=xgrid(i);
test_xmax=xgrid(j)+ 20 %w_width/2;
test_ymin=ygrid(i);
test_ymax=ygrid(j)+ 20 %w_width/2;
x_disp=0;
y_disp=0;
test_ima= Imagea(test_xmin:test_xmax, test_ymin:test_ymax);
test_imb= Imageb(test_xmin-x_disp_max:test_xmax+x_disp_max, test_ymin-y_disp_max:test_ymax+ y_disp_max);
correlation= normxcorr2(test_ima, test_imb);
[xpeak, ypeak]= find (correlation==max(correlation(:) ));
end
end
thanks in advance
  1 件のコメント
Walter Roberson
Walter Roberson 2024 年 7 月 8 日 2:12
for i= 1: 100;
for j= 1: 100;
max_correlation=0;
test_xmin=xgrid(i);
test_xmax=xgrid(j)+ 20 %w_width/2;
test_ymin=ygrid(i);
test_ymax=ygrid(j)+ 20 %w_width/2;
x_disp=0;
y_disp=0;
test_ima= Imagea(test_xmin:test_xmax, test_ymin:test_ymax);
test_imb= Imageb(test_xmin-x_disp_max:test_xmax+x_disp_max, test_ymin-y_disp_max:test_ymax+ y_disp_max);
correlation= normxcorr2(test_ima, test_imb);
[xpeak{i,j}, ypeak{i,j}]= find (correlation==max(correlation(:) ));
end
end

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

採用された回答

Umar
Umar 2024 年 7 月 8 日 2:17

Hi Mario,

Based on the provided code snippet, it seems like you are attempting to correlate PIV (Particle Image Velocimetry) images using a nested loop structure in MATLAB. To modify the loop to correlate all 100 PIV image pairs, you need to adjust the loop structure and indexing. The current code snippet provided runs nested loops for all image pairs but does not store or utilize the correlation results effectively. You can modify the loop as follows:

for i = 1:99

    for j = i+1:100
        max_correlation = 0;
        test_xmin = xgrid(i);
        test_xmax = xgrid(j) + 20;
        test_ymin = ygrid(i);
        test_ymax = ygrid(j) + 20;
        x_disp = 0;
        y_disp = 0;
        test_ima = Imagea(test_xmin:test_xmax, test_ymin:test_ymax);
        test_imb = Imageb(test_xmin - x_disp_max:test_xmax + x_disp_max, test_ymin - y_disp_max:test_ymax + y_disp_max);
        correlation = normxcorr2(test_ima, test_imb);
        [xpeak, ypeak] = find(correlation == max(correlation(:)));
        % Store or process correlation results here
    end
end

This modified loop structure ensures that each image pair is correlated exactly once, avoiding redundant calculations. Remember to include the necessary logic to store or process the correlation results as needed for your application.

If you encounter any issues or need further assistance, feel free to ask for more help!

  10 件のコメント
Mario
Mario 2024 年 7 月 14 日 2:51
Hi Umar,
I am trying to implement two point correlation between PIV images using the pervious mentioned code. Can you advise me how can I dynamically adjust the size of the `correlation` matrix?
thanks in advance
Mario
Umar
Umar 2024 年 7 月 14 日 4:02
Hi Mario,
It is adjusted based on the dimensions of the images being compared (`test_ima` and `test_imb`). By calculating the appropriate size of the correlation matrix before computing the normalized cross-correlation.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by