Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

Can anyone explain the loops in this code?

1 visualización (últimos 30 días)
SURILA GUGLANI
SURILA GUGLANI el 27 de Mayo de 2018
Cerrada: MATLAB Answer Bot el 20 de Ag. de 2021
figure(2)
file1='Frame_0001.png';%Reference
I=imread(file1);
imshow(I)
J=rgb2gray(I);
K=imresize(J, [500 500]);
figure(3)
file2='Frame_0242.png';
P=imread(file2);
imshow(P)
Q=rgb2gray(P);
R=imresize(Q,[500 500]);
bbox1=edge(K,'canny');
bbox2=edge(R,'canny');
matched_data1=0;
matched_data2=0;
white_points=0;
black_points=0;
for a=1:1:500
for b=1:1:500
if (bbox1(a,b)==1)
white_points=white_points+1;
else
black_points=black_points+1;
end
end
end
for i=1:1:500
for j=1:1:500
if (bbox2(i,j)==1)
matched_data1=matched_data1+1;
else
matched_data2=matched_data2+1;
end
end
end
total_data=white_points;
matched_data=matched_data1;
traffic_density_percentage=abs((((matched_data-total_data)/total_data)*100)*6.5);
figure(4)
if (traffic_density_percentage>=0) && (traffic_density_percentage<15)
instruc = 'Zero Traffic, Green Light for 15 seconds';
display=insertObjectAnnotation(R, 'rectangle', [0 450 0 0], instruc);
imshow(display);
elseif (traffic_density_percentage>=15) && (traffic_density_percentage<32)
instruc = 'Low Traffic, Green Light for 40 seconds';
display=insertObjectAnnotation(R, 'rectangle', [0 450 0 0], instruc);
imshow(display);
elseif (traffic_density_percentage>=32) && (traffic_density_percentage<70)
instruc = 'Moderate Traffic, Green Light for 60 seconds';
display=insertObjectAnnotation(R, 'rectangle', [0 450 0 0], instruc);
imshow(display);
else (traffic_density_percentage >=70)
instruc = 'Heavy Traffic, Green Light for 90 seconds';
display=insertObjectAnnotation(R, 'rectangle', [0 450 0 0], instruc);
imshow(display);
end
print('first','-dpng','-r300');

Respuestas (1)

sloppydisk
sloppydisk el 27 de Mayo de 2018
Editada: sloppydisk el 27 de Mayo de 2018
They're counting the number of white points, black points and matched data, but they could be replaced by using logical indexing, (for example for the first one):
white_points = sum(bbox1);
black_points = sum(~bbox1);

La pregunta está cerrada.

Productos


Versión

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by