Code takes too much time to compile. Maybe some advice?

My Matlab code is taking too much time to compile. It basically has a lot of iterations. The real work of the code is to individually get rgb values(For a specific row and col of the picture matrix) using some logic and then creating a fresh new rgb matrix and finally converting the rgb matrix into an image. Maybe I would need some advice on making the compilation time quicker. Your help will be much appreciated. Also I tried to put a waitbar, bu the waitbar doesnt show any progress at all.
My Code h = waitbar(0,'Please wait...'); for i=1:1000 numberOfImages=2;
k=0;
for row=1:1584 for col=1:2780
for i=1:numberOfImages
filename=[num2str(i), '.png'];
rgbImage=imread(filename, 'png');
R = rgbImage(row, col, 1);
G = rgbImage(row, col, 2);
B = rgbImage(row, col, 3);
RGBMatrix(i,:) =[R,G,B];
end
for imageNumber=1:numberOfImages
match=0;
jitter=0;
for j=numberOfImages:-1:1
RedChannelDifference=abs(double(RGBMatrix(j,1))-double(RGBMatrix(imageNumber,1)));
GreenChannelDifference=abs(double(RGBMatrix(j,2))-double(RGBMatrix(imageNumber,2)));
BlueChannelDifference=abs(double(RGBMatrix(j,3))-double(RGBMatrix(imageNumber,3)));
if (RedChannelDifference+GreenChannelDifference+BlueChannelDifference)<=10
jitter=jitter+RedChannelDifference+GreenChannelDifference+BlueChannelDifference;
match=match+1;
end
end
match=match-1;
matchMatrixOfAllImages(imageNumber,:)=[match];
end
%fprintf('The maximum value of matches is : %d \n', max(matchMatrixOfAllImages(:)));
index=find(matchMatrixOfAllImages == max(matchMatrixOfAllImages(:)));
if size(index,1)>1
jitterMatrixOfAllImages(imageNumber,:)=[jitter];
% fprintf('Jitter values of ONLY MATCHES');
jitterMatrixOfMatchedImages=jitterMatrixOfAllImages(index,:);
indexForJitter=find(jitterMatrixOfMatchedImages == min(jitterMatrixOfMatchedImages(:)));
if size(indexForJitter,1)>1
indexOfPictureNeeded=indexForJitter(1,:);
filenameOfImage1=[num2str(indexOfPictureNeeded), '.png'];
rgbImage1=imread(filename, 'png');
R1 = rgbImage1(row, col, 1);
G1 = rgbImage1(row, col, 2);
B1 = rgbImage1(row, col, 3);
RGBMatrix1(indexOfPictureNeeded,:) =[R1,G1,B1];
k=k+1;
out(k,:) =RGBMatrix1 ;
else
indexOfPictureNeeded=indexForJitter(1,:);
filenameOfImage1=[num2str(indexOfPictureNeeded), '.png'];
rgbImage1=imread(filename, 'png');
R1 = rgbImage1(row, col, 1);
G1 = rgbImage1(row, col, 2);
B1 = rgbImage1(row, col, 3);
RGBMatrix1(indexOfPictureNeeded,:) =[R1,G1,B1];
k=k+1;
out(k,:) =RGBMatrix1 ;
end
else
jitterMatrixOfAllImages(imageNumber,:)=[jitter];
jitterMatrixOfMatchedImages=jitterMatrixOfAllImages(index,:);
indexForJitter=find(jitterMatrixOfMatchedImages == min(jitterMatrixOfMatchedImages(:)));
indexOfPictureNeeded1=indexForJitter(1,:);
filename1=[num2str(indexOfPictureNeeded1), '.png'];
rgbImage2=imread(filename, 'png');
R1 = rgbImage2(row, col, 1);
G1 = rgbImage2(row, col, 2);
B1 = rgbImage2(row, col, 3);
RGBMatrix2(indexOfPictureNeeded1,:) =[R1,G1,B1];
k=k+1;
out(k,:) =RGBMatrix2 ;
end
end
end imshow(imagesc(out)); waitbar(i/1000,h) end

4 commentaires

What do you mean by compile? I've noticed that the time to compile code into a standalone executable with the MATLAB Compiler varies with the release. Some releases compiled really slowly, like 3-4 minutes, and others were pretty quick, like 30 seconds or so.
Or did you mean "run" or "execute" rather than "compile"?
This was basically copying the code to the command window and running it.
KSSV
KSSV le 22 Mar 2018
It is not a good practice to copy and run the code. Copy it in a editor, save it with .m extension and run the code through this file.
Thank you. But any advice on how to run this. I have not been able to get an output image. But However, if i do it at a particular row and col i do get my results. Now when i loop it doesnt work

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by