I am getting more time complexity for the below code can you
Afficher commentaires plus anciens
%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
Pavan teja
le 5 Mar 2018
What is your question? Please read http://www.mathworks.com/matlabcentral/answers/13205-tutorial-how-to-format-your-question-with-markup and fix your question.
Stephen23
le 5 Mar 2018
Can you reduce the time complexity by making some changes in the code?
Pavan teja
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.
Pavan teja
le 6 Mar 2018
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?
@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?
Pavan teja
le 9 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.
Pavan teja
le 11 Mar 2018
Pavan teja
le 12 Mar 2018
Pavan teja
le 12 Mar 2018
Modifié(e) : Pavan teja
le 12 Mar 2018
Stephen23
le 12 Mar 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
le 12 Mar 2018
Modifié(e) : Pavan teja
le 12 Mar 2018
Réponses (1)
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.
Catégories
En savoir plus sur Timing and presenting 2D and 3D stimuli 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!