How to reduce for loops
Show older comments
I would like to construct a matrix from two differnent(r,g,b) channels of a image.
by using
c_i (x,y,j)= -(‖(f_i ) ̂(Ω)‖ _2)/‖f ̂_j (Ω)‖_2
where i,j are r,g,b channels,
Ω = (m,n), neighborhood support.
code is :
%Image is I
%Ir, Ig, Ib are respective r,g,b channels of image
% code for Ir and Ig as
M=size(I,1);
N=size(I,2);
M1=ceil(sqrt(M));
N1=ceil(sqrt(N));
M2=M-M1;
N2=N-N1;
for i=1:M1
for j=1:N1
f1=norm(Ir(i:i+M2-1,j:j+N2-1));
for i1=1:M1
for j1=1:N1
f2=norm(Ig(i1:i1+M2-1,j1:j1+N2-1));
c((i*(M1))+j-(M1),((N1)*i1)+j1-(N1))=-(f1/f2);
end
end
end
end
Answers (0)
Categories
Find more on Neighborhood and Block Processing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!