Doubt in the specific line
    5 visualizzazioni (ultimi 30 giorni)
  
       Mostra commenti meno recenti
    
could you please explain the following code?
k = zeros(img_h, img_w, 4);
k(:,:,1) = (fxx./((1 + fx.^2).^(3/2))).*fvr; % hor
k(:,:,2) = (fyy./((1 + fy.^2).^(3/2))).*fvr; % ver
k(:,:,3) = (f11./((1 + f1.^2).^(3/2))).*fvr; % \
k(:,:,4) = (f22./((1 + f2.^2).^(3/2))).*fvr; % / 
Wr = 0;
bla = k(:,:,1) > 0;
for y=1:img_h
    for x=1:img_w
        if(bla(y,x))  %%% I cant understand (bla(y,x))
            Wr = Wr + 1;
        end
0 Commenti
Risposta accettata
  KSSV
      
      
 il 24 Lug 2020
        
      Modificato: KSSV
      
      
 il 24 Lug 2020
  
      It is bad to ask such questions......asking to explain a specific line or a code. You have code in hand, play around with that. Print the values, run the code in debug and you can make yourself clear with the code. 
bla = k(:,:,1) > 0;
In the above case bla is a logical matrix. It will have 0, and 1's. 0 where the condition >0 is not met and 1's where the condition > 0 is met. 
if(bla(y,x)) 
In the above line a if condition is used, the conditon is met or if is executed if bla(x,y) is 1 or the if contion is not met. 
0 Commenti
Più risposte (1)
  Walter Roberson
      
      
 il 24 Lug 2020
        The code
Wr = 0;
bla = k(:,:,1) > 0;
for y=1:img_h
    for x=1:img_w
        if(bla(y,x))  %%% I cant understand (bla(y,x))
            Wr = Wr + 1;
        end
    end
end
can be entirely replaced with
Wr = nnz(k(:,:,1) > 0);
You are just counting the number of places that k(:,:,1) is true.
0 Commenti
Vedere anche
Categorie
				Scopri di più su Entering Commands 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!


