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

%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 commentaires

this is the link where database images are available i used 1000 image dataset
Jan
Jan le 5 Mar 2018
Modifié(e) : Jan le 5 Mar 2018
Pavan teja's "Answer" moved here:
Can you reduce the time complexity by making some changes in the code?
I didn't get you
Jan
Jan le 5 Mar 2018
Modifié(e) : Jan le 5 Mar 2018
@Pavan: Please edit the question and format the code as explained here. Posting readable code is essential when you want others to help you.
What does your expression "time complexity" mean? Do you want to accelerate your code? Then use the profiler to find out, which commands take the most time. If it is e.g. imread then buying a faster hard drive is the best solution.
I have attached the above code with some corrections,I think I made enough changes
Stephen23
Stephen23 le 9 Mar 2018
Modifié(e) : Stephen23 le 9 Mar 2018
Pavan teja's "Answer" moved here:
I want to compute mean of a image in x any y direction as image is a function of x and y.so how can I do that?
Jan
Jan le 9 Mar 2018
Modifié(e) : Jan le 10 Mar 2018
@Pavan teja: I cannot understand, why you refuse to format the code in your question. It is trivial: Simply copy& paste the code, select it and press the "{} Code" button. This will take less than 10 seconds, but you do not want to do it. Why?
The attached code would be easier to read and to understand, if you apply the standard indentation: In Matlab's editor press Ctrl-a Ctrl-i.
It is still not clear, what your question is:
I am getting more time complexity for the below code can you
Can we what? What is the relation to your new question:
compute mean of a image in x any y direction as image is a
function of x and y.so how can I do that?
Now I am asking a different one.could you please give some idea about it
Jan
Jan le 10 Mar 2018
Modifié(e) : Jan le 10 Mar 2018
@Pavan: Does "different one" means, that you ask a new question, or that you do not want an answer from me but from another person?
Did you even read my comment? The question "can you" is incomplete, the code is hard to read, other parts of the question are not clear enough to be answered and you ignore the questions for clarifications. I do not see a way to assist you to solve your problem. Good luck.
I think I have attached the matlab file according to your requirements,Is it ok Now?
It is not the answer to my question i am asking you to resolve it
Pavan teja
Pavan teja le 12 Mar 2018
Modifié(e) : Pavan teja le 12 Mar 2018
I didn't see any changes has been done to my code,yet
@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 le 12 Mar 2018
Modifié(e) : Pavan teja le 12 Mar 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

Connectez-vous pour commenter.

Réponses (1)

Jan
Jan le 13 Mar 2018
Modifié(e) : Jan le 13 Mar 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.

Modifié(e) :

Jan
le 13 Mar 2018

Community Treasure Hunt

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

Start Hunting!

Translated by