To Apply 2D sliding window on data to calculate doppler parameter rapidly

7 Ansichten (letzte 30 Tage)
I need help to merge 2-for loops using filter2 (2D) filter or any suitable way to make my code efficient enough.
I want to run a 2D sliding window of 256*256 to move through whole data and calculate one 'dc' for each patch, moreover, I just received last value of ''dc'' while rest of previous values are 0.
img= [1:1664,1:4352] %% Size of image
PRF = 1925;
k = 128; % size of patch
C= zeros(size(img));
for i = k+1:size(img_o,1)-k
for j = k+1:size(img_o,2)-k
Bb = img_o(i-kk:i+kk-1, j-kk:j+kk-1);
dc(k) = doppler_centroid(Bb, PRF); %% this function calculate doppler centroid ''dc''
C(i,j) = dc(k);

Akzeptierte Antwort

Shashank Gupta
Shashank Gupta am 26 Mai 2021
Hi Amjad,
There are many things, I don't understand in the code. First line defining the variable "img" seems odd because the way you defined it give the same of "img" as [ 1 ,6016] which I don't think is intended. May be that's the reason of you getting abrubt values in C. You can simply define the size of image in img and define C accordingly
img = [1664,4352] % Size of image.
C = zeros(img); % Define C according to the size of image.
Also, yes these can be optimized, I don't know what the doppler_centroid function do. But you can remove both the for loop and convert this problem in matrix space and then use a convolution filter to solve the problem, Refer conv2 function. I will give an example describing how it can be useful.
% Let try to find a simple mean of the sliding window.
A = rand(10,10);
B = ones(2,2)./4; % Design a matrix for taking average.
C = conv2(A,B,"same"); % This matrix is the result of average over a sliding window of length 2.
Do try out the above code and adapt in your case.
I hope this helps.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by