How to count patches on a matrix?
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hi, I have a matrix (img_interp) 512x512, which is rebuilt using some patches (p) 5x5. Now, I want to count the number of overlapping patches on the main matrix (img_interp). How can I do? the code is below
clear all
% image creation
N = 100;
dr = 5; dc = 5; %displacements
pr = 100; pc = 100; %positions
x = zeros(512,512); x(pr+(1:N),pc+(1:N))=255*ones(N,N);
img1 = x;
x = zeros(512,512); x(pr+dr+(1:N),pc+dc+(1:N))=255*ones(N,N);
img2 = x;
% Calculation UV
uv=calcolaOF(img1, img2);
u=uv(:,:,1);
v=uv(:,:,2);
% plot motion vector
%figure, quiver(u, v, 'color', 'b', 'linewidth', 5);
% set(gca,'YDir','reverse');
% title('Flow Vector','color','red');
count = zeros(size(img1)); % count patch contributions to individual pixels
[Nrow, Ncol] = size(img1);
img_interp = zeros(size(img1)); % interpolated frame
dim_filtro=7;
Np = 5; % patch size
skip = 2; % skip between patches
uvm=zeros(size(uv));
% ciclo sulle patch
for i=1:skip:Nrow-Np+1
for j=1:skip:Ncol-Np+1 %2 cicli for per iterare ciascun patch
p = img1(i+(0:Np-1),j+(0:Np-1)); % patch img1
uvp = uv(i+(0:Np-1),j+(0:Np-1),:); %patch matrix uv
%riga 56 = riga 55 + riga 54
uvm = VectorMedianFilterP(uvp, dim_filtro);
um=uvm((Np+1)/2,(Np+1)/2 , 1);
vm=uvm((Np+1)/2,(Np+1)/2 , 2);
% interpolation
[X,Y] = meshgrid(0:Np-1); % grid for original patch
[Xdr,Ydc] = meshgrid(0:Np-2) ; % grid for new patch
X=X+(um/2);
Y=Y+(vm/2);
p_int= interp2(X,Y,p,Xdr, Ydc );
% insertion patches on img_interp
img_interp( i+(0:Np-2),j+(0:Np-2) ) = img_interp(i+(0:Np-2),j+(0:Np-2) ) + p_int;
%CHECK count
if img_interp( i+(0:Np-2),j+(0:Np-2) )
count = count + 1;
end
end
end
I don't know how to write the last part of the code Thanks
1 Commento
jonas
il 26 Ott 2018
Undefined function or variable
'calcolaOF'.
Can you post a working example or explain in more detail what you are doing?
Risposte (0)
Vedere anche
Categorie
Scopri di più su Polygons in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!