this is the link where database images are available i used 1000 image dataset
I am getting more time complexity for the below code can you
1 次查看(过去 30 天)
显示 更早的评论
%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
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.
回答(1 个)
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image Processing Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!