Info

Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.

Could anybody tell me how to replace these loops with either parfor or vectorization as the code right now runs extremely slowly?

1 Ansicht (letzte 30 Tage)
[rows, columns, numberOfColorChannels] = size(face); % face is an image matrix
for x=1:rows
for y=1:columns
if(red(x,y)>=150)
n = n+1;
rtot = sum(double(red(:)));
end
end
end
rmean= rtot/n;
for x=1:rows
for y=1:columns
red_pixel= red(x,y);
if(red_pixel>=200)
if(red_pixel> rmean)
blush= blush+1;
rblush = sum(double(red_pixel(:)));
end
end
end
end
perc_blush(i)= (blush/(rows*columns))*100;
perc_pale(i)= ((abs(rblush-rmean))/(rows*columns))*100;
  6 Kommentare
Aishwarya Jayachandran
Aishwarya Jayachandran am 19 Okt. 2019
The code i have right now is extremely slow. im going through a dataset of about 500 pictures and it takes hours for me to get the data and put it into an excel sheet. Here is the full code.
%Detect objects using Viola-Jones Algorithm
%To detect Face
FDetect = vision.CascadeObjectDetector;
%Read the input image
source=dir('C:\Users\0wner\Desktop\CBIR project\dataset\normal\*.jpg');
for i=1:566
I= imread(strcat('C:\Users\0wner\Desktop\CBIR project\dataset\normal\', source(i).name));
%Returns Bounding Box values based on number of objects
BB = step(FDetect,I);
for j=1:size(BB,1)
face= imcrop(I, BB(j,:));
end
red= face(:,:,1);
blush=0;
n=0;
rtot=0;
rblush=0;
[rows, columns, numberOfColorChannels] = size(face);
for x=1:rows
for y=1:columns
if(red(x,y)>=150)
n = n+1;
rtot = sum(double(red(:)));
end
end
end
rmean= rtot/n;
for x=1:rows
for y=1:columns
red_pixel= red(x,y);
if(red_pixel>=200)
if(red_pixel> rmean)
blush= blush+1;
rblush = sum(double(red_pixel(:)));
end
end
end
end
perc_blush(i)= (blush/(rows*columns))*100;
perc_pale(i)= ((abs(rblush-rmean))/(rows*columns))*100;
end
perc_face_blush= perc_blush';
perc_face_pale= perc_pale';
xlswrite('blush.xls', perc_face_blush);
xlswrite('pale.xls', perc_face_pale);

Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by