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

1 Ansicht (letzte 30 Tage)
Pavel Chatterjee
Pavel Chatterjee am 21 Mär. 2018
Kommentiert: Pavel Chatterjee am 22 Mär. 2018
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 Kommentare
KSSV
KSSV am 22 Mär. 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.
Pavel Chatterjee
Pavel Chatterjee am 22 Mär. 2018
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

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu MATLAB Compiler finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by