I have the following code (recognizing individuals pixels of a matrix). For a high number of images, this is very time consuming. Therefore, ¿Could the loop be avoided ? Thanks!
Ältere Kommentare anzeigen
V=zeros(x,y,num_images,'uint16')
for k=1:num_images
for i= 1:x
for j= 1:y
if B(i,j,k)==0
V(i,j,k)= A(i,j,k)/3
else
V(i,j,k)= A(i,j,k)/3+(2^15)
end
end
end
end
1 Kommentar
KSSV
am 22 Dez. 2016
First you terminate the outputs with ;. Else it will take hell lot of time, because it will print result on the screen.
V=zeros(x,y,num_images,'uint16') ;
for k=1:num_images
for i= 1:x
for j= 1:y
if B(i,j,k)==0
V(i,j,k)= A(i,j,k)/3 ;
else
V(i,j,k)= A(i,j,k)/3+(2^15) ;
end
end
end
end
Akzeptierte Antwort
Weitere Antworten (2)
Santi
am 22 Dez. 2016
0 Stimmen
1 Kommentar
David Barry
am 22 Dez. 2016
Great. Please accept the answer then.
John BG
am 22 Dez. 2016
there is no need to initialise the void V, go straight to the indices returned from functions
- find( zeros())
- find( nonzeros())
A=A/3
V(find(zeros(B)))=A(find(zeros(B)))+2^15
V(find(nonzeros(B)))=A(find(nonzeros(B)))
if you find my answer useful would you please mark it as Accepted Answer by clicking on the ACCEPT ANSWER button?
thanks in advance for time and attention
John BG
1 Kommentar
Both lines do not work:
- nonzeros() replies the vector of the non-zero elements and the information about the position inside B is lost.
- zeros() creates an array of zeros with the elements of B as dimensions. Therefore find(zeros(B)) will reply the empty matrix.
Kategorien
Mehr zu Logical finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!