필터 지우기
필터 지우기

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

조회 수: 1 (최근 30일)
Pavan teja
Pavan teja 2018년 3월 5일
편집: Jan 2018년 3월 13일
%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
Stephen23
Stephen23 2018년 3월 12일
@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 2018년 3월 12일
편집: Pavan teja 2018년 3월 12일
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

댓글을 달려면 로그인하십시오.

답변 (1개)

Jan
Jan 2018년 3월 13일
편집: Jan 2018년 3월 13일
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.

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by