Filter löschen
Filter löschen

I am getting more time complexity for the below code can you

1 Ansicht (letzte 30 Tage)
Pavan teja
Pavan teja am 5 Mär. 2018
Bearbeitet: Jan am 13 Mär. 2018
%Texture image retrieval
tic
disp('query')
[filename, pathname]=uigetfile({'*.jpg'},'queryimage');
img=strcat(pathname,filename);
Image=imread(img);
figure('Name','TEXTURE FEATURE RETRIVED IMAGES','NumberTitle','off');
subplot(4,3,2)
imshow(Image)
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0.05 1 0.95]);
drawnow();
[M,N, numOfBands] = size(Image);
%--------------------------------------------------------------------------
%2.Convert each color component to grayscale
%--------------------------------------------------------------------------
Grey=rgb2gray(Image);
offsets = [0 1; -1 1;-1 0;-1 -1];
glcms = graycomatrix(Grey,'Offset',offsets);
stats= graycoprops(glcms);
A=[stats.Energy,stats.Homogeneity,stats.Correlation,stats.Contrast];
disp('database')
CP=zeros(1,999);
str='.jpg';
for z=1:999
c = fullfile(pathname, sprintf('%d%s', z, str));
Image=imread(c);
%--------------------------------------------------------------------------
%2.Convert each color component to grayscale
%--------------------------------------------------------------------------
[M,N, numOfBands] = size(Image);
Grey=rgb2gray(Image);
offsets = [0 1; -1 1;-1 0;-1 -1];
glcms = graycomatrix(Grey,'Offset',offsets);
stats= graycoprops(glcms);
B=[stats.Energy,stats.Homogeneity,stats.Correlation,stats.Contrast];
CP(z)=euclideanDistance(A,B);
end
[~,P]=sort(CP);
for M=1:12
z=P(M);
img = fullfile(pathname, sprintf('%d%s', z, str) );
subplot(5,3,M+3)
imshow( img )
title( sprintf('z = %d', z) )
drawnow()
end
disp('retrived')
toc
  15 Kommentare
Stephen23
Stephen23 am 12 Mär. 2018
@Pavan teja: you can speed up your code by following the guidelines in the MATLAB documentation (this is what we would do, so you can do it too):
The more your read and using practice these methods for writing efficient code then the easier the more you will understand how and why they work. If you have any specific questions come and ask us.
Pavan teja
Pavan teja am 12 Mär. 2018
Bearbeitet: Pavan teja am 12 Mär. 2018
Okay thank you for the suggestion.I think I have followed suggestions stated by you already in the attached code I think,if I didn't apply any please state about that

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Jan
Jan am 13 Mär. 2018
Bearbeitet: Jan am 13 Mär. 2018
Some amrginal ideas only:
Replace your euclideanDistance() call by:
sqrt(sum((A(:) - B(:)).^2))
Move the drawnow out of the loops, such that the figure must not be updated too frequently.
But this will not help a lot, because it is not the most time-consuming part of the code. Consider the suggestion Stephen has given already: Profile your code. See https://www.mathworks.com/help/matlab/matlab_prog/techniques-for-improving-performance.html . This let you identify the bottleneck of your code. It is not worth to accelerate a part of the code, which uses 1% of the processing time only, because you can save less than 1% of the total processing time there.
You process 1000 images and it is reasonable, that this take a while. Because all we see is the current code, we cannot estimate, if the wanted results can be processed in a cheaper way.
Note: This is a strange thread. Several of my questions for clarifications have been ignored and the readers still have to guess, what the actual question is. The title of the thread is still mysterious: "can you"? I do not have any idea about what "I didn't see any changes has been done to my code,yet" means. You are asking us to solve your problem, but do not offer enough information to so this, even not after explicit questions.

Kategorien

Mehr zu Matrix Indexing 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