Info

This question is closed. Reopen it to edit or answer.

How to make my program run faster.

1 view (last 30 days)
Ogheneochuko
Ogheneochuko on 25 Nov 2015
Closed: MATLAB Answer Bot on 20 Aug 2021
Hello, I am facing the challenge of making my program code run faster as it takes about 13 minutes to process a set of 132 images. The images were processed along with the mat files(used to plot contours and overlay on the images) generated from them. I have attached 5 images and their mat files as samples along with the program. Any assistance will be greatly appreciated. Thanks.
inputPath1 = uigetdir('K:\');
listFiles = dir([inputPath1 '\*.jpg']);
Memory pre-allocation
[A] = zeros(720,960);
[B] = zeros(720,960);
[C] = zeros(2,200000); [h]= zeros(2,124088);
E = cell(300);
F = cell(300);
%
for k = 1:length(listFiles); % Commence iteration count equal to number of jpg files.
I = imread([inputPath1 '\' listFiles(k).name]);% Load jpg files.
E{k} = I;
end
%
inputPath = uigetdir('K:\');
M = dir([inputPath '\*.mat']);
matfiles = dir([inputPath '\*.mat']);
numfiles = length(matfiles);
%
for i = 1:numfiles; % Commence iteration count equal to number of mat files.
data = load([inputPath '\' matfiles(i).name]); % Load mat files.
flds = fieldnames(data);% Fieldnames of data.
field = flds{1};% First field in data structure.
A = data.(field);% First field of data structure is allocated to A.
B = -(27315/100)+A;% Converts displayed temperature from kelvin to celsius.
F{i} = round(B,1); % Rounds values of matrix B to one decimal place.
end
%
N = max(max([F{:}])); % Determines the maximum value in cell F containing matrices.
O = min(min([F{:}])); % Determines the minimum value in cell F containing matrices.
v = [O:1:N];% Creates level upon which contours will be plotted.
mkdir('Test');% Create folder named Test in current directory
cd 'Test' % Change current directory to Test
%
for j= 1:length(listFiles);
L = F{j};
G = fspecial('average');% Creates predefined average 2_D filter
image = imfilter(L,G);% Applies filter to image
D = image;
f = figure('visible','off'); % Prevents the figure from being displayed
P = E{j};
imshow(P);
axis off;
hold on
[C,h] = contour(D,v);
clabel(C,h); % Labels the contours
colorbar; % Creates a colorbar for the superimposed contour on the image
axis off; % Makes the axis invisible
saveas(f,sprintf('result%d.png',j));
end

Answers (0)

Community Treasure Hunt

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

Start Hunting!